diff options
Diffstat (limited to 'not')
-rw-r--r-- | not/Hero.lua | 31 | ||||
-rw-r--r-- | not/Player.lua | 4 |
2 files changed, 20 insertions, 15 deletions
diff --git a/not/Hero.lua b/not/Hero.lua index 1181080..38eb749 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -156,18 +156,23 @@ function Hero:update (dt) end -- Jumping. - if self:isJumping() and self.jumpTimer > 0 then - if not self._jumpevent then - self._jumpevent = true - self:onJump() - end - if self.jumpCounter == 0 or self.jumpCounter == 1 then - local x = self:getLinearVelocity() - self:setLinearVelocity(x,-160) - self.jumpTimer = self.jumpTimer - dt + if self:isJumping() then + if self.jumpTimer > 0 then + if not self._jumping then + self._jumping = true + self:onJumpStarted() + end + if self.jumpCounter == 0 or self.jumpCounter == 1 then + local x = self:getLinearVelocity() + self:setLinearVelocity(x,-160) + self.jumpTimer = self.jumpTimer - dt + end end else - self._jumpevent = false + if self._jumping then + self._jumping = false + self:onJumpStopped() + end end end @@ -191,7 +196,7 @@ function Hero:onWalkingStopped () end end -function Hero:onJump () +function Hero:onJumpStarted () -- Start salto if last jump if self.jumpCounter == 1 then self.salto = true @@ -214,6 +219,10 @@ function Hero:onJump () end end +function Hero:onJumpStopped () + self.jumpTimer = Hero.JUMP_TIMER +end + --- Damps linear velocity every frame by applying minor force to body. function Hero:dampVelocity (dt) if not self:isWalking() then diff --git a/not/Player.lua b/not/Player.lua index 1cf6018..72d64bb 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -60,10 +60,6 @@ end function Player:controlreleased (set, action, key) if set ~= self:getControllerSet() then return end - -- Jumping - if action == "jump" then - self.jumpTimer = Hero.JUMP_TIMER - end end return Player |