SOLVED [4.5.6] AI Directional Based Proxy

Craigery

Active member
I have written a new AI code for directional based proxy, however it is not working and I am seeking some assistance as I am missing what I am doing wrong.

So here is how the Proxy code is generally supposed to work. Get Monster facing direction and if they are facing Left then subtract a userScreenByte variable so the center point is now to the left of the monster. When it checks the distance it is checking both positive and negative of the center point, so your variable is doubled. In my example below I have the distance set to 16 pixels, so that is really checking 16 pixels in each direction, so a total of 32 pixels. My offset is set at 16, so it will ultimately be checking 32 pixels to the left of the monsters actual center point as demonstrated in the image below (I think I may be wrong on this point).

Currently the it doesn't trigger, as the monster is supposed to changeActionStep to an attack.

Example Direction Areas:
X Proxy Distance = 16 - userScreenByte6
Y Proxy Distance = 16 - userScreenByte7
X Center Offset = 16 - userScreenByte4
Y Center Offset = 16 - userScreenByte5
Red = Facing Left
Yellow = Facing Up
Orange = Facing Right
Magenta = Facing Down

TheBoxAIProxyChart.png

;;This only works if player is Left of or Above Monster?
;;How can it work for Right of or Below Monster?

;;Consolidate?
;;Move to new bank?
; ;;;; enemy punch
;SwitchBank #$18
;JSR doEnemyProxy
;ReturnBank

;;Load Player X and Y
TXA
STA temp
PHA
LDX player1_object

;;Load and Save X with offset to center of player, and Y
LDA Object_x_hi,x
ADC #$08 ;;this moves the X to the player center
STA tempA
LDA Object_y_hi,x
STA tempB

LDA Object_screen,x
STA temp1

;;Load Monster direction
PLA
TAX
LDX temp

;LDA temp1
;CMP Object_screen,x
;BEQ +skip

;;Check if Left Right
;;#% 7 6 5 4 3 2 1 0
;; 0 = down, counterclockwise, 7=down-left
LDA Object_direction,x
CMP #%01000000
BEQ +saveLeft
CMP #%00000100
BEQ +saveRight

LDA Object_x_hi,x
ADC #$08 ;;adds 8 pixels so it is centered on monster.
STA tempC
JMP +doYCheck

;;save as tempC for X Proxy Direction Offset
;;userScreenByte6 distance to move monster X view area
+saveLeft
LDA Object_x_hi,x
SBC userScreenByte6
STA tempC
JMP +checkXProxyL

+saveRight
LDA Object_x_hi,x
ADC userScreenByte6
STA tempC
JMP +checkXProxyR

;;Compare X Positions
;;userScreenByte4 is X distance to check
+checkXProxyL
LDA tempC ;;load monster X pos tempC minus tempA. This is checks if Player is Left of monster. If more then userScreenByte4 jump to +checkYProxy, if less than do check right side.
SBC tempA ;;minus to player X pos
CMP userScreenByte4
BCC +doAttack ;;if it is less then userScreenByte4 jump to +doAttack
JMP +doYCheck

+checkXProxyR
LDA tempA ;;load Player X pos tempA minus tempC. This would be for if the player is Right of the Monster.
SBC tempC ;;minus to Monster X pos
BCC +doAttack
JMP +doYCheck ;;if X isn't triggered checkYPosition

;;Check if Up Down
+doYCheck
LDA Object_direction,x
CMP #%00010000
BEQ +saveUp
CMP #%10000000
BEQ +saveDown
JMP +skip

;;userScreenByte7 distance to move monster Y view area
+saveUp
LDA Object_y_hi,x
SBC userScreenByte7
STA tempD
JMP +checkYProxyU

+saveDown
LDA Object_y_hi,x
ADC userScreenByte7
STA tempD
JMP +checkYProxyD

;;Compare Y Positions
;;userScreenByte5 is Y distance to check
+checkYProxyU
LDA tempD ;;load monster Y pos
SBC tempB ;;Minus player Y pos
CMP userScreenByte5 ;;compare to player Y pos
BCC +doAttack ;;if it is less then
JMP +skip

+checkYProxyD
LDA tempB ;;load player Y pos
SBC tempD ;;Minus monster Y pos
CMP userScreenByte5 ;;compare to player Y pos
BCC +doAttack
JMP +skip

+doAttack
ChangeActionStep temp, #$05

+skip

;;Check Vulnerability
;;LDA Object_vulnerability,x
;;AND #%00100000
;;BEQ +skip

For my Monster Settings, this script is set on Repeat on a timer of 1.

Again, not sure why this doesn't trigger. I still need to add a check for Object_vulnerability, but once I get this all figured out I will make a new post in Community Tutorials.
Thanks!

edit: I rewrote some of the code because I know I incorrectly was looking for left and right at the same time, but had to add more code, which I will try to move to another bank in the future. I will stew on it some more and try and consolidate, but would love suggestions.
 
Last edited:
  • Like
Reactions: Yan

Craigery

Active member
I tried again. Here is a new version, but it triggers every time. This version is suppsoed to determine facing direction, then check X proxy in that in that direction, but I still not grasping this.
;;Load Player X and Y
TXA
STA temp
PHA
LDX player1_object

;;Load and Save X with offset to center of player, and Y
LDA Object_x_hi,x
ADC #$08 ;;this moves the X to the player center
STA tempA
LDA Object_y_hi,x
STA tempB

LDA Object_screen,x
STA temp1

;;Load Monster direction
PLA
TAX
LDX temp

LDA temp1
CMP Object_screen,x
BEQ +skip

;;Check if Left Right Up Down
;;#% 7 6 5 4 3 2 1 0
;; 0 = down, counterclockwise, 7=down-left
+checkXPositions
LDA Object_direction,x
CMP #FACE_LEFT
BEQ +saveLeft
CMP #FACE_RIGHT
BEQ +saveRight

+checkYPositions
LDA Object_direction,x
CMP #FACE_UP
BEQ +saveUp
CMP #FACE_DOWN
BEQ +saveDown
JMP +skip


;LDA Object_x_hi,x
;ADC #$08 ;;adds 8 pixels so it is centered on monster.
;STA tempC
;JMP +doYCheck

;;save as tempC for X Proxy Direction Offset
;;userScreenByte6 distance to move monster X view area
+saveLeft
LDA Object_x_hi,x
SBC tempA ;;load monster X pos tempC minus tempA. This is checks if Player is Left of monster. If more then userScreenByte4 jump to +checkYProxy, if less than do check right side.
SBC userScreenByte6 ;;minus to player X pos
CMP userScreenByte4
BCC +doAttack ;;if it is less then userScreenByte4 jump to +doAttack

LDA Object_y_hi,x
ADC #$10
BCC +doAttack
SBC #$20
BCC +doAttack
JMP +skip


+saveRight
LDA Object_x_hi,x
ADC tempA ;;load monster X pos tempC minus tempA. This is checks if Player is Left of monster. If more then userScreenByte4 jump to +checkYProxy, if less than do check right side.
ADC userScreenByte6 ;;minus to player X pos
CMP userScreenByte4
BCC +doAttack ;;if it is less then userScreenByte4 jump to +doAttack

LDA Object_y_hi,x
ADC #$10
BCC +doAttack
SBC #$20
BCS +doAttack
+skip

;;Compare Y Positions
;;userScreenByte5 is Y distance to check
+saveUp
LDA Object_y_hi,x
SBC tempB ;;load monster X pos tempC minus tempA. This is checks if Player is Left of monster. If more then userScreenByte4 jump to +checkYProxy, if less than do check right side.
SBC userScreenByte6 ;;minus to player X pos
CMP userScreenByte4
BCC +doAttack ;;if it is less then userScreenByte4 jump to +doAttack

LDA Object_x_hi,x
ADC #$10
BCC +doAttack
SBC #$20
BCS +doAttack
JMP +skip

+saveDown
LDA Object_y_hi,x
ADC tempB ;;load monster X pos tempC minus tempA. This is checks if Player is Left of monster. If more then userScreenByte4 jump to +checkYProxy, if less than do check right side.
ADC userScreenByte6 ;;minus to player X pos
CMP userScreenByte4
BCC +doAttack ;;if it is less then userScreenByte4 jump to +doAttack

LDA Object_x_hi,x
ADC #$10
BCC +doAttack
SBC #$20
BCS +doAttack
JMP +skip


+doAttack
ChangeActionStep temp, #$05

+skip
 
Top Bottom