Prev: CA7C Up: Map Next: CAEE
CA82: Place Player At Door
Used by the routine at BuildRoom.
Moves the player to the doorway on the opposite side of a room to the one that it left the last room by. When the player goes through a door, TestDoorPassage sets the x or y position of the player to 00 or FF to show which wall it went through. In the new room, the player is put in front of the door in the opposite wall, in the doorway, with the edge of the player nearest the centre of the room two units inside the wall. Nothing is done when the player is not at one of the edges, which is how a game starts.
Input
IX Address of the player
Fetch the wall distances, then see which way the player came.
PlacePlayerAtDoor CA82 LD A,($A71D) Fetch RoomSizeX.
CA85 SUB $02 Subtract 02.
CA87 LD L,A Copy it to L.
Fetch the distance to the walls along y and take off two.
CA88 LD A,($A71E) Fetch RoomSizeY.
CA8B SUB $02 Subtract 02.
CA8D LD H,A Copy it to H.
CA8E LD A,(IX+$01) Fetch the x position of the player.
CA91 AND A Jump to PlacePlayerAtDoor_EndOfX if the player went through the wall at the start of x.
CA92 JR Z,PlacePlayerAtDoor_EndOfX
CA94 INC A Jump to PlacePlayerAtDoor_StartOfX if it went through the wall at the end of x, which is FF.
CA95 JR Z,PlacePlayerAtDoor_StartOfX
CA97 LD A,(IX+$02) Fetch the y position of the player.
CA9A AND A Jump to PlacePlayerAtDoor_EndOfY if the player went through the wall at the start of y.
CA9B JR Z,PlacePlayerAtDoor_EndOfY
CA9D INC A Jump to PlacePlayerAtDoor_StartOfY if it went through the wall at the end of y, which is FF.
CA9E JR Z,PlacePlayerAtDoor_StartOfY
CAA0 RET Return.
The player came from the north.
PlacePlayerAtDoor_StartOfY CAA1 LD C,$03 Set the wall to look for a door in, which is at the start of y.
CAA3 CALL FindDoor Call FindDoor to find the door and put the player in front of it.
CAA6 LD A,$80 Set the position of the wall at the start of y, which is the centre of the room.
CAA8 SUB H Subtract the distance to the walls less two...
CAA9 SUB (IX+$05) ...and the half size of the player along y, which puts the edge of the player nearest the centre of the room two units inside the wall.
PlacePlayerAtDoor_SetPlayerY CAAC LD (IX+$02),A Store it as the y position of the player.
Mark the player to be drawn.
PlacePlayerAtDoor_MarkPlayerForDrawing CAAF SET 4,(IX+$07) Set bit 4 of the flags.
CAB3 SET 4,(IX+$27) Set bit 4 of the flags of the top half.
Copy the x position of the player to the body.
CAB7 LD A,(IX+$01) Fetch the x position of the player.
CABA LD (IX+$21),A Set the x position of the top half.
Copy the y position of the player to the body.
CABD LD A,(IX+$02) Fetch the y position of the player.
CAC0 LD (IX+$22),A Set the y position of the top half.
CAC3 RET Return.
The player came from the south.
PlacePlayerAtDoor_EndOfY CAC4 LD C,$02 Set the wall to look for a door in, which is at the end of y.
CAC6 CALL FindDoor Call FindDoor to find the door and put the player in front of it.
CAC9 LD A,H Fetch the distance to the walls less two.
CACA ADD A,$80 Add the position of the centre of the room...
CACC ADD A,(IX+$05) ...and the half size of the player along y.
CACF JR PlacePlayerAtDoor_SetPlayerY Jump to PlacePlayerAtDoor_SetPlayerY to store it.
The player came from the east.
PlacePlayerAtDoor_StartOfX CAD1 LD C,$01 Set the wall to look for a door in, which is at the start of x.
CAD3 CALL FindDoor Call FindDoor to find the door and put the player in front of it.
CAD6 LD A,$80 Set the position of the wall at the start of x, which is the centre of the room.
CAD8 SUB L Subtract the distance to the walls less two...
CAD9 SUB (IX+$04) ...and the half size of the player along x, which puts the edge of the player nearest the centre of the room two units inside the wall.
PlacePlayerAtDoor_SetPlayerX CADC LD (IX+$01),A Store it as the x position of the player.
CADF JR PlacePlayerAtDoor_MarkPlayerForDrawing Jump to PlacePlayerAtDoor_MarkPlayerForDrawing to finish.
The player came from the west.
PlacePlayerAtDoor_EndOfX CAE1 LD C,$00 Set the wall to look for a door in, which is at the end of x.
CAE3 CALL FindDoor Call FindDoor to find the door and put the player in front of it.
CAE6 LD A,L Fetch the distance to the walls less two.
CAE7 ADD A,$80 Add the position of the centre of the room...
CAE9 ADD A,(IX+$04) ...and the half size of the player along x.
CAEC JR PlacePlayerAtDoor_SetPlayerX Jump to PlacePlayerAtDoor_SetPlayerX to store it.
View the equivalent code in;
Prev: CA7C Up: Map Next: CAEE