Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Récupération de la métaclasse
- local Animation = require("Animation")
- --------------------- ATTRIBUTS DE CLASSE
- -- Chargement des images pour chaque animation
- local IMGS = {}
- IMGS.idle[1] = love.graphics.newImage("path/idle1.png")
- IMGS.idle[2] = love.graphics.newImage("path/idle2.png")
- IMGS.attack[1] = love.graphics.newImage("path/attack1.png")
- IMGS.attack[2] = love.graphics.newImage("path/attack2.png")
- IMGS.attack[3] = love.graphics.newImage("path/attack3.png")
- IMGS.attack[4] = love.graphics.newImage("path/attack4.png")
- IMGS.death[1] = love.graphics.newImage("path/death1.png")
- IMGS.death[2] = love.graphics.newImage("path/death2.png")
- IMGS.death[3] = love.graphics.newImage("path/death3.png")
- IMGS.death[4] = love.graphics.newImage("path/death4.png")
- IMGS.death[5] = love.graphics.newImage("path/death5.png")
- -- Création des Animations (se fait une seule fois dans tout le code)
- local ANIMS = {}
- ANIMS.idle = Animation.initClass(IMGS.idle, 0.4)
- ANIMS.attack = Animation.initClass(IMGS.attack, 0.8)
- ANIMS.death = Animation.initClass(IMGS.death, 2, false)
- --------------------- ATTRIBUTS D'INSTANCE
- -- C'est lors de l'instanciation des objets qu'on initialise chaque animation.
- -- Ainsi chaque objet partage les mêmes animations (attributs de classes), mais avec des temps de parcours différents (attributs d'instances)
- perso.anims = {}
- perso.anims.idle = ANIMS.idle.new()
- perso.anims.attack = ANIMS.attack.new()
- perso.anims.death = ANIMS.death.new()
- -- Lors de l'utilisation, il suffit d'utiliser l'état dominant (en faisant l'hypothèse que tu stockes l'état dans un attribut 'state')
- -- Lors d'une maj
- perso.img = perso.anims[perso.state].update(dt)
- -- Ou lors d'un changement d'état
- perso.state = newState
- perso.img = perso.anims[perso.state].update(dt, true)
- -- Et donc lors de l'affichage
- love.graphics.draw(perso.img, perso.x, perso.y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement