Prev: BFF1 Up: Map Next: C057
C02C: Set Velocity Towards Player
Used by the routine at UpdateGhost.
Makes the object at IX chase the player, by setting its velocity along each axis to two units towards the player.
Input
IX Object
SetVelocityTowardsPlayer C02C LD E,(IX+$01) Fetch the X position of the object.
C02F LD D,(IX+$02)
C032 LD HL,($BC8F) Fetch the X position of the player.
C035 AND A Work out how far the player is to the right of the object.
C036 SBC HL,DE
C038 LD A,$02 Use a velocity of 02 to move towards the player...
C03A JR NC,SetVelocityTowardsPlayer_SetX ... unless the player is on the left of the object, which needs the opposite velocity.
The player is to the left of the object.
SetVelocityTowardsPlayer_Left C03C NEG Reverse the velocity, to move left.
SetVelocityTowardsPlayer_SetX C03E LD (IX+$0A),A Set the velocity of the object along the X axis.
C041 LD E,(IX+$03) Fetch the Y position of the object.
C044 LD D,(IX+$04)
C047 LD HL,($BC91) Fetch the Y position of the player.
C04A AND A Work out how far the player is above the object.
C04B SBC HL,DE
C04D LD A,$02 Use a velocity of 02 to move towards the player...
C04F JR NC,SetVelocityTowardsPlayer_SetY ... unless the player is below the object, which needs the opposite velocity.
The player is below the object.
SetVelocityTowardsPlayer_Down C051 NEG Reverse the velocity, to move down the screen.
SetVelocityTowardsPlayer_SetY C053 LD (IX+$0B),A Set the velocity of the object along the Y axis.
C056 RET Return.
Prev: BFF1 Up: Map Next: C057