summaryrefslogtreecommitdiffhomepage
path: root/not
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2018-04-09 03:21:33 +0200
committerAki <nthirtyone@gmail.com>2018-04-09 03:21:33 +0200
commit6bad1609ca28ce88dbe75207e524ce8d67ec2a61 (patch)
treee91fbdbe67e35dfb7ec79b638e80841feadb0025 /not
parent0baba0172f916a70042a5ddadf2a30957afa33d4 (diff)
downloadroflnauts-6bad1609ca28ce88dbe75207e524ce8d67ec2a61.zip
roflnauts-6bad1609ca28ce88dbe75207e524ce8d67ec2a61.tar.gz
roflnauts-6bad1609ca28ce88dbe75207e524ce8d67ec2a61.tar.bz2
Added onJumpStopped, moved jump timer reset there; renamed onJump to onJumpStarted
Diffstat (limited to 'not')
-rw-r--r--not/Hero.lua31
-rw-r--r--not/Player.lua4
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