diff options
author | Aki <nthirtyone@gmail.com> | 2018-04-09 02:23:13 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2018-04-09 02:23:13 +0200 |
commit | 4e2ad54590449037e4c35e26b285638029c8282d (patch) | |
tree | 087f02f45bbf3e1a45e1b704294613b90dcea04e /not | |
parent | c36b981f54d22c3891856c64b6be780815e8b7df (diff) | |
download | roflnauts-4e2ad54590449037e4c35e26b285638029c8282d.zip roflnauts-4e2ad54590449037e4c35e26b285638029c8282d.tar.gz roflnauts-4e2ad54590449037e4c35e26b285638029c8282d.tar.bz2 |
Added onWalkingStopped and moved animation changes there from Player
Diffstat (limited to 'not')
-rw-r--r-- | not/Hero.lua | 17 | ||||
-rw-r--r-- | not/Player.lua | 8 |
2 files changed, 15 insertions, 10 deletions
diff --git a/not/Hero.lua b/not/Hero.lua index 118b9f1..1181080 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -132,7 +132,10 @@ function Hero:update (dt) self:onWalkingStarted() end else - self._already_walking = false + if self._already_walking then + self._already_walking = false + self:onWalkingStopped() + end end if self:isWalkingLeft() then self:walk(-1) @@ -169,7 +172,7 @@ function Hero:update (dt) end --- Called each time Hero starts walking. --- Is not called when only direction of walking is changed. +-- Is not called when direction of walking is changed. function Hero:onWalkingStarted () if (self.current ~= self.animations.attack) and (self.current ~= self.animations.attack_up) and @@ -178,6 +181,16 @@ function Hero:onWalkingStarted () end end +--- Called when Hero stops walking. +-- Is not called when direction of walking is changed. +function Hero:onWalkingStopped () + if not (self:isControlDown("left") or self:isControlDown("right")) then + if self.current == self.animations.walk then + self:setAnimation("default") + end + end +end + function Hero:onJump () -- Start salto if last jump if self.jumpCounter == 1 then diff --git a/not/Player.lua b/not/Player.lua index 5e73e25..b33e229 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -65,14 +65,6 @@ function Player:controlreleased (set, action, key) if action == "jump" then self.jumpTimer = Hero.JUMP_TIMER end - -- Walking - if (action == "left" or action == "right") then - if not (self:isControlDown("left") or self:isControlDown("right")) then - if self.current == self.animations.walk then - self:setAnimation("default") - end - end - end end return Player |