Hi guys,
I would very much appreciate your help.
I am making Dog jump over obstacles game.
My code is as follows:
local function jumpAgain(event)
if (player.jump_completed == true and player.x < (obstacle1.x - 100) and player.oneJump == false and player.jumped == false) then
player:setLinearVelocity(150, -100)
player.oneJump = true
player.jump_completed = false
player.jumped = true
end
end
local function jumpAgain2(event)
if (player.jump_completed == false and player.x < (obstacle2.x -50) and player.oneJump == true and player.jumped == true) then
player:setLinearVelocity(150, - 100)
player.oneJump = false
player.jump_completed = true
player.jumped = false
end
end
Runtime:addEventListener ( “enterFrame”, jumpAgain )
Runtime:addEventListener ( “enterFrame”, jumpAgain2 )
I have three short questions regarding this topic:
-
My player jumps over first obstacle but not over second obstacle (it lands before obstacle2.x - 50)?
-
Is there a better way to automate this code?
-
Is there a better function than setLinearVelocity for this?
Many thanks.
Ivan