Prev: 45127 Up: Map Next: 45176
45139: Update Player Direction
Used by the routine at GamePlay_Start.
Sets the direction the player faces to match the way the player has moved. Bits 2-3 of the sprite ID hold the direction: 0 is left, 4 is right, 8 is up and 12 is down. The vertical movement is tested first, so if the player has moved both horizontally and vertically then the horizontal direction is used. The walking animation is also advanced (see AnimateWalk).
Input
D New Y position
E New X position
IX Actor record of the player
UpdatePlayerDirection 45139 CALL AnimateWalk Animate the walking player.
45142 LD A,D Fetch the new Y position.
45143 CP (IX+4) Jump to UpdatePlayerDirection_Horizontal if the player has not moved up or down.
45146 JR Z,UpdatePlayerDirection_Horizontal
45148 LD A,(IX+0) Fetch the sprite ID of the player.
45151 JR C,FaceUp Jump to FaceUp if the player has moved up.
45153 OR %00001100 Set bits 2-3, so the player faces down.
This entry point is used by the routine at FaceUp.
UpdatePlayerDirection_Store 45155 LD (IX+0),A Set the new sprite ID of the player.
UpdatePlayerDirection_Horizontal 45158 LD A,E Fetch the new X position.
45159 CP (IX+3) Return if the player has not moved left or right.
45162 RET Z
45163 LD A,(IX+0) Fetch the sprite ID of the player.
45166 JR C,FaceLeft Jump to FaceLeft if the player has moved left.
45168 AND %11110011 Keep only bits 0-1, 4-7.
45170 OR %00000100 Set bit 2, so the player faces right.
This entry point is used by the routine at FaceLeft.
UpdatePlayerDirection_Write 45172 LD (IX+0),A Set the new sprite ID of the player.
45175 RET Return.
Prev: 45127 Up: Map Next: 45176