Double jump in NESmaker 4.5.6 metrovania

baardbi

Well-known member
PS!!!! This tutorial is outdated. I made a new tutorial that is much better:


I DID IT !!! I modified the original code from Joe. It works with a little bug. If you tap the A button really quickly you get infinite jumps. But at least it's a good start. Here's the code:

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
    SwitchBank #$1C
    LDY Object_type,x
    LDA ObjectBboxTop,y
    CLC
    ADC ObjectHeight,y
    sta temp2
   
    LDA Object_x_hi,x
    CLC
    ADC ObjectBboxLeft,y
    STA temp
    JSR getPointColTable
   
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1
    CheckCollisionPoint temp, temp1, #$00, tempA ;; check below feet to see if it is NULL (in the air).
                                    ;;; if it is (equal), can jump.
                                    ;;; if not, skips jumping.
    BNE noDoubleJump
   
    LDA gotDoubleJump
    CMP #$01
    BNE noDoubleJump
    LDA doubleJumpCounter
    CMP #$02
    BEQ noDoubleJump
   
        JMP +doJump
noDoubleJump:
    LDA #$00
    STA doubleJumpCounter
   
    CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
   
    CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
     CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is prize block .
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
    CheckCollisionPoint temp, temp1, #$0A, tempA ;; check below feet to see if it is ladder.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
     BNE +dontDoJump
          JMP  +doJump
        +dontDoJump
            ;; check second point.
        LDY Object_type,x
        LDA ObjectWidth,y
        CLC
        ADC temp
        STA temp
        JSR getPointColTable
        CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                            ;;; if it is (equal), can jump.
                                            ;;; if not, skips jumping.         
        BEQ +doJump
       
        CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$0A, tempA ;; check below feet to see if it is ladder.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
            JMP +skipJumping
+doJump:
    TXA
    STA temp ;; assumes the object we want to move is in x.
    ;PlaySound #sfx_thump

    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    EOR #$FF
    STA Object_v_speed_hi,x
       
    TXA
    STA temp ;; assumes the object we want to move is in x.
 ;  change the object's action so that he is in jump mode.
    INC doubleJumpCounter
+skipJumping:
    ReturnBank
    RTS
 
Last edited:

mouse spirit

Well-known member
Awesome! Maybe switch where it INC. Or switch the order of your inputs in the input editor to try to fix the bug.I got it working in 4.1.5 but i need to reset when i hit the ground.. so i only get 2 jumps perscreen.But it works too!
 

mouse spirit

Well-known member
Got it workin . What i did to reset jumps was made an input script that said....

if onground
Make my variable 00

And put it on release any and hold any button.

Resets it just fine so far.
 

mouse spirit

Well-known member
Another thing i had to do is put my variable, for if i had double jump or not, into system variables manually. I forgot i needed to do that i guess.
But it works perfectly in 4.1.5 the way i have it.I know people had already done it for that version but im glad i didnt follow instructions and got it doneski's.
 

baardbi

Well-known member
Subotai said:
Hi Baardbi, did you succeed with double jump script without the infinite bug of jumping ?

No. Unfortunately I haven't had much time to work with NESmaker lately, since I'm moving to my new house. But when I get this script bug free I'll post it both here and in the Facebook group.
 

mouse spirit

Well-known member
I think to stop an infinite jump you would just add a variable. Whenever you jump INC the variable , if the variable is equal to 2, make it so you cant jump.
If you are onground, make variable 0.
 

vanderblade

Active member
Thanks for the leg work on this. I just beat my head against the code wall for the better part of an hour to get it working without the bug of infinite jumps. I use weaponsUnlocked for all my player abilities, which saves me having to add yet another variable (I'm at my limit basically). Anyway, for anybody who wants to see what I'm doing and how I'm slightly modifying the above (and it's admittedly inefficient as hell), here you go:

Edit: I noticed cases where if the player is running to the left near a solid tile edge, the jump won't register. I think this is because we are now checking for the #$00 tile, and there are times when players are on edges and their bottom hit box is touching both the empty tile and the solid tile. I took another 10-15 minutes to alter the code to avoid this problem. The new code (updated below) works perfectly as far as I can tell. It's not checking for #$00 tiles now, and checks the double jump stuff ONLY IF the player is not on a "solid" tile. Cheers, and let me know if you run into any bugs here.

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
    SwitchBank #$1C
    LDY Object_type,x
    LDA ObjectBboxTop,y
    CLC
    ADC ObjectHeight,y
    sta temp2
    
    LDA Object_x_hi,x
    CLC
    ADC ObjectBboxLeft,y
    STA temp
    JSR getPointColTable
    
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1
    CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
    
    CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
     CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is prize block .
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.

    BNE +dontDoJump
        JMP +doJump
          
        +dontDoJump
            ;; check second point.
        LDY Object_type,x
        LDA ObjectWidth,y
        CLC
        ADC temp
        STA temp
        JSR getPointColTable
        CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                            ;;; if it is (equal), can jump.
                                            ;;; if not, skips jumping.         
        BEQ +doJump
        
        CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
            JMP +checkIfCanDoubleJump       
            
        +checkIfCanDoubleJump
        LDA weaponsUnlocked
        AND #%00000010
        BNE +doubleJumpUnlocked
            JMP +skipJumping
        
        +doubleJumpUnlocked
        LDA doubleJumpCounter
        CMP #$02
        BEQ +skipJumping
        JMP +doJumpNoReset   

+doJump:
LDA #$00
STA doubleJumpCounter

+doJumpNoReset
    TXA
    STA temp ;; assumes the object we want to move is in x.
    ;PlaySound #sfx_thump

    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    EOR #$FF
    STA Object_v_speed_hi,x
        
    TXA
    STA temp ;; assumes the object we want to move is in x.
 ;  change the object's action so that he is in jump mode.
    INC doubleJumpCounter
    ReturnBank
    RTS

+skipJumping:
    ReturnBank
    RTS
 
Last edited:

mouse spirit

Well-known member
Thanks for the leg work on this. I just beat my head against the code wall for the better part of an hour to get it working without the bug of infinite jumps. I use weaponsUnlocked for all my player abilities, which saves me having to add yet another variable (I'm at my limit basically). Anyway, for anybody who wants to see what I'm doing and how I'm slightly modifying the above (and it's admittedly inefficient as hell), here you go:

Edit: I noticed cases where if the player is running to the left near a solid tile edge, the jump won't register. I think this is because we are now checking for the #$00 tile, and there are times when players are on edges and their bottom hit box is touching both the empty tile and the solid tile. I took another 10-15 minutes to alter the code to avoid this problem. The new code (updated below) works perfectly as far as I can tell. It's not checking for #$00 tiles now, and checks the double jump stuff ONLY IF the player is not on a "solid" tile. Cheers, and let me know if you run into any bugs here.

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
    SwitchBank #$1C
    LDY Object_type,x
    LDA ObjectBboxTop,y
    CLC
    ADC ObjectHeight,y
    sta temp2
  
    LDA Object_x_hi,x
    CLC
    ADC ObjectBboxLeft,y
    STA temp
    JSR getPointColTable
  
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1
    CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
  
    CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
     CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is prize block .
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.

    BNE +dontDoJump
        JMP +doJump
        
        +dontDoJump
            ;; check second point.
        LDY Object_type,x
        LDA ObjectWidth,y
        CLC
        ADC temp
        STA temp
        JSR getPointColTable
        CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                            ;;; if it is (equal), can jump.
                                            ;;; if not, skips jumping.       
        BEQ +doJump
      
        CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
            JMP +checkIfCanDoubleJump     
          
        +checkIfCanDoubleJump
        LDA weaponsUnlocked
        AND #%00000010
        BNE +doubleJumpUnlocked
            JMP +skipJumping
      
        +doubleJumpUnlocked
        LDA doubleJumpCounter
        CMP #$02
        BEQ +skipJumping
        JMP +doJumpNoReset 

+doJump:
LDA #$00
STA doubleJumpCounter

+doJumpNoReset
    TXA
    STA temp ;; assumes the object we want to move is in x.
    ;PlaySound #sfx_thump

    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    EOR #$FF
    STA Object_v_speed_hi,x
      
    TXA
    STA temp ;; assumes the object we want to move is in x.
;  change the object's action so that he is in jump mode.
    INC doubleJumpCounter
    ReturnBank
    RTS

+skipJumping:
    ReturnBank
    RTS
Nice. Yeah I have 2 variables for the jumps,or two spots on a flippy bitwise thing. Jorotroid did show me another place to initialize variables if you do run out of room,it's in memory map asm. I think it's right after a sound include and before the endm
 

baardbi

Well-known member
Thanks for the leg work on this. I just beat my head against the code wall for the better part of an hour to get it working without the bug of infinite jumps. I use weaponsUnlocked for all my player abilities, which saves me having to add yet another variable (I'm at my limit basically). Anyway, for anybody who wants to see what I'm doing and how I'm slightly modifying the above (and it's admittedly inefficient as hell), here you go:

Edit: I noticed cases where if the player is running to the left near a solid tile edge, the jump won't register. I think this is because we are now checking for the #$00 tile, and there are times when players are on edges and their bottom hit box is touching both the empty tile and the solid tile. I took another 10-15 minutes to alter the code to avoid this problem. The new code (updated below) works perfectly as far as I can tell. It's not checking for #$00 tiles now, and checks the double jump stuff ONLY IF the player is not on a "solid" tile. Cheers, and let me know if you run into any bugs here.

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
    SwitchBank #$1C
    LDY Object_type,x
    LDA ObjectBboxTop,y
    CLC
    ADC ObjectHeight,y
    sta temp2
  
    LDA Object_x_hi,x
    CLC
    ADC ObjectBboxLeft,y
    STA temp
    JSR getPointColTable
  
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1
    CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
  
    CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
     CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is prize block .
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.

    BNE +dontDoJump
        JMP +doJump
        
        +dontDoJump
            ;; check second point.
        LDY Object_type,x
        LDA ObjectWidth,y
        CLC
        ADC temp
        STA temp
        JSR getPointColTable
        CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                            ;;; if it is (equal), can jump.
                                            ;;; if not, skips jumping.       
        BEQ +doJump
      
        CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
            JMP +checkIfCanDoubleJump     
          
        +checkIfCanDoubleJump
        LDA weaponsUnlocked
        AND #%00000010
        BNE +doubleJumpUnlocked
            JMP +skipJumping
      
        +doubleJumpUnlocked
        LDA doubleJumpCounter
        CMP #$02
        BEQ +skipJumping
        JMP +doJumpNoReset 

+doJump:
LDA #$00
STA doubleJumpCounter

+doJumpNoReset
    TXA
    STA temp ;; assumes the object we want to move is in x.
    ;PlaySound #sfx_thump

    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    EOR #$FF
    STA Object_v_speed_hi,x
      
    TXA
    STA temp ;; assumes the object we want to move is in x.
;  change the object's action so that he is in jump mode.
    INC doubleJumpCounter
    ReturnBank
    RTS

+skipJumping:
    ReturnBank
  
[/QUOTE]

Thanks for the leg work on this. I just beat my head against the code wall for the better part of an hour to get it working without the bug of infinite jumps. I use weaponsUnlocked for all my player abilities, which saves me having to add yet another variable (I'm at my limit basically). Anyway, for anybody who wants to see what I'm doing and how I'm slightly modifying the above (and it's admittedly inefficient as hell), here you go:

Edit: I noticed cases where if the player is running to the left near a solid tile edge, the jump won't register. I think this is because we are now checking for the #$00 tile, and there are times when players are on edges and their bottom hit box is touching both the empty tile and the solid tile. I took another 10-15 minutes to alter the code to avoid this problem. The new code (updated below) works perfectly as far as I can tell. It's not checking for #$00 tiles now, and checks the double jump stuff ONLY IF the player is not on a "solid" tile. Cheers, and let me know if you run into any bugs here.

Code:
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Only can jump if the place below feet is free.
    SwitchBank #$1C
    LDY Object_type,x
    LDA ObjectBboxTop,y
    CLC
    ADC ObjectHeight,y
    sta temp2
   
    LDA Object_x_hi,x
    CLC
    ADC ObjectBboxLeft,y
    STA temp
    JSR getPointColTable
   
    LDA Object_y_hi,x
    CLC
    ADC #$02
    CLC
    ADC temp2
    STA temp1
    CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
   
    CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
    BNE +checkMore
        JMP +doJump
    +checkMore
     CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is prize block .
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.

    BNE +dontDoJump
        JMP +doJump
         
        +dontDoJump
            ;; check second point.
        LDY Object_type,x
        LDA ObjectWidth,y
        CLC
        ADC temp
        STA temp
        JSR getPointColTable
        CheckCollisionPoint temp, temp1, #$01, tempA ;; check below feet to see if it is solid.
                                            ;;; if it is (equal), can jump.
                                            ;;; if not, skips jumping.        
        BEQ +doJump
       
        CheckCollisionPoint temp, temp1, #$07, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
        CheckCollisionPoint temp, temp1, #$09, tempA ;; check below feet to see if it is jumpthrough platform.
                                        ;;; if it is (equal), can jump.
                                        ;;; if not, skips jumping.
        BEQ +doJump
            JMP +checkIfCanDoubleJump      
           
        +checkIfCanDoubleJump
        LDA weaponsUnlocked
        AND #%00000010
        BNE +doubleJumpUnlocked
            JMP +skipJumping
       
        +doubleJumpUnlocked
        LDA doubleJumpCounter
        CMP #$02
        BEQ +skipJumping
        JMP +doJumpNoReset  

+doJump:
LDA #$00
STA doubleJumpCounter

+doJumpNoReset
    TXA
    STA temp ;; assumes the object we want to move is in x.
    ;PlaySound #sfx_thump

    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    EOR #$FF
    STA Object_v_speed_hi,x
       
    TXA
    STA temp ;; assumes the object we want to move is in x.
;  change the object's action so that he is in jump mode.
    INC doubleJumpCounter
    ReturnBank
    RTS

+skipJumping:
    ReturnBank
    RTS
Hey. That's great. I have changed so much in my code at this point, so I'm afraid to include new changes since I'm pretty much finished with the game. I'll definitely take a closer look at your code though. Thanks for posting this.
 

baardbi

Well-known member
Did the infinite jump work similar to a Joust flying mechanic, and if not could it be tweaked to do so?
No. Unfortunately it's a little unreliable. Sometimes it happens and sometimes not. It would have to be changed to work like Joust. With a little ASM coding that should actually be pretty simple.
 
Top Bottom