Prev: 49137 Up: Map Next: 49239
49196: 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 49196 LD E,(IX+1) Fetch the X position of the object.
49199 LD D,(IX+2)
49202 LD HL,(48271) Fetch the X position of the player.
49205 AND A Work out how far the player is to the right of the object.
49206 SBC HL,DE
49208 LD A,2 Use a velocity of 2 to move towards the player...
49210 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 49212 NEG Reverse the velocity, to move left.
SetVelocityTowardsPlayer_SetX 49214 LD (IX+10),A Set the velocity of the object along the X axis.
49217 LD E,(IX+3) Fetch the Y position of the object.
49220 LD D,(IX+4)
49223 LD HL,(48273) Fetch the Y position of the player.
49226 AND A Work out how far the player is above the object.
49227 SBC HL,DE
49229 LD A,2 Use a velocity of 2 to move towards the player...
49231 JR NC,SetVelocityTowardsPlayer_SetY ... unless the player is below the object, which needs the opposite velocity.
The player is below the object.
SetVelocityTowardsPlayer_Down 49233 NEG Reverse the velocity, to move down the screen.
SetVelocityTowardsPlayer_SetY 49235 LD (IX+11),A Set the velocity of the object along the Y axis.
49238 RET Return.
Prev: 49137 Up: Map Next: 49239