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 /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 'effect.lua')
-rw-r--r-- | effect.lua | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/effect.lua b/effect.lua deleted file mode 100644 index 4e327a1..0000000 --- a/effect.lua +++ /dev/null @@ -1,68 +0,0 @@ --- `Effect` --- Short animation with graphics that plays in various situation. - --- Metatable of `Effect` --- nils initialized in constructor -Effect = { - x = 0, - y = 0, - delay = 0.06, - initial = nil, - frame = 1, - animation = nil, - sprite = nil, - quads = require "effects" -} - --- Construct of `Effect` -function Effect:new(name, x, y) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Load spritesheet to metatable if not yet loaded - if self.sprite == nil then - self.sprite = love.graphics.newImage("assets/effects.png") - end - -- Init - o.initial = o.delay - o.animation = name - o.x = x or self.x - o.y = y or self.y - return o -end - --- Position -function Effect:getPosition() - return self.x, self.y -end - --- Animation and return flag for deletion after completion --- returns true if completed and ready to delete -function Effect:update(dt) - self.delay = self.delay - dt - if self.delay < 0 then - if self.frame < self.quads[self.animation].frames then - self.frame = self.frame + 1 - self.delay = self.delay + self.initial - else - return true -- delete - end - end - return false -end - --- Draw me with scale and offsets, senpai -function Effect:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - local x, y = self:getPosition() - -- pixel grid - local draw_x = (math.floor(x) + offset_x) * scale - local draw_y = (math.floor(y) + offset_y) * scale - -- draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, self.quads[self.animation][self.frame], draw_x, draw_y, 0, scale, scale) -end
\ No newline at end of file |