[4.5.9] Holding B to Run

dale_coop

Moderator
Staff member
A small tutorial to show how to implement the Holding B to Run in your projects.

HoldingB.gif

The principle is simple, we'll modify the Physics to modify the speed when B is pressed.

INSTRUCTIONS

Modify your Handle Physics script (you can find it in the "Project Settings > Script Settigns" under "SubRoutines").
Find those exact lines in the script (around line 110 or 270 or 280 depending of the module used):
Code:
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        ASL
        ASL
        ASL
        ASL
        ;AND #%00001111
        STA myMaxSpeed
        LDA ObjectMaxSpeed,y
        LSR
        LSR
        LSR
        LSR
        STA myMaxSpeed+1

And replace those lines with:
Code:
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        STA tempA
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; if holding B
        CPX player1_object
        BNE +skip   ;; if not the player object, we skip
            LDA gamepad
            AND #%00000010  ;; B button
            BEQ +skip
                LDA tempA
                ASL     ;; double the speed
                STA tempA
        +skip:
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        LDA tempA
        ASL
        ASL
        ASL
        ASL
        ;AND #%00001111
        STA myMaxSpeed
        LDA tempA
        LSR
        LSR
        LSR
        LSR
        STA myMaxSpeed+1

Voilà, that's it.
 

NightMusic

Member
A small tutorial to show how to implement the Holding B to Run in your projects.

View attachment 7869

The principle is simple, we'll modify the Physics to modify the speed when B is pressed.

INSTRUCTIONS

Modify your Handle Physics script (you can find it in the "Project Settings > Script Settigns" under "SubRoutines").
Find those exact lines in the script (around line 110 or 270 or 280 depending of the module used):
Code:
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        ASL
        ASL
        ASL
        ASL
        ;AND #%00001111
        STA myMaxSpeed
        LDA ObjectMaxSpeed,y
        LSR
        LSR
        LSR
        LSR
        STA myMaxSpeed+1

And replace those lines with:
Code:
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        STA tempA
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; if holding B
        CPX player1_object
        BNE +skip   ;; if not the player object, we skip
            LDA gamepad
            AND #%00000010  ;; B button
            BEQ +skip
                LDA tempA
                ASL     ;; double the speed
                STA tempA
        +skip:
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        LDA tempA
        ASL
        ASL
        ASL
        ASL
        ;AND #%00001111
        STA myMaxSpeed
        LDA tempA
        LSR
        LSR
        LSR
        LSR
        STA myMaxSpeed+1

Voilà, that's it.
This is awesome! Run Agent Cooper Run! (get that next cup of midnight black coffee!) :) thank you
 

TheRetroBro

Active member
A small tutorial to show how to implement the Holding B to Run in your projects.

View attachment 7869

The principle is simple, we'll modify the Physics to modify the speed when B is pressed.

INSTRUCTIONS

Modify your Handle Physics script (you can find it in the "Project Settings > Script Settigns" under "SubRoutines").
Find those exact lines in the script (around line 110 or 270 or 280 depending of the module used):
Code:
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        ASL
        ASL
        ASL
        ASL
        ;AND #%00001111
        STA myMaxSpeed
        LDA ObjectMaxSpeed,y
        LSR
        LSR
        LSR
        LSR
        STA myMaxSpeed+1

And replace those lines with:
Code:
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        STA tempA
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; if holding B
        CPX player1_object
        BNE +skip   ;; if not the player object, we skip
            LDA gamepad
            AND #%00000010  ;; B button
            BEQ +skip
                LDA tempA
                ASL     ;; double the speed
                STA tempA
        +skip:
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        LDA tempA
        ASL
        ASL
        ASL
        ASL
        ;AND #%00001111
        STA myMaxSpeed
        LDA tempA
        LSR
        LSR
        LSR
        LSR
        STA myMaxSpeed+1

Voilà, that's it.
will this work in platformer if Im using b to shoot?
 

dale_coop

Moderator
Staff member
it should work too (like when Mario shoot a fireball before starting to run ;))
(....Unless your 'B shoot' stops the player's movements)
 

TheRetroBro

Active member
it should work too (like when Mario shoot a fireball before starting to run ;))
(....Unless your 'B shoot' stops the player's movements)
So I implemented this and it works . My only questions is can I change the increase speed to say 20% instead of 50? 50 is just way too fast!
 

dale_coop

Moderator
Staff member
If you want to use a more precise speed run, you could replace the
Code:
LDA tempA
ASL     ;; double the speed
STA tempA

With:
Code:
LDA tempA
CLC
ADC #16 ;; you can use any value here from 00 to 255 to adjust the running speed
STA tempA
 

Luxnolucas

New member
Yep, i try to use this
Code:
pha
  CPX player1_object
  LDA Object_h_speed_hi,x
  SEC
  SBC #$02   ; Ralentissement
  STA Object_h_speed_hi,x
 
  LDA Object_v_speed_hi,x
  SEC
  SBC #$00   ; Ralentissement
  STA Object_v_speed_hi,x
pla

But it's not really smooth... And ultimately, managing the scrolling speed with keys is more suitable than with tiles.
thanks
 
Top Bottom