diff options
Diffstat (limited to 'not/Trap.lua')
-rw-r--r-- | not/Trap.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/not/Trap.lua b/not/Trap.lua new file mode 100644 index 0000000..0867a36 --- /dev/null +++ b/not/Trap.lua @@ -0,0 +1,51 @@ +Trap = require "not.PhysicalBody":extends() + +function Trap:new (direction, x, y, world, imagePath) + Trap.__super.new(self, x, y, world, imagePath) + self:setAnimationsList(require("config.animations.flames")) + self:setBodyType("static") + + 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(4) + fixture:setMask(1,3,4) + fixture:setUserData({direction}) + fixture:setSensor(true) + + 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 + +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 + +return Trap |