Prev: FC48 Up: Map Next: FC9C
FC66: Work out which way a chaser should go to reach its target
Used by the routine at ZOOMIN.
The heading is along one floor axis only, whichever the target is further off along: x (+6) or z (+8), measured to a point two units past the target's corner, and z when they are equal. The chaser's timer (+15) is set to 10 passes before it looks again, or to 3 when the z distance is under 14 -- the z distance whichever axis won, as the code has it.
Input
IX The chaser's record
IY The target's record
Output
A The heading: 8 for +x, 4 for -x, $40 for +z, $80 for -z
D How far off the target is along that axis
AIM_AT FC66 LD A,(IY+OBJ_X) Look again in 10 passes
FC69 ADD A,$02
FC6B LD (IX+OBJ_COUNT),$0A
FC6F PUSH HL Keep HL
FC70 SUB (IX+OBJ_X) Along x: H = +x (8) or -x (4), D = how far
FC73 LD H,$08
FC75 JR NC,AIM_AT_0
FC77 NEG
FC79 LD H,$04
AIM_AT_0 FC7B LD D,A
FC7C LD A,(IY+OBJ_Z) Along z: L = +z ($40) or -z ($80)
FC7F ADD A,$02
FC81 SUB (IX+OBJ_Z)
FC84 LD L,$40
FC86 JR NC,AIM_AT_1
FC88 NEG
FC8A LD L,$80
AIM_AT_1 FC8C CP D As far or further along z: head that way
FC8D JR C,AIM_AT_2
FC8F LD D,A
FC90 LD H,L
AIM_AT_2 FC91 CP $0E Near along z: look again in 3 passes
FC93 JR NC,AIM_AT_3
FC95 LD (IX+OBJ_COUNT),$03
AIM_AT_3 FC99 LD A,H A = the heading
FC9A POP HL
FC9B RET
Prev: FC48 Up: Map Next: FC9C