animation: added entity for playing animations
This commit is contained in:
parent
a50e53d260
commit
5a5381e817
1 changed files with 36 additions and 0 deletions
36
entities/animation.lua
Normal file
36
entities/animation.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
Class = require 'hump.class'
|
||||
require 'entities/entity'
|
||||
|
||||
Animation = Class{
|
||||
__includes = Entity,
|
||||
|
||||
frames = {},
|
||||
|
||||
curFrame = 0
|
||||
|
||||
init = function(self, x, y, level, basename, numFrames, fps)
|
||||
Entity.init(self, x, y, level)
|
||||
|
||||
for frame = 0,numFrames - 1 do
|
||||
self.frames[frame] = love.graphics.newImage(string.format(basename, frame))
|
||||
end
|
||||
|
||||
self.angle = 0
|
||||
self.width = self.frames[0].getWidth();
|
||||
self.height = self.frames[0].getHeight();
|
||||
self.quad = love.graphics.newQuad(0, 0, self.width, self.height, self.width, self.height)
|
||||
end;
|
||||
|
||||
draw = function(self)
|
||||
if self.health > 0 then
|
||||
local img = self.frames[math.floor(curFrame)]
|
||||
if img then
|
||||
love.graphics.draw(self.frames[0], self.quad, 0, 0, self.angle, 1, 1, self.width / 2, self.width / 2)
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
update = function(self, dt)
|
||||
curFrame += dt * fps
|
||||
end;
|
||||
}
|
Loading…
Reference in a new issue