diff options
author | Aki <nthirtyone@gmail.com> | 2017-04-09 22:07:04 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-04-09 22:07:04 +0200 |
commit | 0dd01913fe0eefc7ba4bc0797877f40fdedf9315 (patch) | |
tree | 8d270eb07f589d2487b3ce66d4865e5a4718042a /not/Effect.lua | |
parent | 55b0cf1a22e4a7e41fe00aa693445d6c4bd0652d (diff) | |
parent | a03c1125f10fbbad253a0efc4727072fcbd55345 (diff) | |
download | roflnauts-0dd01913fe0eefc7ba4bc0797877f40fdedf9315.zip roflnauts-0dd01913fe0eefc7ba4bc0797877f40fdedf9315.tar.gz roflnauts-0dd01913fe0eefc7ba4bc0797877f40fdedf9315.tar.bz2 |
Merge branch 'com'
Diffstat (limited to 'not/Effect.lua')
-rw-r--r-- | not/Effect.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/not/Effect.lua b/not/Effect.lua new file mode 100644 index 0000000..dd7570a --- /dev/null +++ b/not/Effect.lua @@ -0,0 +1,46 @@ +--- `Effect` +-- Short animation with graphics that plays in various situation. +-- TODO: animation is currently slower than it used to be, check if it is ok; if not then make it possible to change it to 0.06 delay. +Effect = { + finished = false, +} + +-- `Effect` is a child of `Decoration`. +require "not.Decoration" +Effect.__index = Effect +setmetatable(Effect, Decoration) + +-- Constructor of `Effect`. +function Effect:new (name, x, y) + local o = setmetatable({}, self) + o:init(name, x, y) + -- Load spritesheet statically. + if self:getImage() == nil then + self:setImage(Sprite.newImage("assets/effects.png")) + end + return o +end + +-- Initializer of `Effect`. +function Effect:init (name, x, y) + Decoration.init(self, x, y, nil) + self:setAnimationsList(require("config.animations.effects")) + self:setAnimation(name) +end + +-- Update of `Effect`. +-- Returns true if animation is finished and effect is ready to be deleted. +function Effect:update (dt) + Decoration.update(self, dt) + return self.finished +end + +-- Overridden from `not.Sprite`. +-- Sets finished flag if reached last frame of played animation. +function Effect:goToNextFrame () + if not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + else + self.finished = true + end +end |