[4.5.9] Using Less Movement Inputs

crazygrouptrio

Active member
In making Tryptic I came to the realization that having lots of set Inputs can cause your game to run slowly! And if you have a 4 directional game and use the provided NESmaker input scripts you'll be using 16 different inputs just for moving! (Move, Stop, Start Action, Stop Action for each direction). To cut this down, I simply combined the movement and change action scripts. This cuts down on inputs, and actually frees up a small amount of bank space.

Move Left:
Code:
    STX temp ;; assumes the object we want to move is in x.
    StartMoving temp, #LEFT
        
            STX temp ;; assumes the object we want to move is in x.
            ChangeFacingDirection temp, #FACE_LEFT
        
        checkWalkAction:
            ; check for actions where we don't want to change to walking action
            ; such as walking or jumping
            GetActionStep temp
            CMP #$01 ; walk
            BEQ +done
            CMP #$02 ; jump
            BEQ +done
            CMP #$07 ; hurt
            BEQ +done 
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ChangeActionStep temp, #$01 ;; assumes that "walk" is in action 1
        +done

    RTS

Now every other direction is slightly different:

Move Right:
Code:
   STX temp ;; assumes the object we want to move is in x.
   StartMoving temp, #RIGHT

        STX temp ;; assumes the object we want to move is in x.
        ChangeFacingDirection temp, #FACE_RIGHT
        JMP checkWalkAction
    RTS

Use this same code for Up and Down if you need and just replace the movement directions. There's no reason to use the "check if we're walking" portion of the code in each script when we can just jump to it, which is part of why this saves space. Now just assign it to "Hold" in your inputs just as you normally would for the StartMoving scripts.

Now we just need to stop movement and set action to Idle:

Stop Movement:
Code:
    STX temp ;; assumes the object we want to move is in x.
    GetActionStep temp
        CMP #$07
        BNE +notHurt
            JMP +done
        +notHurt
        
        ; use this for 4 directional game - adventure
         LDA gamepad
         AND #%11110000
         BEQ changeToStop_NoDpadPressed
         JMP +done
            
        ; use this for 2 directional game - i.e. platformer, metroidvania
       ; LDA gamepad
       ; AND #%11000000
       ; BEQ changeToStop_NoDpadPressed
       ; JMP +done

    changeToStop_NoDpadPressed:
        ChangeActionStep temp, #$00 ;; assumes that "idle" is in action 0
        StopMoving temp, #$FF, #$00
        
        +done
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    RTS

You can swap out the middle portion depending on what type of game you have. Set it to "Release" just as you would for the default stop movement.

And that's it! We've cut our number of inputs in half!

Here's a rundown:

Advantages:
* Less inputs
* Less slow down
* Less bank space
* Fixes the "return to walking after attacking" issue

Disadvantages:
* A little less fluid in 4 directional games, but still playable
 

Bucket Mouse

Active member
I just tried it. It works, but with one alteration: changeToStop_NoDpadPressed should actually be +changeToStop_NoDpadPressed. Since you have to assign Stop Movement to each direction, it will try to compile that name four times and create an error.

Also, with the new inputs in place, my sprite will freeze when attacking for the full duration of the attack step -- it can't move. With the original input system I did not have to wait -- any of the directional buttons would break that freeze. Is this what you meant by "a little less fluid"? It's kind of a dealbreaker, especially since it doesn't actually seem to reduce slowdown for me.
 

crazygrouptrio

Active member
I just tried it. It works, but with one alteration: changeToStop_NoDpadPressed should actually be +changeToStop_NoDpadPressed. Since you have to assign Stop Movement to each direction, it will try to compile that name four times and create an error.

Also, with the new inputs in place, my sprite will freeze when attacking for the full duration of the attack step -- it can't move. With the original input system I did not have to wait -- any of the directional buttons would break that freeze. Is this what you meant by "a little less fluid"? It's kind of a dealbreaker, especially since it doesn't actually seem to reduce slowdown for me.
You assign Stop to each direction but there is only 1 instance of the script loaded in, so it's fine as-is.

It will obviously not fit every instance as it is, and yeah the provided input scripts may be perfectly fine for some games. In my game I wanted the player to stop while attacking then continue walking if the direction is held (like Zelda) and this does that without any other alterations. I would assume if your attack step isn't listed under "checkWalkAction" it will change to walk when a direction is pressed.
 
Top Bottom