RAD Jump (a better multijump framework)

WolfMerrik

New member
RAD Jump!

So, I made a VASTLY improved jump script, which allows for a configurable amount of jumps/extra jumps.
This could easily be modified, improved, to make items that give double jumps as a powerup/etc.
It also fixes the "Bouncing" that happens when holding A, as it uses presses vs holding.

I had made some changes to my platform physics scrips, so hopefully, this works well with the default platformer module!

Please let me know what you think in a reply below.

Here are the two scripts:
DoubleJump_Rad.asm v1.0
JumpRelease_Rad.asm v1.0

You will need to add these constants to Constants.asm
You can, of course, change the values, just remember, it uses "negative" numbers, which are #$00 as 0, #$FF as -1, etc
This saves on math operations over the last script.

If you did want to add a variable jump_height/speed item, you could still do this by adding a few lines of code.

The constants are:

Code:
; Rad Jump Constants:
; We use NEG Numbers, and save on math operations
JUMP_RELEASE_HEIGHT = #$FD	; When we release the jump
JUMP_HEIGHT = #$FA		; The jump Height
JUMP_HEIGHT_DOUBLE = #$FC	; The double jump Height
JUMP_EXTRA_LIMIT = #$02		; Max number of "Double" jumps!

You will need to add this variable to SystemVariables.asm

Code:
jumpStatus .dsb 1	; Basically a counter for the multi jumps

First, we want to define what happens when we release the jump button.
This script is done when the "Jump" Botton is released:

Code:
; JumpRelease_Rad.asm v1.0 by WolfMerrik
; Use on "Release A" Input (Or your jump button of choice)
; This works very similarly to the old method, but with better comments & optimizations

LDA #JUMP_RELEASE_HEIGHT	; The constant we will be comparing against. Use a predefined negative
LDX player1_object		; Load the player object to the X register for compare/setting
CMP Object_v_speed_hi,x		; Compare our v-speed with the jump release height (Speed)
BMI skipJumpRelease		; If the speed is below the jumping (reverse falling speed)
LDA #JUMP_RELEASE_HEIGHT	; Load the new release speed/height
STA Object_v_speed_hi,x		; Set it!
skipJumpRelease		; Did not need it
RTS

This file is available here: JumpRelease_Rad.asm v1.0


The next script handles all the jumps, detects the ground flags, adds to the counter, etc
This will be done when the "Jump" button is pressed :

Code:
; DoubleJump_Rad.asm v1.0 by WolfMerrik
; Use on "Press A" Input (Or your jump button of choice)
;    Using this as a "press" avoids that weird bouncing we got with the old script
;     Much more than a double jump, but a multi-jump
;     You can define how many "DoubleJumps" you can do in constants
;     You could even add an item that increases this with a variable easily
;     This would be done to canDoubleJump, and you would ADC, or SBC the jump items value.
;     The same could be done of course with jump height (high jump boots anyone?)

LDA jumpStatus
CMP #$00
BEQ firstJump
JMP doubleJumpCheck

firstJump:
    LDX player1_object
    LDA Object_status,x
    AND #%00000100	; Are we on the ground?
    BNE canJump		; We are NOT on the ground
    RTS
    
canJump:    
    LDA #JUMP_HEIGHT
    STA Object_v_speed_hi,x	; Set the jump height!
    LDA Object_status,x
    AND #%11111011
    STA Object_status,x
    ChangeObjectState #$02, #$02    ; Jump animation state
    LDA #$01
    STA jumpStatus		; Set the Jump status to "1"  
    JMP doneJumping		; Jump to done jumping. haha

doubleJumpCheck:
    LDA Object_status,x	; Are we on the ground?
    AND #%00000100
    BEQ canDoubleJump	; If we are, let's jump normally!
    LDA #$00
    STA jumpStatus
    JMP firstJump	; We were on the ground... so let's try to jump again normally!

canDoubleJump:
    LDA #JUMP_EXTRA_LIMIT
    SEC 
    SBC jumpStatus
    BMI doneJumping
    LDX player1_object
    LDA #JUMP_HEIGHT_DOUBLE
    STA Object_v_speed_hi,x
    LDA Object_status,x			; For some reason... this ust be set again
    AND #%11111011			; It sometimes fails without
    STA Object_status,x			; Not sure why!
    ;ChangeObjectState #$03, #$03	; Double Jump State Would go here
    LDA jumpStatus
    ADC #$01
    CLC
    STA jumpStatus		; Add one to the jump Status! We could expand, and make the third jump less, etc

doneJumping:
    RTS

This file is available here: DoubleJump_Rad.asm v1.0

Hopefully, you like it, and I would love to have your feedback, and hear about what you do with it!
 

WolfMerrik

New member
I'm glad to see people like it! It still needs some work, and it meant as a very basic script to be expanded on (no sfx, etc)
But I definitely like how it came out well, and beats the hell out of my old jump script haha =P
 

Imagaryboy

New member
This is really great, thank you for sharing this!!!

Were you able to solve the problem with the collision detection that caused a 2-5 frame window where jumping is not possible?

Because I still have this problem, even with this new script :/
 

WolfMerrik

New member
Imagaryboy said:
Were you able to solve the problem with the collision detection that caused a 2-5 frame window where jumping is not possible?

Sadly, not yet. Even as I have been digging into the physics a lot lately, I have still not find a "why" that it is happening... IF I can find this, I can hopefully create a "how" lol
 

digitalbooty

New member
Thanks for making this! I set these as my new press and release script actions for button A. It will let me jump twice and then it won't let me jump anymore. Not even on the ground. Is there a setting in the script I need to set?
 

SubCog

New member
I'm having the same issue. The double jump works fine the first time, but then once I hit the ground it never lets me jump again. Any ideas what I'm doing wrong?
 

dale_coop

Moderator
Staff member
Did you set all the scripts according to the original post? (Constants.asm, SystemVariables.asm, JumpRelease_Rad.asm assigned to the "release" A button and DoubleJump_Rad.asm to the "press" A button)
Tried again today with a fresh 4.0.11 platformer demo and it works well.
 

digit2600

Member
I'm about to try using this fucker tomorrow. All I need is ti get this double jump thing in order, and I've got one last game mechanic to finish.
 
Top Bottom