diff options
author | Aki <nthirtyone@gmail.com> | 2017-01-20 12:09:54 +0100 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-01-20 12:09:54 +0100 |
commit | cc48afb0a20d01c8f4098c195239f2ca51fac495 (patch) | |
tree | 7e25fda63b89ebb99e0947682bfbccc67550e211 /animated.lua | |
parent | e0da0e869c5f0639b792c1e435b773393126ec02 (diff) | |
download | roflnauts-cc48afb0a20d01c8f4098c195239f2ca51fac495.zip roflnauts-cc48afb0a20d01c8f4098c195239f2ca51fac495.tar.gz roflnauts-cc48afb0a20d01c8f4098c195239f2ca51fac495.tar.bz2 |
Animated class changes.
Diffstat (limited to 'animated.lua')
-rw-r--r-- | animated.lua | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/animated.lua b/animated.lua index c698872..236b68d 100644 --- a/animated.lua +++ b/animated.lua @@ -1,42 +1,59 @@ -- `Animated` --- Abstract class for animated entities. +-- Abstract class for drawable animated entities. -- Metatable Animated = { - animations = require "animations", - current--[[animations.idle]], + animations--[[table with animations]], + current--[[animations.default]], + sprite--[[love.graphics.newImage()]], frame = 1, - delay = .1 + delay = .1, } Animated.__index = Animated -Animated.current = Animated.animations.idle --- setAnimation(self, animation) +-- Sets an Image as a sprite. +function Animated:setSprite(image) + self.sprite = image +end +-- Returns current sprite Image. +function Animated:getSprite() + return self.sprite +end + +-- Sets current animation by table key. function Animated:setAnimation(animation) self.frame = 1 self.delay = Animated.delay -- INITIAL from metatable self.current = self.animations[animation] end - --- getAnimation(self) +-- Returns current animation table. function Animated:getAnimation() return self.current end --- animate(self, dt) -function Animated:animate(dt) +-- Get frame quad for drawing. +function Animated:getQuad() + return self.current[self.frame] +end + +-- Drawing self to LOVE2D buffer. +function Animated:draw(...) + love.graphics.draw(self:getSprite(), self:getQuad(), ...) +end + +-- Animation updating. +function Animated:update(dt) self.delay = self.delay - dt if self.delay < 0 then self.delay = self.delay + Animated.delay -- INITIAL from metatable self:nextFrame() end end - --- nextFrame(self) +-- Moving to the next frame. function Animated:nextFrame() if self.current.repeated or not (self.frame == self.current.frames) then self.frame = (self.frame % self.current.frames) + 1 else - self:setAnimation("idle") + self:setAnimation("default") end end
\ No newline at end of file |