Here's a quick way to enable a Double Jump feature in your MPAGD platform games. It also includes a key debounce so that the Double Jump isn't initiated automatically by keeping your finger on the fire/jump button/key.
I've used a variable, J, that will store our current jump status, you could use a sprite variable like SETTINGA if you prefer. For the Double Jump feature there are five possible jump status:
0 No Jump active
1 1st jump has been initiated
2 A second jump is possible
3 A Second jump has been initiated
4 The player has landed after doing a jump.
By using an IF ELSE ENDIF on our fire key, we can ensure the right status is set which will the allow (or) not a second jump. This code will also ensure the fire key has been released before any type of jump (single or double) can take place.
IF KEY FIRE
IF J = 0 ; J is our jump status
JUMP 6
LET J = 1 ; player has Jumped set status to 1
ENDIF
IF J = 2 ; double jump is possible
STOPFALL
JUMP 6
LET J = 3 ; double jump has occured
ENDIF
ELSE ; player is not pressing jump
IF J = 1 ; if jump flag is active and we've released the jump key
LET J = 2 ; set jump flag to double jump possible (2)
ENDIF
IF J = 4 ; if player had jumped, then landed and now released jump
LET J = 0 ; reset the jump status
ENDIF
ENDIF
IF AIRBORNE = 0 ; PLAYER HAS LANDED
IF J >= 1 ; if player had jumped or double jumped
LET J = 4 ; set status to 4 and await jump key being released
ENDIF
ENDIFHere it is in action, I've displayed the J Value at the top of the screen to help you see what was going on!
