Permalink
Browse files

Jumping right and left now work.

  • Loading branch information...
JesterXL committed Jan 16, 2012
1 parent 8a8f161 commit 19b27c0df28a28169323af714552c10c5b12d0e3
@@ -7,7 +7,7 @@ require "com.jxl.zombiestick.states.MovingLeftState"
require "com.jxl.zombiestick.states.MovingRightState"
require "com.jxl.zombiestick.states.JumpState"
require "com.jxl.zombiestick.states.JumpRightState"
---require "com.jxl.zombiestick.states.JumpLeftState"
+require "com.jxl.zombiestick.states.JumpLeftState"
require "com.jxl.zombiestick.players.BasePlayer"
PlayerJXL = {}
@@ -105,7 +105,7 @@ function PlayerJXL:new(params)
player.fsm:addState2(MovingRightState:new())
player.fsm:addState2(JumpState:new())
player.fsm:addState2(JumpRightState:new())
- --player.fsm:addState2(JumpLeftState:new())
+ player.fsm:addState2(JumpLeftState:new())
player.fsm:setInitialState("ready", player)
return player
@@ -0,0 +1,39 @@
+require "com.jxl.zombiestick.states.JumpState"
+
+JumpLeftState = {}
+
+function JumpLeftState:new()
+ local state = JumpState:new("jumpLeft")
+ state.xForce = nil
+
+ state.superOnEnterState = state.onEnterState
+ function state:onEnterState(event)
+ print("JumpLeftState::onEnterState")
+ self:superOnEnterState(event)
+
+ local player = self.player
+ player:setDirection("left")
+ self.xForce = -player.jumpForwardForce
+ --local multiplier = 60
+ --player:applyForce(xForce* multiplier, self.jumpForce * multiplier, 40, 32)
+ end
+
+ state.superOnExitState = state.onExitState
+ function state:onExitState(event)
+ local player = self.player
+ player:applyLinearImpulse(self.xForce / 3, 0, 40, 32)
+ self:superOnExitState(event)
+ end
+
+ state.superTick = state.tick
+ function state:tick(time)
+ local player = self.player
+ player.x = player.x + self.xForce
+ self:superTick(time)
+ end
+
+ return state
+
+end
+
+return JumpLeftState
@@ -21,7 +21,7 @@ function JumpRightState:new()
state.superOnExitState = state.onExitState
function state:onExitState(event)
local player = self.player
- player:applyLinearImpulse(player.speed / 3, 0, 40, 32)
+ player:applyLinearImpulse(self.xForce / 3, 0, 40, 32)
self:superOnExitState(event)
end

0 comments on commit 19b27c0

Please sign in to comment.