Prev: 87A6 Up: Map Next: 8862
882D: Steer Creature
Sets the velocities of a creature so that it heads towards a target position, which is one pixel per step on each axis (or nothing on an axis where it has already arrived). Bit 0 of C is set if the creature is at the Y position of the target and bit 1 is set if it is at the X position, so C is 03 when it has arrived.
Input
IX The creature entity
DE The target position (X in E and Y in D)
Output
C Bit 0 set if the Y positions match, bit 1 set if the X ones do
SteerCreature 882D LD C,$00 Clear the result in C, which flags which axes have been reached.
882F LD A,D Fetch the target Y position.
8830 CP (IX+$04) Compare the target Y position with the Y position of the creature.
8833 JR Z,SteerCreature_SameY Jump to SteerCreature_SameY if they are the same.
8835 JR NC,SteerCreature_Below
8837 LD (IX+$09),$FF Set the Y velocity of the creature to -01 (the target is above).
SteerCreature_X 883B LD A,E Fetch the target X position.
883C CP (IX+$03) Compare the target X position with the X position of the creature.
883F JR Z,SteerCreature_SameX Jump to SteerCreature_SameX if they are the same.
8841 JR NC,SteerCreature_Right
8843 LD (IX+$08),$FF Set the X velocity of the creature to -01 (the target is to the left).
8847 RET Return.
SteerCreature_SameY 8848 LD (IX+$09),$00 Set the Y velocity of the creature to 00.
884C SET 0,C Flag that the creature is at the target Y position.
884E JR SteerCreature_X Jump to SteerCreature_X to work out the X velocity.
SteerCreature_Below 8850 LD (IX+$09),$01 Set the Y velocity of the creature to 01.
8854 JR SteerCreature_X Jump to SteerCreature_X to work out the X velocity.
SteerCreature_SameX 8856 LD (IX+$08),$00 Set the X velocity of the creature to 00.
885A SET 1,C Flag that the creature is at the target X position.
885C RET Return.
SteerCreature_Right 885D LD (IX+$08),$01 Set the X velocity of the creature to 01.
8861 RET Return.
Prev: 87A6 Up: Map Next: 8862