| ← C8C2 | Map | C977 → |
C91C: Steer an object toward a target object
|
Sets the heading of the object that steers, in its logic record, to one of eight headings. That heading points from its sprite position toward a target object's sprite position.
|
|||||||||||
|
|||||||||||
|
Both objects' positions are read from their sprite records. X increases rightward and Y increases downward. The heading is the direction of the vector from the steerer to the target. The headings run clockwise: 0 for up, 2 for right, 4 for down and 6 for left, with the diagonals between them. Equal X yields 0 (target level or above) or 4 (target below). Equal Y yields 2 (target right) or 6 (target left).
|
|||||||||||
| head_toward_target | C91C | PUSH IY | Save the steerer's records and the target id across the slot lookup. | ||||||||
| C91E | PUSH BC | ||||||||||
| C91F | PUSH IX | ||||||||||
| C921 | LD A,B | Point IY at target slot B's sprite record. IX stays on the steerer's own sprite record. | |||||||||
| C922 | CALL object_slot_ptr | ||||||||||
| C925 | PUSH IX | ||||||||||
| C927 | POP IY | ||||||||||
| C929 | POP IX | ||||||||||
| C92B | POP BC | ||||||||||
| C92C | LD A,(IX+$00) | Pick the heading from where the target lies. This three-way split compares X, and each branch compares Y. | |||||||||
| C92F | CP (IY+$00) | ||||||||||
| C932 | JR Z,heading_same_column | ||||||||||
| C934 | JR C,heading_target_right | ||||||||||
| C936 | JR heading_target_left | ||||||||||
| heading_same_column | C938 | LD A,(IX+$01) | Same column (X equal), target below: head down. | ||||||||
| C93B | CP (IY+$01) | ||||||||||
| C93E | JR NC,heading_straight_up | ||||||||||
| C940 | LD A,$04 | ||||||||||
| C942 | JR store_heading | ||||||||||
| heading_straight_up | C944 | XOR A | Target level or above: heading up. | ||||||||
| C945 | JR store_heading | ||||||||||
| heading_target_left | C947 | LD A,(IX+$01) | Target to the left and below: 5 (down-left). | ||||||||
| C94A | CP (IY+$01) | ||||||||||
| C94D | JR Z,heading_left | ||||||||||
| C94F | JR NC,heading_up_left | ||||||||||
| C951 | LD A,$05 | ||||||||||
| C953 | JR store_heading | ||||||||||
| heading_left | C955 | LD A,$06 | Level with the target: due left. | ||||||||
| C957 | JR store_heading | ||||||||||
| heading_up_left | C959 | LD A,$07 | Target above: up-left | ||||||||
| C95B | JR store_heading | ||||||||||
| heading_target_right | C95D | LD A,(IX+$01) | Target to the right and below: 3 (down-right). | ||||||||
| C960 | CP (IY+$01) | ||||||||||
| C963 | JR Z,heading_right | ||||||||||
| C965 | JR NC,heading_up_right | ||||||||||
| C967 | LD A,$03 | ||||||||||
| C969 | JR store_heading | ||||||||||
| heading_right | C96B | LD A,$02 | Level with the target: due right. | ||||||||
| C96D | JR store_heading | ||||||||||
| heading_up_right | C96F | LD A,$01 | Target above: up-right | ||||||||
| store_heading | C971 | POP IY | Store the chosen heading as the steerer's new heading. | ||||||||
| C973 | LD (IY+$00),A | ||||||||||
| C976 | RET | ||||||||||
| ← C8C2 | Map | C977 → |
