From 84278ed41f61c586dbb38dd99c45ee33e2f58c77 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 16 Mar 2017 19:05:50 +0100 Subject: Moved ? -> not.?; Renamed Player -> Hero --- not/Effect.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 not/Effect.lua (limited to 'not/Effect.lua') diff --git a/not/Effect.lua b/not/Effect.lua new file mode 100644 index 0000000..4e327a1 --- /dev/null +++ b/not/Effect.lua @@ -0,0 +1,68 @@ +-- `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 -- cgit v1.1 From 2e352657813b37d17c2215b85189f18a50c099f9 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 03:29:32 +0100 Subject: Comments, todos, pretty useless --- not/Effect.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'not/Effect.lua') diff --git a/not/Effect.lua b/not/Effect.lua index 4e327a1..7010946 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -3,6 +3,8 @@ -- Metatable of `Effect` -- nils initialized in constructor +-- TODO: inherit from `not.Sprite`. +-- TODO: clean-up and reformat code, see newer code for reference. Effect = { x = 0, y = 0, -- cgit v1.1 From 33865425828c92bb1cf97dee8d0b0f51f9b01042 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 19:16:42 +0200 Subject: Effect is now child of Decoration. Uses Sprite methods and Decoration positioning --- not/Effect.lua | 92 ++++++++++++++++++++++------------------------------------ 1 file changed, 34 insertions(+), 58 deletions(-) (limited to 'not/Effect.lua') 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 -- cgit v1.1 From b4389dfb590862b50cc6c9ce59d3fcef9bd046b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 20:11:21 +0200 Subject: World comments, other comments, todos --- not/Effect.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Effect.lua') diff --git a/not/Effect.lua b/not/Effect.lua index 1bf9ed7..4051b92 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -21,7 +21,7 @@ function Effect:new (name, x, y) return o end --- Initializator of `Effect`. +-- Initializer of `Effect`. function Effect:init (name, x, y) Decoration.init(self, x, y, nil) self:setAnimationsList(require("effects")) -- cgit v1.1 From a03c1125f10fbbad253a0efc4727072fcbd55345 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 8 Apr 2017 20:38:45 +0200 Subject: Moved configs from root directory to config directory --- not/Effect.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Effect.lua') diff --git a/not/Effect.lua b/not/Effect.lua index 4051b92..dd7570a 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -24,7 +24,7 @@ end -- Initializer of `Effect`. function Effect:init (name, x, y) Decoration.init(self, x, y, nil) - self:setAnimationsList(require("effects")) + self:setAnimationsList(require("config.animations.effects")) self:setAnimation(name) end -- cgit v1.1