crazygrouptrio
Active member
I've spent the past few days working in terms of monsters movement depending on the player and I combined them all into one action. It fixes a lot of things that are troublesome with NESmaker core scripts so I wanted to share. Ideally this script is for platformer modules but could be used in others I'm sure.
First we need to do a few things. Go to your Zero Page Ram tab and add:
Next, if you plan to use this for recoil, track down where recoil is handled in the physics script (around line 170 for me) and remove it however you deem fit. You can use an Action Step Flag, skip the code, or just gut it out (Unless you need it for the player. This will only recoil the monster). We just don't want both recoil systems trying to trigger at the same time.
Now here is the action script:
Save this as an ASM in a new file and add it to your AI Actions wherever you want and label it. I've added notes that explain how it works in the script, short version is it checks the monster number up top if you want it to move in 8 directions, and defaults to 2 directions if no monster is checked (the example in the script is Monster #22). Increased speed works the same, checks a monster if you want to increase speed, if monster isn't listed it won't.
If you're using this for recoil, set the Hurt step (7) to this action and it will recoil away when its hurt and increase its speed. This functions differently than the default recoil, in that it determines where the player is, and just moves in the opposite direction with increased speed that I've set, rather than the default which is a bit more complex. So if you have any issues, that's probably why.
Enjoy!
What this Action does:
8 Directional Movement Towards Player
Increased Speed when Moving Towards in Player in 8 directions (Optional)
2 Directional Movement Towards Player
Handles Functional Recoil (LR Only)
Move Towards Player LR--------- Move Towards Player 8 Direction --------- Recoil Away from Player
All using the same Action. Neat huh?
8 Directional Movement Towards Player
Increased Speed when Moving Towards in Player in 8 directions (Optional)
2 Directional Movement Towards Player
Handles Functional Recoil (LR Only)
Move Towards Player LR--------- Move Towards Player 8 Direction --------- Recoil Away from Player
All using the same Action. Neat huh?
First we need to do a few things. Go to your Zero Page Ram tab and add:
This is used so pieces of the script can be handled differently without rewriting it all.tempCGT
Next, if you plan to use this for recoil, track down where recoil is handled in the physics script (around line 170 for me) and remove it however you deem fit. You can use an Action Step Flag, skip the code, or just gut it out (Unless you need it for the player. This will only recoil the monster). We just don't want both recoil systems trying to trigger at the same time.
Now here is the action script:
Code:
LDA Object_type,x
CMP #22 ; # of monster
BEQ move8Directions
; add 8 directional monsters here
JMP move2Directions
move8Directions:
TYA
PHA
TXA
PHA
STA tempx
LDA Object_x_hi,x
STA tempA
LDA Object_y_hi,x
STA tempB
LDX player1_object
LDA Object_x_hi,x
STA tempC
LDA Object_y_hi,x
STA tempD
LDX tempx
MoveTowardsPoint tempA, tempC, tempB, tempD
LDA Object_direction,x
AND #%00000111
ORA #%00001000
STA Object_direction,x
; do you want the monster to move faster when they approach player? add them here
LDA Object_type,x
CMP #22 ; monsters you want to move faster
BEQ speedUp
JMP ++
speedUp:
LDA tempA
STA Object_h_speed_lo,x
LDA #$01
STA Object_h_speed_hi,x
LDA tempB
STA Object_v_speed_lo,x
LDA #$01
STA Object_v_speed_hi,x
++
LDA tempCGT
BNE +
PLA
TAX
PLA
TAY
+
RTS
move2Directions:
TXA
STA temp
GetActionStep temp
CMP #$07
BNE +notHurt
LDA #$01
STA tempCGT ; if we are recoiling we need to ignore some parts of script
JMP +doManualRecoil
; this monster is hurt so we are going to make him recoil in L or R direction
+notHurt
LDY player1_object
LDA #$00
STA temp
LDA Object_x_hi,y
CMP Object_x_hi,x
BCC moveLeft
moveRight:
LDA #%000000010
STA Object_direction,x
TAY
LDA DirectionTableOrdered,y
STA temp
TYA ;; the 0-7 value for direction
ORA temp
STA Object_direction,x
JMP +
moveLeft:
LDA #%000000110
STA Object_direction,x
TAY
LDA DirectionTableOrdered,y
STA temp
TYA ;; the 0-7 value for direction
ORA temp
STA Object_direction,x
+
LDA tempCGT
BEQ +
TXA
LDA Object_x_hi,x
STA tempA
LDA Object_y_hi,x
STA tempB
JSR speedUp
LDA #$00
STA tempCGT
+
RTS
+doManualRecoil
LDY player1_object
LDA #$00
STA temp
LDA Object_x_hi,y
CMP Object_x_hi,x
BCC moveRight
JMP moveLeft
RTS
If you're using this for recoil, set the Hurt step (7) to this action and it will recoil away when its hurt and increase its speed. This functions differently than the default recoil, in that it determines where the player is, and just moves in the opposite direction with increased speed that I've set, rather than the default which is a bit more complex. So if you have any issues, that's probably why.
Enjoy!
Last edited: