Prev: 89FC Up: Map Next: 8A5C
8A00: Move an ant towards the player
Used by the routine at ANT_TURN.
The ant is taken out of the map, moved, and put back. If the move brought it closer to the player it walks on (and, within three cells, turns to face the player); otherwise it stops and turns a random way.
MOVE_ANT 8A00 LD D,(IX+$01) Out of the map...
8A03 LD E,(IX+$00)
8A06 PUSH DE
8A07 LD A,(IX+$02)
8A0A CALL TOGGLE_MAP_BIT
8A0D CALL MOVE_OR_RESPAWN Move it.
8A10 LD H,(IX+$01) ...and back in where it is now.
8A13 LD L,(IX+$00)
8A16 LD D,H
8A17 LD E,L
8A18 LD A,(IX+$02)
8A1B CALL TOGGLE_MAP_BIT
8A1E LD D,(IY+$01) Its distance from the player, now and before.
8A21 LD E,(IY+$00)
8A24 CALL DISTANCE
8A27 LD C,A
8A28 POP HL
8A29 CALL DISTANCE
8A2C LD B,A
8A2D LD A,C
8A2E CP B
8A2F JR NC,MOVE_ANT_0
8A31 LD A,(IX+$08) Closer: walk.
8A34 INC A
8A35 AND $01
8A37 LD (IX+$08),A
8A3A LD A,C Within three cells (under four): face the player.
8A3B CP $04
8A3D RET NC
8A3E LD H,(IX+$01)
8A41 LD L,(IX+$00)
8A44 CALL DIRECTION_TO
8A47 LD (IX+$04),A
8A4A RET
MOVE_ANT_0 8A4B LD (IX+$08),$00 No closer: stop, and turn left or right at random.
8A4F CALL RANDOM
8A52 JR C,MOVE_ANT_1
8A54 INC (IX+$04)
8A57 RET
MOVE_ANT_1 8A58 DEC (IX+$04)
8A5B RET
Prev: 89FC Up: Map Next: 8A5C