summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-04-03 19:16:42 +0200
committerAki <nthirtyone@gmail.com>2017-04-03 19:16:42 +0200
commit33865425828c92bb1cf97dee8d0b0f51f9b01042 (patch)
tree6e16c1085a2cc77bf667ed037de75ec695a4333a
parente2e4164cda3b4536fcba96f5c5283eb125d2b6b1 (diff)
downloadroflnauts-33865425828c92bb1cf97dee8d0b0f51f9b01042.zip
roflnauts-33865425828c92bb1cf97dee8d0b0f51f9b01042.tar.gz
roflnauts-33865425828c92bb1cf97dee8d0b0f51f9b01042.tar.bz2
Effect is now child of Decoration. Uses Sprite methods and Decoration positioning
-rw-r--r--effects.lua21
-rw-r--r--not/Effect.lua92
2 files changed, 48 insertions, 65 deletions
diff --git a/effects.lua b/effects.lua
index 6946d10..dd6d55e 100644
--- a/effects.lua
+++ b/effects.lua
@@ -16,14 +16,16 @@ local quads = {
[2] = love.graphics.newQuad( 24, 0, 24,24, 168,120),
[3] = love.graphics.newQuad( 48, 0, 24,24, 168,120),
[4] = love.graphics.newQuad( 72, 0, 24,24, 168,120),
- frames = 4
+ frames = 4,
+ repeated = false
},
doublejump = {
[1] = love.graphics.newQuad( 0, 24, 24,24, 168,120),
[2] = love.graphics.newQuad( 24, 24, 24,24, 168,120),
[3] = love.graphics.newQuad( 48, 24, 24,24, 168,120),
[4] = love.graphics.newQuad( 72, 24, 24,24, 168,120),
- frames = 4
+ frames = 4,
+ repeated = false
},
land = {
[1] = love.graphics.newQuad( 0, 48, 24,24, 168,120),
@@ -31,7 +33,8 @@ local quads = {
[3] = love.graphics.newQuad( 48, 48, 24,24, 168,120),
[4] = love.graphics.newQuad( 72, 48, 24,24, 168,120),
[5] = love.graphics.newQuad( 96, 48, 24,24, 168,120),
- frames = 5
+ frames = 5,
+ repeated = false
},
respawn = {
[1] = love.graphics.newQuad( 0, 72, 24,24, 168,120),
@@ -41,7 +44,8 @@ local quads = {
[5] = love.graphics.newQuad( 96, 72, 24,24, 168,120),
[6] = love.graphics.newQuad(120, 72, 24,24, 168,120),
[7] = love.graphics.newQuad(144, 72, 24,24, 168,120),
- frames = 7
+ frames = 7,
+ repeated = false
},
clash = {
[1] = love.graphics.newQuad( 0, 96, 24,24, 168,120),
@@ -50,20 +54,23 @@ local quads = {
[4] = love.graphics.newQuad( 72, 96, 24,24, 168,120),
[5] = love.graphics.newQuad( 96, 96, 24,24, 168,120),
[6] = love.graphics.newQuad(120, 96, 24,24, 168,120),
- frames = 6
+ frames = 6,
+ repeated = false
},
trail = {
[1] = love.graphics.newQuad(104, 0, 16,16, 168,120),
[2] = love.graphics.newQuad(120, 0, 16,16, 168,120),
[3] = love.graphics.newQuad(136, 0, 16,16, 168,120),
[4] = love.graphics.newQuad(152, 0, 16,16, 168,120),
- frames = 4
+ frames = 4,
+ repeated = false
},
hit = {
[1] = love.graphics.newQuad(106, 18, 16,16, 168,120),
[2] = love.graphics.newQuad(122, 18, 16,16, 168,120),
[3] = love.graphics.newQuad(138, 18, 16,16, 168,120),
- frames = 3
+ frames = 3,
+ repeated = false
}
}
return quads \ No newline at end of file
diff --git a/not/Effect.lua b/not/Effect.lua
index 7010946..1bf9ed7 100644
--- a/not/Effect.lua
+++ b/not/Effect.lua
@@ -1,70 +1,46 @@
--- `Effect`
+--- `Effect`
-- Short animation with graphics that plays in various situation.
-
--- Metatable of `Effect`
--- nils initialized in constructor
--- TODO: inherit from `not.Sprite`.
--- TODO: clean-up and reformat code, see newer code for reference.
+-- 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 = {
- x = 0,
- y = 0,
- delay = 0.06,
- initial = nil,
- frame = 1,
- animation = nil,
- sprite = nil,
- quads = require "effects"
+ finished = false,
}
--- 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")
+-- `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
- -- 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
+-- Initializator of `Effect`.
+function Effect:init (name, x, y)
+ Decoration.init(self, x, y, nil)
+ self:setAnimationsList(require("effects"))
+ self:setAnimation(name)
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
+-- 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
--- 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
+-- 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