Prev: 42043 Up: Map Next: 42131
42059: Calculate New Position
Works out where an actor will be after it has moved by its velocities (see IX+6 and IX+7), keeping it on the screen. The velocities are in sixteenths of a pixel.
The X position is kept between 0 and 0256 minus the width (held in Actor_Width) and the Y position between 39 and 191.
Input
IX Actor record
Output
B Bit 0 is set if the actor hit the left or right of the screen, bit 1 is set if it hit the top or bottom
D The new Y position
E The new X position
CalculateNewPosition 42059 LD B,0 Clear the edge flags in B.
42061 LD A,(38573) Fetch the width of the actor from Actor_Width.
42064 LD C,A Stash the width in C.
Work out the new X position.
42065 LD A,(IX+6) Fetch the X velocity of the actor.
42068 CALL GetWholePixels Convert the X velocity to pixels.
42071 JP M,CalculateNewPosition_Left Jump to CalculateNewPosition_Left if the actor is moving left.
42074 ADD A,(IX+3) Add the X position of the actor.
42077 LD E,A Stash the new X position in E.
42078 ADD A,C Add the width of the actor.
42079 JR C,CalculateNewPosition_HitRight Jump to CalculateNewPosition_HitRight if the actor would go off the right edge of the screen.
Work out the new Y position.
CalculateNewPosition_Y 42081 LD A,(IX+7) Fetch the Y velocity of the actor.
42084 CALL GetWholePixels Convert the Y velocity to pixels.
42087 JP M,CalculateNewPosition_Up Jump to CalculateNewPosition_Up if the actor is moving up.
42090 ADD A,(IX+4) Add the Y position of the actor.
42093 LD D,A Stash the new Y position in D.
42094 CP 191 Return if the actor is not off the bottom of the screen (191).
42096 RET C
42097 LD D,191 Limit the Y position to the bottom of the screen (191).
CalculateNewPosition_HitY 42099 SET 1,B Set the top or bottom edge flag (bit 1).
42101 RET Return.
The actor hit the right of the screen.
CalculateNewPosition_HitRight 42102 LD A,C Fetch the width of the actor.
42103 NEG Negate it to give the X position which puts the actor against the right of the screen.
42105 LD E,A Stash it in E as the new X position.
42106 SET 0,B Set the left or right edge flag (bit 0).
42108 RET Return.
The actor is moving left.
CalculateNewPosition_Left 42109 ADD A,(IX+3) Add the X position of the actor.
42112 LD E,A Stash the new X position in E.
42113 JR C,CalculateNewPosition_Y Jump to CalculateNewPosition_Y if the actor is still on the screen.
42115 LD E,0 Limit the X position to the left edge of the screen (0).
42117 SET 0,B Set the left or right edge flag (bit 0).
42119 RET Return.
The actor is moving up.
CalculateNewPosition_Up 42120 ADD A,(IX+4) Add the Y position of the actor.
42123 LD D,A Stash the new Y position in D.
42124 CP 39 Return if the actor is not off the top of the screen (the Y position is 39 or more).
42126 RET NC
42127 LD D,39 Limit the Y position to the top of the screen (39).
42129 JR CalculateNewPosition_HitY Jump to CalculateNewPosition_HitY to set the top or bottom edge flag.
Prev: 42043 Up: Map Next: 42131