chronicleroflegends
Member
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.
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.
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.
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
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.