Prev: 8ED7 Up: Map Next: 8F66
8EEF: Move a heading towards a target, within limits
Used by the routine at MOVE_PLAYER.
Adds E and D to the pair at +$06 and +$07 and clamps the result to L and H, handling the negative side by negating, comparing and negating back. The two fields are a signed heading, so this is how a creature turns towards something gradually rather than snapping round to face it.
STEER 8EEF LD A,(IX+$02) Not every call: the low nibble of +$02 gates it.
8EF2 AND $0F
8EF4 JR NZ,STEER_6
8EF6 LD A,E Add the change to the horizontal part...
8EF7 ADD A,(IX+$06)
8EFA JP M,STEER_2 ...taking the negative side separately.
8EFD CP L Clamp to the limit in L.
8EFE JR C,STEER_0
8F00 LD A,L
STEER_0 8F01 LD (IX+$06),A Store it.
8F04 LD A,D And the vertical part the same way.
8F05 ADD A,(IX+$07)
8F08 JP M,STEER_4
8F0B CP H
8F0C JR C,STEER_1
8F0E LD A,H
STEER_1 8F0F LD (IX+$07),A
8F12 LD A,(IX+$06) Both parts through the same conversion on the way out.
8F15 CALL SCALE_SIGNED
8F18 LD E,A
8F19 LD A,(IX+$07)
8F1C CALL SCALE_SIGNED
8F1F LD D,A
8F20 RET
STEER_2 8F21 NEG
8F23 CP L
8F24 JR C,STEER_3
8F26 LD A,L
STEER_3 8F27 NEG
8F29 JR STEER_0
STEER_4 8F2B NEG
8F2D CP H
8F2E JR C,STEER_5
8F30 LD A,H
STEER_5 8F31 NEG
8F33 JR STEER_1
STEER_6 8F35 LD A,(IX+$06)
8F38 AND A
8F39 JP M,STEER_9
8F3C AND $F0
8F3E JR Z,STEER_7
8F40 LD A,$02
STEER_7 8F42 LD E,A
8F43 LD A,(IX+$07)
8F46 AND A
8F47 JP M,STEER_10
8F4A AND $F0
8F4C JR Z,STEER_8
8F4E LD A,$02
STEER_8 8F50 LD D,A
8F51 RET
STEER_9 8F52 NEG
8F54 AND $F0
8F56 JR Z,STEER_7
8F58 LD A,$FE
8F5A JR STEER_7
STEER_10 8F5C NEG
8F5E AND $F0
8F60 JR Z,STEER_8
8F62 LD A,$FE
8F64 JR STEER_8
Prev: 8ED7 Up: Map Next: 8F66