From 6bad1609ca28ce88dbe75207e524ce8d67ec2a61 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 9 Apr 2018 03:21:33 +0200 Subject: Added onJumpStopped, moved jump timer reset there; renamed onJump to onJumpStarted --- not/Hero.lua | 31 ++++++++++++++++++++----------- 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 -- cgit v1.1