Platformer module: Give the player special abilities! With toggle.

Just wanted to share a script I came up with for my game.
I wanted the player to have more abilities than there are buttons on the NES controller.
With this script I can let the player cycle through any abilities you have defined.
So you can have Mega Man or Metroid style unlockable abilities :)

My solution:
Pressing the select button scrolls through your 'special abilities' and a certain button combo activates them (In my case DOWN+B)

This is done with two scripts:
One alters a user variable plrAbility when you press the select button:
It also rolls back over to the first ability when you reach the end.
I recommend altering the maximum ability to match how many you have, but if you have empty slots they seem to default to ability 0.
Code:
;; Change the players selected ability variable
    LDA plrAbility
    CMP #$07 ; The maximum ability value - equal to the number of abilities
    BCC notLastAbility
    JMP LastAbility

notLastAbility:
    LDA plrAbility
    CLC
    ADC #$01
    STA plrAbility
    JMP abilityFinishedChanging
    
LastAbility:
    LDA #$00
    STA plrAbility
    JMP abilityFinishedChanging
    
abilityFinishedChanging:
    RTS

The second part is more complicated. In the input editor set this script to HOLD on only the FIRST button of the combo.
The second button is checked for in the script. So when you press the first button and then the next button also it triggers the ability.
Code:
;; Determine input type
;; Cancel if any other direction except DOWN is pressed
    LDA gamepad
    AND #%01000000 ;Keep only left bit
    CMP #%01000000 ;LEFT
    BEQ +
    LDA gamepad
    AND #%10000000 ;Keep only right bit
    CMP #%10000000 ;RIGHT
    BEQ +
    LDA gamepad
    AND #%00010000 ;Keep only UP bit
    CMP #%00010000 ;UP
    BEQ +
    LDA gamepad
    AND #%00100000 ;Keep only DOWN bit
    CMP #%00100000 ;DOWN
    BEQ gamepadDownIsPressed
    JMP + ;No direction is pressed, so no special actions can be taken
+
    RTS

;; Down is pressed, is anything else pressed?
gamepadDownIsPressed:
    LDA gamepad
    AND #%00000010 ; Keep only B bit
    CMP #%00000010
    BEQ gamepadDownB ; Advance to activating special
    JMP gamepadDownOnly ;Nothing else was pressed

;; --INPUT STATE: DOWN + B--
gamepadDownB:
    LDA plrAbility
    CMP #$00
    BEQ jumpSpecialMove0
    LDA plrAbility
    CMP #$01
    BEQ jumpSpecialMove1
    LDA plrAbility
    CMP #$02
    BEQ jumpSpecialMove2
    LDA plrAbility
    CMP #$03
    BEQ jumpSpecialMove3  
    
jumpSpecialMove0:
    JMP specialMove0
    
jumpSpecialMove1:
    JMP specialMove1
    
jumpSpecialMove2:
    JMP specialMove2
    
jumpSpecialMove3:
    JMP specialMove3

;; ---SPECIAL MOVES-------------------------------------------------------    
;; --DEFINE WHAT YOUR SPECIAL MOVES DO HERE
;; --TODO: LIMIT ALL SPECIAL MOVES WITH A COOLDOWN TIMER
specialMove0:
specialMove1:
specialMove2:
specialMove3:

;; ---END SPECIAL MOVES-------------------------------------------------------  
    
;; --INPUT STATE: DOWN ONLY--
gamepadDownOnly:
;; Set player action state to crouch
LDX player1_object
LDA Object_status,x
AND #%00000100
BEQ +
ChangeObjectState #$03, #$02

;; --Finish Script--
+

RTS
Improvements I want to make but not implemented yet:
Tie the abilities to the weapons unlocked variable, so they are not all there by default.
Limit ability use to a cooldown timer so you cannot just spam the ability.
 

dale_coop

Moderator
Staff member
Nice script :)
I made something like that too for my 4.0.11 demo I submit for the challenges (3 weapons/abilities to unlock/buy, and cycle between them using "SELECT" button).
 

rimoJO

Member
Modifying a user variable? How do you do that? Is there a certain script? Also, 4.1.0's simple platformer module has no user variables.
Also wait a minute. Buying items? I thought shops didn't work!
 

dale_coop

Moderator
Staff member
Shops are not yet implemented in NESmaker. But NPC giving items/weapons works. Now imagine, if the NPC was checking if the player have enough money before continuing his action. You could implement not a shop but a room where you have some NPCs that can give you item if you have money.
It woudl required some custom scripts... will be very specific for a game... not very versatile.
But before that, I think you would have to find a way to swtich between different weapons... that also required some custom scripts and user variables.
 

dale_coop

Moderator
Staff member
I don't think anyone have made yet versatile scripts for that (we'd need scripts that could be used for everyone's project... and not only for my/your specific game).
 

dale_coop

Moderator
Staff member
But... someone will end posting a tutorial. a lot of people asking for that (multiple weapons and switch between them), so...
Stay tuned!
 
Top Bottom