BillNyeAutisticGuy
New member
I made a new AI for my monster, however, when I place him, he doesn't do anything. Is this a glitch, or is it my code that's the problem?
Here's the code. It's an updated version of Bucket Mouse's move towards player script I made. Tell me if there is something wrong with it.
Here's the code. It's an updated version of Bucket Mouse's move towards player script I made. Tell me if there is something wrong with it.
Code:
LDY player1_object ;;load player object into Y register
;; Note: if this is an ai script, X should already be loaded with the current object, so no need to worry about that.
LDA #$00
STA temp ;;this is just to zero out the variable in case there's something there leftover from another script
LDA Object_x_hi,y
CMP Object_x_hi,x
BCC playerIsToMyLeft ;;BCC or "branch on carry clear" acts as a "is this value less than the value I'm comparing it to?" after a compare instruction
;; If it didn't branch, that means the player is to my right
LDA #%000000010
STA Object_movement,x
TAY
LDA DirectionMovementTable,y
STA temp
TYA
ORA temp
STA Object_movement,x
JMP skiptoAboveBelowCheck
playerIsToMyLeft:
BEQ skiptoAboveBelowCheck ;;since we only checked for "less than", we need to branch if both values are the same
LDA #%000000110
STA Object_movement,x
TAY
LDA DirectionMovementTable,y
STA temp
TYA
ORA temp
STA Object_movement,x
skiptoAboveBelowCheck:
LDA Object_y_hi,y
CMP Object_y_hi,x
BCC playerIsAboveMe
LDA #%000000000
STA Object_movement,x
TAY
LDA DirectionMovementTable,y
STA temp
TYA
ORA temp
STA Object_movement,x
JMP endMoveTowardPlayer
playerIsAboveMe:
BEQ endMoveTowardPlayer
LDA #%000000100
STA Object_movement,x
TAY
LDA DirectionMovementTable,y
STA temp
TYA
ORA temp
STA Object_movement,x
endMoveTowardPlayer:
LDA temp ;; temp should now be loaded with the movement information we want, and we can now store it in this object's Object_movement variable, which will make it move.
STA Object_movement,x
;; no RTS because it's an AI script, and they manage subroutines and returns already