From cfacf87da639e448699a883c0e3fb4da8b6f6471 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 19 Sep 2017 17:49:04 +0200 Subject: Added empty Trap class --- not/Trap.lua | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 not/Trap.lua (limited to 'not/Trap.lua') diff --git a/not/Trap.lua b/not/Trap.lua new file mode 100644 index 0000000..012561d --- /dev/null +++ b/not/Trap.lua @@ -0,0 +1,3 @@ +Trap = require "not.PhysicalBody":extends() + +return Trap -- cgit v1.1 From 03ccc9890c2b349eb939b0d9fcaa982ead98f0cd Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 01:52:27 +0200 Subject: Moved most important parts from createFlame to Trap --- not/Trap.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'not/Trap.lua') diff --git a/not/Trap.lua b/not/Trap.lua index 012561d..25eeb0b 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -1,3 +1,59 @@ Trap = require "not.PhysicalBody":extends() +-- TODO: Move flames' animations to config file. +local animations = { + default = { + [1] = love.graphics.newQuad(0, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(42, 0, 42, 19, 168, 19), + frames = 2, + repeated = true + }, + fadein = { + [1] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), + frames = 2, + repeated = false + }, + fadeout = { + [1] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), + frames = 2, + repeated = false + } +} + +function Trap:new (direction, x, y, world, imagePath) + Trap.__super.new(self, x, y, world, imagePath) + self:setAnimationsList(animations) + self:setBodyType("static") + + local mirror = 1 + if direction == "left" then mirror = -1 end + local fixture = Trap.__super.addFixture(self, {0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) + fixture:setCategory(3) + fixture:setMask(1) + fixture:setUserData({0, direction}) + fixture:setSensor(true) + + self.mirror = mirror +end + +function Trap:getHorizontalMirror () + return self.mirror +end + +function Trap:goToNextFrame () + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + elseif self.current == self.animations.fadeout then + self:setAnimation("default") + self.hidden = true + else + self:setAnimation("default") + end +end + +-- TODO: Trap@damage is hotfix for clashing. +function Trap:damage () end + return Trap -- cgit v1.1 From f2979320625eceeaadd594ccf6bad6c6b2543aff Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 13:27:03 +0200 Subject: Added fadein and fadeout methods to Trap --- not/Trap.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'not/Trap.lua') diff --git a/not/Trap.lua b/not/Trap.lua index 25eeb0b..2ebb4d2 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -38,6 +38,23 @@ function Trap:new (direction, x, y, world, imagePath) self.mirror = mirror end +function Trap:fadeIn () + self.hidden = false + self:setBodyActive(true) + if self.animations.fadein then + self:setAnimation("fadein") + end +end + +function Trap:fadeOut () + self:setBodyActive(false) + if self.animations.fadeout then + self:setAnimation("fadeout") + else + self.hidden = true + end +end + function Trap:getHorizontalMirror () return self.mirror end -- cgit v1.1 From cdec3cf410bba80d037fda760da06e9e3ed75945 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 15:43:08 +0200 Subject: Removed obsolete verbose call of addFixture --- not/Trap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Trap.lua') diff --git a/not/Trap.lua b/not/Trap.lua index 2ebb4d2..84de5b0 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -29,7 +29,7 @@ function Trap:new (direction, x, y, world, imagePath) local mirror = 1 if direction == "left" then mirror = -1 end - local fixture = Trap.__super.addFixture(self, {0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) + local fixture = self:addFixture({0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) fixture:setCategory(3) fixture:setMask(1) fixture:setUserData({0, direction}) -- cgit v1.1 From 453095b2e0b34cc4bd24671bc8abe6ff9279a318 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 16:06:53 +0200 Subject: Flames animations moved to separate config file --- not/Trap.lua | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'not/Trap.lua') diff --git a/not/Trap.lua b/not/Trap.lua index 84de5b0..47c3f09 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -1,30 +1,8 @@ Trap = require "not.PhysicalBody":extends() --- TODO: Move flames' animations to config file. -local animations = { - default = { - [1] = love.graphics.newQuad(0, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(42, 0, 42, 19, 168, 19), - frames = 2, - repeated = true - }, - fadein = { - [1] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), - frames = 2, - repeated = false - }, - fadeout = { - [1] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), - frames = 2, - repeated = false - } -} - function Trap:new (direction, x, y, world, imagePath) Trap.__super.new(self, x, y, world, imagePath) - self:setAnimationsList(animations) + self:setAnimationsList(require("config.animations.flames")) self:setBodyType("static") local mirror = 1 -- cgit v1.1 From f60ee890682b9dbecb7dace030862dcdc46d2dc6 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 17:19:42 +0200 Subject: Changed Trap collision category, added category constants to Box2D callbacks --- not/Trap.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'not/Trap.lua') diff --git a/not/Trap.lua b/not/Trap.lua index 47c3f09..2a328d6 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -8,9 +8,9 @@ function Trap:new (direction, x, y, world, imagePath) local mirror = 1 if direction == "left" then mirror = -1 end local fixture = self:addFixture({0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) - fixture:setCategory(3) - fixture:setMask(1) - fixture:setUserData({0, direction}) + fixture:setCategory(4) + fixture:setMask(1,3,4) + fixture:setUserData({direction}) fixture:setSensor(true) self.mirror = mirror -- cgit v1.1 From 99a968d29f580aabc5350e608e545f9162458f0e Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 17:40:34 +0200 Subject: Removed obsolete hotfix for clashes in Traps --- not/Trap.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'not/Trap.lua') diff --git a/not/Trap.lua b/not/Trap.lua index 2a328d6..0867a36 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -48,7 +48,4 @@ function Trap:goToNextFrame () end end --- TODO: Trap@damage is hotfix for clashing. -function Trap:damage () end - return Trap -- cgit v1.1