crazygrouptrio
Active member
Nothing too exciting here, just thought I'd share my modified version of the attack script from the Brawler module, it can be used in Platformers as well. It could be used in other modules if you edit it enough.
I've set it up to be more customizable without using more space (as-is it may actually be smaller than the original script).
For example: You can add multiple objects, object states, spawn points, etc.
First of all just add this to your Zero Page Ram:
Here is the attack script. Just copy it and add it to your input scripts, and set it to the gamepad like normal.
The code has several comments that explain what does what where, and it will be up to you to set everything up to fit your game. Many of the values used in the script are just placeholder that I used for my game. You can add more attacks of different varieties as long as they follow the same setup I've provided.
This script DOES use many variables (tempx, tempy, tempA, etc). It's never caused problems for me, but if it does just create new variables and use those instead.
I've set it up to be more customizable without using more space (as-is it may actually be smaller than the original script).
For example: You can add multiple objects, object states, spawn points, etc.
First of all just add this to your Zero Page Ram:
Code:
tempCGT
Code:
TXA
STA temp ;; assumes the object that we want is in x.
; here we're going to get the player's direction and store it to determine states
; if your object doesn't use different states, you can comment out these and other tempCGT lines
GetObjectDirection temp
STA tempCGT
; set which action steps do not allow attacking, or what attacks need to be performed
; I'll just display 2 attacks, but you can add more and change them, as long as they
; are set up like the attacks below.
GetActionStep temp
CMP #$02 ; jumping
BEQ setJumpAttack ; we have a jump attack separate from regular attack so we "jump" to that
CMP #$03 ; attacking
BEQ noAttack
CMP #$05 ; crouching
BEQ noAttack
; nothing else interrupted so normal attack state
ChangeActionStep temp, #$03
; my attacks require a different Y coord, so we'll set it here for regular attack
LDA #$09
STA tempy
; set the action state here
; we're checking for left or right to determine which state to make
LDA tempCGT
CMP #$02 ; check for right
BEQ +facingRight
LDA #$01 ; left state weapon 1
JMP setWeaponState
+facingRight
LDA #$00 ; right state weapon 1
JMP setWeaponState
noAttack:
RTS
setJumpAttack:
ChangeActionStep temp, #$06
; my objects use a different Y coord, so we'll set it here
LDA #$1F
STA tempy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; if this uses a different object, you can set that here, for example:
; LDA "your object #"
; STA "variable of your choice"
; then add your variable in the create object macro further down,
; replacing the "#$02", as long as all attacks store to that variable as well
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; set the action state here
; my jump attack uses the same blank action state,
; so we don't need to check direction for what state to draw
LDA #$04 ; state for weapon 2
JMP setWeaponState
setWeaponState:
; this stores the weapon object for all attacks
STA tempC
continueAttack:
; if you want to stop moving uncomment this line,
; though I've never seen this actually work outside of the brawler module
; StopMoving temp, #$FF;, #$00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Now, we have to create the object.
;; We will need to determine the direction
;; of the player.
;; We already have this loaded into tempCGT, so we can just check that
LDA tempCGT
CMP #$02
BNE +notRight
;;; CREATE RIGHT WEAPON
;;; now that we know the direction we can set the X value here
LDA #$10
STA tempx
LDX player1_object
LDA Object_x_hi,x
CLC
ADC tempx
STA tempA
LDA Object_screen,x
ADC #$00
STA tempD
LDA Object_y_hi,x
CLC
ADC tempy
STA tempB
;; we're actually creating the object now
;; this is the macro defined to help keep track of what's what
; CreateObjectOnScreen x, y, object, state, currentNametable
; all of these variables should be defined above
; in my case all weapons are stored in object #$02, but you can
; swap it out for your own weapon # or defined variable
CreateObjectOnScreen tempA, tempB, #$02, tempC, tempD
LDA #%11000000
STA Object_direction,x
JMP +doneWithCreatingWeapon
+notRight
;;; CREATE LEFT WEAPON
;;; now that we know the direction we can set the X value here
LDA #$F9
STA tempx
LDX player1_object
LDA Object_x_hi,x
CLC
ADC tempx
STA tempA
LDA Object_screen,x
SBC #$00
STA tempD
LDA Object_y_hi,x
CLC
ADC tempy
STA tempB
;; we're actually creating the object now
;; this is the macro defined to help keep track of what's what
; CreateObjectOnScreen x, y, object, state, currentNametable
; all of these variables should be defined above
; in my case all weapons are stored in object #$02, but you can
; swap it out for your own weapon # or defined variable
CreateObjectOnScreen tempA, tempB, #$02, tempC, tempD
LDA #%10000000
STA Object_direction,x
JMP +doneWithCreatingWeapon
+notLeft
+doneWithCreatingWeapon
; use your attack sound here. swish, zap, pow!
PlaySound #2
RTS
This script DOES use many variables (tempx, tempy, tempA, etc). It's never caused problems for me, but if it does just create new variables and use those instead.