Double Jump Guide?

Discussion in 'Discussion & Q&A' started by FlyTF, Jul 1, 2017.

Thread Status:
Not open for further replies.
  1. FlyTF

    FlyTF Newcomer Trialist

    Joined:
    Dec 1, 2015
    Messages:
    8
    On Sonic Games Dimension was a guide with this code, the problem is that it was closed.
    Code:
    ; ---------------------------------------------------------------------------
    ; EB's double jump code
    ; ---------------------------------------------------------------------------
    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
    Sonic_DoubleJump:
            cmpi.b    #2,$1C(a0)            ; EB: is the current animation rolling?
            bne.s    @return                ; EB:  if not, branch
            btst    #7,$22(a0)        ; EB: read if DoubleJump flag was set
            bne.s    @return                ; EB: was it set? if not, branch
            move.b    ($FFFFF603).w,d0        ; EB: read the controller
            tpress    A,(SonicControl)            ; EB: was A,B or C pressed?
            beq.w    @return                ; EB: if not, branch
            bset    #7,$22(a0)        ; EB: set DoubleJump flag
            move.w    #$A0,d0            ; EB: play 'jump' sound
            jsr    (PlaySound_Special).l   ; ^
            move.w  #-1500,$12(A0)          ; EB: set Y speed
            move.w  #6, $10 (a0)            ; EB: clear X speed
    @return:
                    rts                             ; EB: return
    And the problem is that Double Jump works once.
    Please help.
    Sorry for grammar, i'm russian
     
  2. AkumaYin

    AkumaYin Well-Known Member Exiled

    Joined:
    Aug 21, 2014
    Messages:
    157
    My guess is that, the code sets the double jump flag after the button is pressed, but doesn't seem to clear it once Sonic lands on a solid surface. Notice how this line:
    Code:
    btst    #7,$22(a0)        ; EB: read if DoubleJump flag was set
    ...runs a check to determine whether or not the double jump flag has already been set (to ensure you can't air-jump infinitely), and this line:
    Code:
    bset    #7,$22(a0)        ; EB: set DoubleJump flag
    ...is what actually sets the flag, right after A, B, or C is pressed. As I said earlier, there's no function to clear the flag once Sonic lands, so the next time you attempt a double jump it reads that the flag is still set. You'll need to find the subroutine that resets Sonic's modes upon floor collision and add extra functions to check for the flag and reset it.
     
    vladikcomper and TheInvisibleSun like this.
  3. FlyTF

    FlyTF Newcomer Trialist

    Joined:
    Dec 1, 2015
    Messages:
    8
    Okay, and the final code is?:

    Code:
    ; ---------------------------------------------------------------------------
    ; EB's double jump code
    ; ---------------------------------------------------------------------------
    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
    Sonic_DoubleJump:
            cmpi.b    #2,$1C(a0)            ; EB: is the current animation rolling?
            bne.s    @return                ; EB:  if not, branch
            btst    #7,$22(a0)        ; EB: read if DoubleJump flag was set
            bne.s    @return                ; EB: was it set? if not, branch
            move.b    ($FFFFF603).w,d0        ; EB: read the controller
            tpress    A,(SonicControl)            ; EB: was A,B or C pressed?
            bset    #7,$22(a0)        ; EB: set DoubleJump flag       
            beq.w    @return                ; EB: if not, branch
            bset    #7,$22(a0)        ; EB: set DoubleJump flag
            move.w    #$A0,d0            ; EB: play 'jump' sound
            jsr    (PlaySound_Special).l   ; ^
            move.w  #-1500,$12(A0)          ; EB: set Y speed
            move.w  #6, $10 (a0)            ; EB: clear X speed
    @return:
                    rts                             ; EB: return
     
  4. FlyTF

    FlyTF Newcomer Trialist

    Joined:
    Dec 1, 2015
    Messages:
    8

    Okay, do I need to add ?:
    Sonic_ResetOnFloor:
    If _DoubleJump_
    Bclr # 7, $ 22 (a0)
    endc

    Sorry for Double post.
     
    Last edited: Jul 1, 2017
  5. AkumaYin

    AkumaYin Well-Known Member Exiled

    Joined:
    Aug 21, 2014
    Messages:
    157
    Correct, the bclr line simply needs to be added to the beginning of "Sonic_ResetOnFloor". The other two lines are only necessary if you're using "if" statements to enable or disable the move (think ReadySonic).
     
    FlyTF likes this.
  6. FlyTF

    FlyTF Newcomer Trialist

    Joined:
    Dec 1, 2015
    Messages:
    8
    Now Double Jump is working correctly. Thank you!
     
Thread Status:
Not open for further replies.