Lets try to Double Jump!

WolfMerrik

New member
Now, this is VERY simple and basically reappropriates the original (plus my first mod) code in the platformer tutorial to make a double jump.
But it does achieve a "Double Jump" mechanic
FIRST, we need to make two vars:

These will be in SystemVariables.asm
Code:
canDoubleJump .dsb 1	; This will be set AFTER we jump, otherwise it's not really a double jump is it.
didDoubleJump .dsb 1	; Keep in mind when looking at this in code, it is a REVERSE boolean

Then we look at the new Jump Script...
I named this playerDoubleJump.asm, and I assigned it to the hold "A" input

Code:
LDX player1_object
LDA Object_status,x
AND #%00000100
BEQ +
LDA #$00
SEC
SBC #$06  
STA Object_v_speed_hi,x
LDA Object_status,x
AND #%11111011
STA Object_status,x
ChangeObjectState #$02, #$02
LDA #$00
STA canDoubleJump	; We cant double jump until AFTER we release, so this will come up again on the release script
LDA #$01
STA didDoubleJump	; Remember how I said I used this like a reverse boolean? don't worry, we didn't double jump yet!
PlaySound #SFX_PLAYER_JUMP	
+
RTS

Next, we look at the release script, which is also VERY similar to the original,
I named mine varPlayerDoubleJumpRelease.asm, and you guessed it! It is called on "A"'s release

Code:
LDA #$01
STA canDoubleJump	; Lets set this now, so we can do it.
LDA #$00		; Its always good to start at 0
SEC
SBC #$02		; I chose 2 over the tutorials 3 because I wanted lighter/tighter jumps
LDX player1_object
CMP Object_v_speed_hi,x	; Rather than BPL, we will compare with the current player value
BMI skipVarJump		; If the speed is below the jumping (reverse falling speed)
LDA #$00		; the same fun way to set the values as the original lol.
SEC
SBC #$02		; This should be the same as we compare against above
	
STA Object_v_speed_hi,x
skipVarJump:				
RTS

Now, we set a new script, this one I called: playerDoubleJumpPress.asm
I use it when the "A" button is pressed.

Code:
LDA canDoubleJump	; Can we double jump?
BEQ +
LDA didDoubleJump	; Did we already do a double jump?
BEQ +
LDA Object_status,x
AND #%00000100		; Remember the check in the jump script? this one works similar, but makes sure we are NOT on the ground
BNE +
LDA #$00
STA didDoubleJump
LDA #$00
STA canDoubleJump
LDA #$00
SEC
SBC #$04		; I went for a lower value than the initial jump... but you can alter the height of it here.
LDX player1_object
STA Object_v_speed_hi,x
LDA Object_status,x
AND #%11111011
STA Object_status,x
ChangeObjectState #$02, #$02
+
RTS

And that just about does it. It seems to be working just fine for me, and I would appreciate any optimizations or improvements, as well as bugs so that I can get it working even better!
 

WolfMerrik

New member
You could also make an action state for this as well (like a forward flip?)
To do this, you would change the state value in playerDoubleJumpPress.asm

This could be a way to make a mechanic like the "Screw Attack" in the Metroid games, you could essentially make this into an attack
 

CutterCross

Active member
Awesome! Would love to see something like a wall-jump script in the future. Sadly I don't have the chops to code that myself yet.
 

WolfMerrik

New member
CutterCross said:
Awesome! Would love to see something like a wall-jump script in the future. Sadly I don't have the chops to code that myself yet.

Ooooo! I want that too!
I was going to look at fixed direction jumps next (like Castlevania etc)
But this could be a lot more fun!
 

WolfMerrik

New member
If you wanted, you could also make it so you can only double jump BEFORE your jump has reached the apex and you are falling:

You would change varPlayerDoubleJumpRelease.asm like this:
Code:
LDA #$00			; Its always good to start at 0
SEC
SBC #$02			; I chose 2 over the tutorials 3 because I wanted lighter/tighter jumps
LDX player1_object
CMP Object_v_speed_hi,x		; Rather than BPL, we will compare with the current player value
BMI skipVarJump			; If the speed is below the jumping (reverse falling speed)
LDA #$00			; the same fun way to set the values as the original lol.
SEC
SBC #$02			; This should be the same as we compare against above
	
STA Object_v_speed_hi,x
LDA #$01
STA canDoubleJump		; Lets set this here, so we cant double jump if we are already falling down
skipVarJump:			; No jump.... no thanks
RTS

This makes it so you can miss the opportunity to double jump, which would be a fun choice for this mechanic.
 

Bucket Mouse

Active member
Can you try to make these topics in the Code forum, or at least double-post them there? They'll get buried here since people don't search this particular subforum to look for good plug-in ASM.
 

WolfMerrik

New member
Bucket Mouse said:
Can you try to make these topics in the Code forum, or at least double-post them there? They'll get buried here since people don't search this particular subforum to look for good plug-in ASM.

I suppose that is not a bad idea, and it is done.
 

WolfMerrik

New member
There does seem to be a "bug" or at the very least something that player could exploit; When a player is falling, if they did not use the "DoubleJump" it can be used.
I would assume the best way to fix this would be to add:

Code:
	LDA #$00	;;Set the ability to Double Jump to 0;
	STA canDoubleJump

When the player hits the ground.
 

WolfMerrik

New member
WolfMerrik said:
There does seem to be a "bug" or at the very least something that player could exploit; When a player is falling, if they did not use the "DoubleJump" it can be used.
I would assume the best way to fix this would be to add:

Code:
	LDA #$00	;;Set the ability to Double Jump to 0;
	STA canDoubleJump

When the player hits the ground. You could even put this on the Change to walking/idle animation scripts.
 
Top Bottom