;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; AI SCRIPT: move away from player
;;
;;
;; Store the object's slot index (which is in the x-register) in
;; the tempx variable for later use.
STX tempx
;; Store the current position of the object into held argument
;; variables for use with the doMoveTowardsPoint subroutine
LDA Object_x_hi,x
STA arg0_hold
LDA Object_y_hi,x
STA arg1_hold
;; Store the current position of the player into held argument
;; variables for use with the doMoveTowardsPoint subroutine.
LDX player1_object
LDA Object_x_hi,x
STA arg2_hold
LDA Object_y_hi,x
STA arg3_hold
STA tempD
;; Restore the object's slot index from the tempx variable and
;; into the x-register.
LDX tempx
;; Get the "move towards point" values. This subroutine is found
;; in bank $18, so we need to bankswitch as well. Because both
;; doMoveTowardsPoint and the SwitchBank macro clobber the
;; y-register, we need to push that onto the stack, so we can
;; restore it after.
TYA
PHA
SwitchBank #$18
JSR doMoveTowardsPoint
ReturnBank
PLA
TAY
;; doMoveTowardsPoint also clobbers the X-register, so we need to
;; restore the object's slot id from the tempx variable into
;; the x-register again.
LDX tempx
;; Reverse the object's horizontal speed, so that the object
;; moves in the exact opposite direction.
LDA tempA
EOR #$FF
CMP #$7F
BEQ +
CLC
ADC #1
+
STA Object_h_speed_lo,x
;; Now do the same for the object's vertical speed.
LDA tempB
EOR #$FF
CMP #$7F
BEQ +
CLC
ADC #1
+
STA Object_v_speed_lo,x
;; Reset the high byte of the object's speed, beause aimed
;; physics by default only set the low byte.
LDA #$00
STA Object_h_speed_hi,x
STA Object_v_speed_hi,x
;; ...I think this forces the object to use aimed physics for
;; the rest of the main game loop?
LDA Object_direction,x
AND #%00000111
ORA #%00001000
STA Object_direction,x