Double Jump

Monkey Forums/Monkey Programming/Double Jump

erebel55(Posted 2014) [#1]
I am attempting to implement double jump but am surprisingly having a hard time with it.

I want the player to jump if the player clicks on the jump button in the bottom right hand corner. If they then release the jump button and click again while the player is still in the air then they should double jump. I know I could be lazy and just use TouchHit instead of TouchDown, but I would rather not do that.

I am trying to add this to therevills platformer code. (No diddy or images)



I tried adding a firstClick field to my button class, however I still couldn't get it working correctly. (not shown in the above code as I didn't really like it anyways)

Anyone care to take a crack at it?

I appreciate it!


Gerry Quinn(Posted 2014) [#2]
<Shrug>

Field isAlreadyFlying:Bool


OnUpdate()
If IsNewJumpHit() And isAlreadyFlying
InitiateDoubleJump()
End
End


It's up to you to track those things. Anyway you want.


erebel55(Posted 2014) [#3]
Right, I understand the concept and tried to implement that but wasn't successful.


Jesse(Posted 2014) [#4]
Keep pounding at it you'll figure it out.
I got you a basic concept out of your own game but only did it with the mouse. I did some modifications to your code that were not necessary but just so that it would be easier and faster for me to work with. I got it working with the mouse only, see if you can figure it out with the spacebar:


edit:
you need to figure out for multitouch. a bit more complicated.


Jesse(Posted 2014) [#5]
Keep pounding at it you'll figure it out.
I got you a basic concept out of your own game but only did it with the mouse. I did some modifications to your code that were not necessary but just so that it would be easier and faster for me to work with. I got it working with the mouse only, see if you can figure it out with the spacebar:


edit:
you need to figure out for multitouch. a bit more complicated.


erebel55(Posted 2014) [#6]
:) Thank you Jesse, I appreciate it.

Ahh yeah you took out the multi-touch, that seems to throw it off.


Gerry Quinn(Posted 2014) [#7]
Sorry I was a bit abrupt. But it seems to me you have a multi-touch / button problem rather than a double-jump problem.

The answer is kind of the same, though. You need to figure out exactly what states the game (including its controls) can be in at any particular time and how they are recorded. And what each state will advance to on any given input (time passed is also an input).

In the abstract, every game is a finite state machine that takes an input during OnUpdate() and advances to a new (or the same) state.


erebel55(Posted 2014) [#8]
No problem Gerry.

I was able to get the multi-touch working with the double jump by making oldTD an array. That all works great now.

However, SetColor wasn't working with it very well so I replaced it with an animated image for the button instead. This animated image has two frames, one for clicked and one for non-clicked. However, it looks horrible because it is animating at the same speed as everything else is updating. I know I can slow it down with a timer, but that seems wrong in this case.

Edit: I ended up getting SetColor to work, but I am still curious on how it would be don with an animated image instead.


Gerry Quinn(Posted 2014) [#9]
Every button should have its own timer.