diff options
author | Aki <nthirtyone@gmail.com> | 2017-09-21 21:05:37 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-09-21 21:05:37 +0200 |
commit | e9a450d65d4fb564691cdf651ef5771dd88303ae (patch) | |
tree | f49d29582dd6877f3b3c807c3f7d9d92d368f798 /not/Trap.lua | |
parent | eb8302723cd85adca0fbaf505cfb315f1db0299a (diff) | |
parent | b97985def64b8bd8f93a7b391b12333595432e52 (diff) | |
download | roflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.zip roflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.tar.gz roflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.tar.bz2 |
Merge branch 'maps'
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 |