From 08271656cbe18fbc4432fc758ac42750e818da84 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 30 Sep 2017 19:27:04 +0200 Subject: Jump moved completely out of Player (I think) --- not/Hero.lua | 39 +++++++++++++++++++++++++++++++++++---- not/Player.lua | 23 ----------------------- 2 files changed, 35 insertions(+), 27 deletions(-) (limited to 'not') diff --git a/not/Hero.lua b/not/Hero.lua index b3edfbf..21c4e27 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -141,10 +141,41 @@ function Hero:update (dt) end -- Jumping. - if self:isJumping() and self.jumpTimer > 0 and (self.jumpCounter == 0 or self.jumpCounter == 1) then - local x = self:getLinearVelocity() - self:setLinearVelocity(x,-160) - self.jumpTimer = self.jumpTimer - dt + 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 + end + else + self._jumpevent = false + end +end + +function Hero:onJump () + -- Start salto if last jump + if self.jumpCounter == 1 then + self.salto = true + end + self.jumpCounter = self.jumpCounter - 1 + if self.jumpCounter > 0 then + -- self:playSound(6) + -- Spawn proper effect + if not self.inAir then + self:createEffect("jump") + else + self:createEffect("doublejump") + end + -- Animation clear + if (self.current == self.animations.attack) or + (self.current == self.animations.attack_up) or + (self.current == self.animations.attack_down) then + self:setAnimation("default") + end end end diff --git a/not/Player.lua b/not/Player.lua index 3d15f31..27ace75 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -41,29 +41,6 @@ end function Player:controlpressed (set, action, key) if set ~= self:getControllerSet() then return end self.smoke = false -- TODO: temporary - -- Jumping - if action == "jump" then - self.jumpCounter = self.jumpCounter - 1 - if self.jumpCounter > 0 then - -- self:playSound(6) - -- Spawn proper effect - if not self.inAir then - self:createEffect("jump") - else - self:createEffect("doublejump") - end - -- Start salto if last jump - if self.jumpCounter == 1 then - self.salto = true - end - -- Animation clear - if (self.current == self.animations.attack) or - (self.current == self.animations.attack_up) or - (self.current == self.animations.attack_down) then - self:setAnimation("default") - end - end - end -- Walking if (action == "left" or action == "right") then -- cgit v1.1