Prev: CA92 Up: Map Next: CAF3
CA9A: Leave Room To The West
Sends the player to the room to the west if it has gone past the west edge of the room. The x position is set to 00, which PlacePlayerAtDoor takes as the sign that the player has come out of the west and puts it at the east side of the new room.
Input
HL Distances to the walls along x and y
IX The address of the object
Leave if past the west edge.
LeaveRoomToWest CA9A POP HL Unstack the size of the room in X and Y.
Work out the coordinate of the west edge of the room.
CA9B LD A,$80 Set A to 80.
CA9D SUB L Subtract L.
CA9E LD L,A Copy it to L.
Add the speed in X and the width of the player to the X coordinate.
CA9F LD A,(IX+$01) Fetch the x position of the player.
CAA2 ADD A,(IX+$09) Add the speed along the x axis.
CAA5 ADD A,(IX+$04) Add the width of the player.
Compare it with the west edge.
CAA8 CP L Return if the player is still in the room.
CAA9 RET NC
CAAA LD (IX+$01),$00 Write 00 to the x position.
Fetch the room number and stash it in L.
CAAE LD A,(IX+$08) Fetch the room number.
CAB1 LD L,A Copy it to L.
CAB2 DEC A Go to the room to the west.
This entry point is used by the routine at LeaveRoomToEast.
Change the column. The room number has the row in the high nibble and the column in the low nibble.
ChangeRoomEastWest CAB3 AND %00001111 Keep the column of the new room number.
CAB5 LD H,A Copy it to H.
CAB6 LD A,L Fetch the old room number.
CAB7 AND %11110000 Keep only bits 4-7.
CAB9 OR H Combine the row with the new column.
This entry point is used by the routines at LeaveRoomToNorth and LeaveRoomToSouth.
Change the room of the player. Bits 4 and 5 of the collision flags start the entering-room counter at 03. If the object is the player then it is copied and replaced by sparkles, and the game loop is started again.
ChangeRoom CABA LD (IX+$08),A Store the new room number.
CABD LD A,(IX+$0C) Fetch the collision flags.
CAC0 OR %00110000 Set the counter of the player entering the room to 03.
CAC2 LD (IX+$0C),A Store the collision flags.
Fetch the graphic number and take 10 off it.
CAC5 LD A,(IX+$00) Fetch the graphic number of the object.
CAC8 SUB $10 Subtract 10.
CACA CP $40 Compare it with 40.
CACC RET NC Return if it is not one of the graphics of the human or the wulf.
CACD INC SP Drop the two return addresses on the stack, as the game loop starts again.
CACE INC SP
CACF INC SP
CAD0 INC SP
CAD1 PUSH IX Point HL at the player (using the stack).
CAD3 POP HL
CAD4 LD DE,$D161 Point DE at PlayerCopy.
CAD7 LD BC,$0040 Set the length to 40, for the two halves of the player.
CADA LDIR Copy the player.
Remember the sprites, then turn the copy into sparkles.
CADC LD A,($D161) Fetch the sprite of the bottom half.
CADF LD ($D171),A Keep it as the sprite that the bottom half will appear as.
Copy the graphic number of the top half into the same field of the top half from PlayerCopy_TopHalf.
CAE2 LD A,($D181) Fetch the sprite of the top half.
CAE5 LD ($D191),A Keep it as the sprite that the top half will appear as.
Fetch the graphic number of the first of the sparkles that show the player appearing.
CAE8 LD A,$78 Write 78 to PlayerCopy and PlayerCopy_TopHalf.
CAEA LD ($D161),A
CAED LD ($D181),A
CAF0 JP RunGame Start the game loop again, which builds the new room.
View the equivalent code in;
Prev: CA92 Up: Map Next: CAF3