[4.5.9] Enable jumping In Adventure module

SciNEStist

Well-known member
While working on a new "Beat-Em-Up" game module to share with everyone,
THREAD HERE
VIDEO DEV BLOG HERE

...I have implemented a jump feature that people might enjoy using with other modules. So here is a detailed tutorial on implementing a sort of "Z axis" in the adventure module, that will allow players to jump over other objects. This tutorial doesn't cover having higher up tiles to walk on, as that can get really messy and complicated without dramatic rewrites of the tile collision code, but I might eventually add that later if there is enough demand.

If you have any trouble with tutorial, or it doesn't work for you, please post immediately. There's a good chance it's my fault.
on the other had, if you successfully implement jumping, please share your game here and let us all know!


Section 1: adding the jump

Step 1: add these to object variables in project settings default value can be left at 0

Object_floor
Object_z_lo
Object_z_hi
Object_z_speed_lo
Object_z_speed_hi

Step 2: reduce the object count down to below 10 (we need Total Bytes Used: down to below 250)

Step 3: add these to Overflow ram:

zHold_lo
zHold_hi
self_head
self_feet
other_head
other_feet

Step 4: add jumping input script:
For whatever button you want to make your character jump, add this input script on press:
(you may have to remove any existing inputs for the same button)

Code:
SwitchBank #$1C
TXA
STA temp
LDA Object_floor,x
CMP Object_z_hi,x
BEQ +
    ReturnBank
    RTS
+
    ChangeActionStep temp, #$03
    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    STA Object_z_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    STA Object_z_speed_hi,x
    ReturnBank
    RTS

Step 5: add jumping/gravity into physics:
open up the "Handle Physics" script under subroutines. Right under this part around lines 32-36:

Code:
    ;;;;;;;;;;;; CUSTOMIZATION: IGNORE PHYSICS IF NOT ON MAIN GAME MODE
        LDA gameState
        BEQ +doHandlePhysics
            JMP skipPhysics
        +doHandlePhysics

we add this:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GRAVITY THAT EFFECTS Z POSIITON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        LDA Object_vulnerability,x
        AND #%00000100
        BEQ +doGravity
            JMP +nograv
        +doGravity
            LDA Object_z_hi,x
            ADC Object_z_speed_hi,x
            STA zHold_hi
            CMP Object_floor,x
            BPL +
                LDA Object_floor,x
                STA Object_z_hi,x
                LDA #$00
                STA Object_z_speed_hi,x
                STA Object_z_speed_lo,x
                TXA
                STA temp
                GetActionStep temp
                CMP #$03
                BEQ +isjumping
                CMP #$04
                BEQ +isjumping
                    JMP +notjumping
                +isjumping
                    LDA gamepad
                    AND #%11110000
                    BNE +walk
                        ChangeActionStep temp, #$00 ;not moving
                    +walk
                        ChangeActionStep temp, #$01 ;walking
                +notjumping
                JMP +decell
            +
            LDA zHold_hi
            STA Object_z_hi,x
            LDA zHold_lo
            STA Object_z_lo,x
        +decell
            LDA Object_z_speed_lo,x
            CLC
            SBC #$40
            STA Object_z_speed_lo,x
            LDA Object_z_speed_hi,x
            SBC #$00
            STA Object_z_speed_hi,x
            CMP #$04
                BNE notOverFallSpeed;; is at least max fall speed.
                    LDA #$00
                    STA Object_z_speed_lo,x
                notOverFallSpeed:
            JMP +donegrav
        +nograv
    +donegrav  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GRAVITY SECTION DONE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Step 6: Drawing the jump
In order to visualize the jump, we need the higher the object is on this new "z" axis, the higher the object is drawn. So we edit "handle drawing sprites" in this section around: lines 40-48:

Code:
    LDA Object_x_hi,x
    SEC
    SBC camX ;; is using scrolling
    STA tempA
    LDA Object_y_hi,x
    sec
    SBC camY
    STA tempB
    LDY Object_type,x

we add just one single line:

Code:
    LDA Object_x_hi,x
    SEC
    SBC camX ;; is using scrolling
    STA tempA
    LDA Object_y_hi,x
    sec
    SBC camY
    SBC Object_z_hi,x ;;;;;;;;;;;;;;;;;;;<WE ADDED THIS PART FOR JUMPING
    STA tempB
    LDY Object_type,x

Step 7: adding a shadow
this step is optional, but I recommend it. adding a shadow to the object allows us to see where the ground is for an object when its in the air.
at the very bottom of the "Handle Drawing Sprites" script, add this code:

Code:
LDA Object_z_hi,x
    CMP Object_floor,x
    BNE +
        JMP +doneshadow
    +
        LDY Object_type,x
        LDA ObjectBboxLeft,y
        STA self_left
   
        LDA ObjectBboxTop,y
        CLC
        ADC ObjectHeight,y
        STA self_bottom
       
        LDA Object_y_hi,x
        SBC Object_floor,x
        ADC self_bottom
        SBC #$04 ; adjust this line to center it vertically
        STA tempy
   
        LDA Object_x_hi,x
        ADC self_left
        ADC #$00 ; adjust this line to center horizontally
        STA tempx
        DrawSprite tempx, tempy, #$3C, #%00000000 ; edit this to point at the sprite you want your shadow to be.
    +doneshadow
here Is how I drew a shadow in for this example (next to the key)
shadow.png

Step 8: Adjust player settings:
Set your player jump height using the jump speed slider in the object details. I recommend starting around 48, and adjust from there. You also might want to bump up the speeed to faster than the default tutorial.

DONE! you have added jumping!!! test it out and see how cool it is!!!!

except.....jumping doesnt really have an effect on anything yet. Sure it looks cool, but its not effecting anything like collisions yet.
so let's add in a way to check if the player is at the same height as other objects before we trigger the collision.

Section 2: Changing object collision detection to account for height differences

Step 1: setting up self object head and feet positions

in "Handle object collisions" near the top around line 47, you will see:

Code:
    STA bounds_bottom
    TYA
    PHA
right under "sta bounds_bottom" and above "TYA" wedge in this bit of code:

Code:
    LDA Object_z_hi,x
    STA self_feet
    LDA ObjectSize,y
    AND #%00000111
    ASL
    ASL
    ASL
    ADC Object_z_hi,x
    STA self_head

Step 2: setting up the "other" head and feet positions
in the "compare bounding boxes" we are looking near the bottom of the script in the "getOtherColBox" section. At the bottom of that section, around line 65, below " STA other_center_y ;; self center in the vertical direction." and above the "PLA" line we add this code:

Code:
        LDA Object_z_hi,x
        STA other_feet
        LDA ObjectSize,y
        AND #%00000111
        ASL
        ASL
        ASL
        ADC Object_z_hi,x
        STA other_head

Step 3: we add the z axis checks to the comparing of object boxes
up higher in the same compare bounding boxes script, you will see a section around lines 17-26 that looks like this:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    LDA other_bottom
    CMP bounds_top
    BCC noBboxCollision
    LDA bounds_bottom
    CMP other_top
    BCC noBboxCollision
    LDA #$01 ;; read that YES, there was a collision here. (could make this the object ID)
    RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

we are going to add our checks here, so erase all that section, and add this instead:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    LDA other_bottom
    CMP bounds_top
    BCC noBboxCollision
    LDA bounds_bottom
    CMP other_top
    BCC noBboxCollision
    LDA self_head
    CMP other_feet
    BCC noBboxCollision
    LDA other_head
    CMP self_feet
    BCC noBboxCollision
    LDA #$01 ;; read that YES, there was a collision here. (could make this the object ID)
    RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DONE!!! NOW YOU CAN jump over objects without touching them!!!
If you test again, you will see that you can now jump over monsters and other objects without touching them.

But wait again!!!! What about Tiles? what if we want to jump over hazards and trap tiles?

Section 3: Jumping over tiles

If you want to make sure you dont touch a tile while jumping, you just need to add this to the beginning of the tile code:
Code:
LDA Object_z_hi,x
BEQ +
    RTS
+

now, it will skip over any tile code i9f you are in the air, and only trigger it if you are on ground level.

Please post any questions you have, or even just post your game if you use this script!
 
Last edited:
While working on a new "Beat-Em-Up" game module to share with everyone,
THREAD HERE
VIDEO DEV BLOG HERE

...I have implemented a jump feature that people might enjoy using with other modules. So here is a detailed tutorial on implementing a sort of "Z axis" in the adventure module, that will allow players to jump over other objects. This tutorial doesn't cover having higher up tiles to walk on, as that can get really messy and complicated without dramatic rewrites of the tile collision code, but I might eventually add that later if there is enough demand.

If you have any trouble with tutorial, or it doesn't work for you, please post immediately. There's a good chance it's my fault.
on the other had, if you successfully implement jumping, please share your game here and let us all know!


Section 1: adding the jump

Step 1: add these to object variables in project settings default value can be left at 0

Object_floor
Object_z_lo
Object_z_hi
Object_z_speed_lo
Object_z_speed_hi

Step 2: reduce the object count down to below 10 (we need Total Bytes Used: down to below 250)

Step 3: add these to Overflow ram:

zHold_lo
zHold_hi
self_head
self_feet
other_head
other_feet

Step 4: add jumping input script:
For whatever button you want to make your character jump, add this input script on press:
(you may have to remove any existing inputs for the same button)

Code:
SwitchBank #$1C
TXA
STA temp
LDA Object_floor,x
CMP Object_z_hi,x
BEQ +
    ReturnBank
    RTS
+
    ChangeActionStep temp, #$03
    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    STA Object_z_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    STA Object_z_speed_hi,x
    ReturnBank
    RTS

Step 5: add jumping/gravity into physics:
open up the "Handle Physics" script under subroutines. Right under this part around lines 32-36:

Code:
    ;;;;;;;;;;;; CUSTOMIZATION: IGNORE PHYSICS IF NOT ON MAIN GAME MODE
        LDA gameState
        BEQ +doHandlePhysics
            JMP skipPhysics
        +doHandlePhysics

we add this:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GRAVITY THAT EFFECTS Z POSIITON;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        LDA Object_vulnerability,x
        AND #%00000100
        BEQ +doGravity
            JMP +nograv
        +doGravity
            LDA Object_z_hi,x
            ADC Object_z_speed_hi,x
            STA zHold_hi
            CMP Object_floor,x
            BPL +
                LDA Object_floor,x
                STA Object_z_hi,x
                LDA #$00
                STA Object_z_speed_hi,x
                STA Object_z_speed_lo,x
                TXA
                STA temp
                GetActionStep temp
                CMP #$03
                BEQ +isjumping
                CMP #$04
                BEQ +isjumping
                    JMP +notjumping
                +isjumping
                    LDA gamepad
                    AND #%11110000
                    BNE +walk
                        ChangeActionStep temp, #$00 ;not moving
                    +walk
                        ChangeActionStep temp, #$01 ;walking
                +notjumping
                JMP +decell
            +
            LDA zHold_hi
            STA Object_z_hi,x
            LDA zHold_lo
            STA Object_z_lo,x
        +decell
            LDA Object_z_speed_lo,x
            CLC
            SBC #$40
            STA Object_z_speed_lo,x
            LDA Object_z_speed_hi,x
            SBC #$00
            STA Object_z_speed_hi,x
            CMP #$04
                BNE notOverFallSpeed;; is at least max fall speed.
                    LDA #$00
                    STA Object_z_speed_lo,x
                notOverFallSpeed:
            JMP +donegrav
        +nograv
    +donegrav  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GRAVITY SECTION DONE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Step 6: Drawing the jump
In order to visualize the jump, we need the higher the object is on this new "z" axis, the higher the object is drawn. So we edit "handle drawing sprites" in this section around: lines 40-48:

Code:
    LDA Object_x_hi,x
    SEC
    SBC camX ;; is using scrolling
    STA tempA
    LDA Object_y_hi,x
    sec
    SBC camY
    STA tempB
    LDY Object_type,x

we add just one single line:

Code:
    LDA Object_x_hi,x
    SEC
    SBC camX ;; is using scrolling
    STA tempA
    LDA Object_y_hi,x
    sec
    SBC camY
    SBC Object_z_hi,x ;;;;;;;;;;;;;;;;;;;<WE ADDED THIS PART FOR JUMPING
    STA tempB
    LDY Object_type,x

Step 7: adding a shadow
this step is optional, but I recommend it. adding a shadow to the object allows us to see where the ground is for an object when its in the air.
at the very bottom of the "Handle Drawing Sprites" script, add this code:

Code:
LDA Object_z_hi,x
    CMP Object_floor,x
    BNE +
        JMP +doneshadow
    +
        LDY Object_type,x
        LDA ObjectBboxLeft,y
        STA self_left
   
        LDA ObjectBboxTop,y
        CLC
        ADC ObjectHeight,y
        STA self_bottom
       
        LDA Object_y_hi,x
        SBC Object_floor,x
        ADC self_bottom
        SBC #$04 ; adjust this line to center it vertically
        STA tempy
   
        LDA Object_x_hi,x
        ADC self_left
        ADC #$00 ; adjust this line to center horizontally
        STA tempx
        DrawSprite tempx, tempy, #$3C, #%00000000 ; edit this to point at the sprite you want your shadow to be.
    +doneshadow
here Is how I drew a shadow in for this example (next to the key)
View attachment 8552

Step 8: Adjust player settings:
Set your player jump height using the jump speed slider in the object details. I recommend starting around 48, and adjust from there. You also might want to bump up the speeed to faster than the default tutorial.

DONE! you have added jumping!!! test it out and see how cool it is!!!!

except.....jumping doesnt really have an effect on anything yet. Sure it looks cool, but its not effecting anything like collisions yet.
so let's add in a way to check if the player is at the same height as other objects before we trigger the collision.

Sections 2: Changing object collision detection to account for height differences

Step 1: setting up self object head and feet positions

in "Handle object collisions" near the top around line 47, you will see:

Code:
    STA bounds_bottom
    TYA
    PHA
right under "sta bounds_bottom" and above "TYA" wedge in this bit of code:

Code:
    LDA Object_z_hi,x
    STA self_feet
    LDA ObjectSize,y
    AND #%00000111
    ASL
    ASL
    ASL
    ADC Object_z_hi,x
    STA self_head

Step 2: setting up the "other" head and feet positions
in the "compare bounding boxes" we are looking near the bottom of the script in the "getOtherColBox" section. At the bottom of that section, around line 65, below " STA other_center_y ;; self center in the vertical direction." and above the "PLA" line we add this code:

Code:
        LDA Object_z_hi,x
        STA other_feet
        LDA ObjectSize,y
        AND #%00000111
        ASL
        ASL
        ASL
        ADC Object_z_hi,x
        STA other_head

Step 3: we add the z axis checks to the comparing of object boxes
up higher in the same compare bounding boxes script, you will see a section around lines 17-26 that looks like this:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    LDA other_bottom
    CMP bounds_top
    BCC noBboxCollision
    LDA bounds_bottom
    CMP other_top
    BCC noBboxCollision
    LDA #$01 ;; read that YES, there was a collision here. (could make this the object ID)
    RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

we are going to add our checks here, so erase all that section, and add this instead:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    LDA other_bottom
    CMP bounds_top
    BCC noBboxCollision
    LDA bounds_bottom
    CMP other_top
    BCC noBboxCollision
    LDA self_head
    CMP other_feet
    BCC noBboxCollision
    LDA other_head
    CMP self_feet
    BCC noBboxCollision
    LDA #$01 ;; read that YES, there was a collision here. (could make this the object ID)
    RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DONE!!! NOW YOU CAN jump over objects without touching them!!!
If you test again, you will see that you can now jump over monsters and other objects without touching them.

Please post any questions you have, or even just post your game if you use this script!
This is awesome! Would also be cool for higher grounded tiles like your bear em up but one step at a time
 

SciNEStist

Well-known member
added a bit of instructions at the end for people wanting to make it possible to jump over some tiles.
 
Followed all instructions having freezing issues when walking into screens with enemies. Not touching any enemies. Just entering a screen with 2 enemies.
 

SciNEStist

Well-known member
can you confirm that the change you made in step 2 was saved?
(Step 2: reduce the object count down to below 10 (we need Total Bytes Used: down to below 250))
 
Top Bottom