Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Double Jump
Started by Cayendo Apr 05 2019 10:04 AM

1 reply to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Cayendo

[GLOBAL: userInfoPane.html]
Cayendo
  • Observer

  • 6 posts
  • Corona SDK

Hi, I am a new at this so I've been following a tutorial that teaches you how to create an endless rounner game. 

function touched( event )
 if hero.isAlive then
  if(event.phase == "began") then
   if(onGround) then
    hero.accel = hero.accel + 25
   end
  end
 else
  if(event.x < gameOver.x + 150 and event.x > gameOver.x - 150 and event.y < gameOver.y + 95 and event.y > gameOver.y - 95) then
   restartGame()
  end
end

 

From what I found out, this is the function that allows you to jump, however I would like to make it so it double jumps, which is not explained in the tutorial. 

 

Could someone help me out?

Thanks in advance. 
 



[TOPIC: post.html]
#2

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 975 posts
  • Corona SDK

You're proving little code so it's hard to tell for sure, but it looks like you code says something like

 

"if the hero is standing on ground then add 25 to his acceleration".

 

Presumably when the hero lands "onGround" is set to false or nil.

 

What you could is create a variable called jumpCounter (with default value zero) and use that instead of the "onGround" variable.

 

In the "touched" function you could then say something like:

 

" If jumpCounter is smaller then 2 then: add 1 to the jumpCounter and set hero.accel to hero.accel + 25".

 

And when then hero lands, you can set the jumpCounter to zero again.

 

p.s. In code that would read something like this:

 

if jumpCounter < 2 then

    jumpCounter = jumpCounter + 1

    hero.accel = hero.accel + 25

end




[topic_controls]
[/topic_controls]