diff options
author | Aki <nthirtyone@gmail.com> | 2017-09-20 01:52:27 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-09-20 01:52:27 +0200 |
commit | 03ccc9890c2b349eb939b0d9fcaa982ead98f0cd (patch) | |
tree | f539a23397e401dbdd369a807ec1e020f069b6fd /not/Trap.lua | |
parent | cfacf87da639e448699a883c0e3fb4da8b6f6471 (diff) | |
download | roflnauts-03ccc9890c2b349eb939b0d9fcaa982ead98f0cd.zip roflnauts-03ccc9890c2b349eb939b0d9fcaa982ead98f0cd.tar.gz roflnauts-03ccc9890c2b349eb939b0d9fcaa982ead98f0cd.tar.bz2 |
Moved most important parts from createFlame to Trap
Diffstat (limited to 'not/Trap.lua')
-rw-r--r-- | not/Trap.lua | 56 |
1 files changed, 56 insertions, 0 deletions
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 |