summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-30 19:27:04 +0200
committerAki <nthirtyone@gmail.com>2017-09-30 19:27:04 +0200
commit08271656cbe18fbc4432fc758ac42750e818da84 (patch)
tree2213c9189176f2942b65fe16fcb310e7116bd2c8
parent6d61fb66d72bb668d71479d3ed5f40b51041639e (diff)
downloadroflnauts-08271656cbe18fbc4432fc758ac42750e818da84.zip
roflnauts-08271656cbe18fbc4432fc758ac42750e818da84.tar.gz
roflnauts-08271656cbe18fbc4432fc758ac42750e818da84.tar.bz2
Jump moved completely out of Player (I think)
-rw-r--r--not/Hero.lua39
-rw-r--r--not/Player.lua23
2 files changed, 35 insertions, 27 deletions
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