Prev: 51858 Up: Map Next: 51955
51866: 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 0, 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 51866 POP HL Unstack the size of the room in X and Y.
Work out the coordinate of the west edge of the room.
51867 LD A,128 Set A to 128.
51869 SUB L Subtract L.
51870 LD L,A Copy it to L.
Add the speed in X and the width of the player to the X coordinate.
51871 LD A,(IX+1) Fetch the x position of the player.
51874 ADD A,(IX+9) Add the speed along the x axis.
51877 ADD A,(IX+4) Add the width of the player.
Compare it with the west edge.
51880 CP L Return if the player is still in the room.
51881 RET NC
51882 LD (IX+1),0 Write 0 to the x position.
Fetch the room number and stash it in L.
51886 LD A,(IX+8) Fetch the room number.
51889 LD L,A Copy it to L.
51890 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 51891 AND %00001111 Keep the column of the new room number.
51893 LD H,A Copy it to H.
51894 LD A,L Fetch the old room number.
51895 AND %11110000 Keep only bits 4-7.
51897 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 3. If the object is the player then it is copied and replaced by sparkles, and the game loop is started again.
ChangeRoom 51898 LD (IX+8),A Store the new room number.
51901 LD A,(IX+12) Fetch the collision flags.
51904 OR %00110000 Set the counter of the player entering the room to 3.
51906 LD (IX+12),A Store the collision flags.
Fetch the graphic number and take 16 off it.
51909 LD A,(IX+0) Fetch the graphic number of the object.
51912 SUB 16 Subtract 16.
51914 CP 64 Compare it with 64.
51916 RET NC Return if it is not one of the graphics of the human or the wulf.
51917 INC SP Drop the two return addresses on the stack, as the game loop starts again.
51918 INC SP
51919 INC SP
51920 INC SP
51921 PUSH IX Point HL at the player (using the stack).
51923 POP HL
51924 LD DE,53601 Point DE at PlayerCopy.
51927 LD BC,64 Set the length to 64, for the two halves of the player.
51930 LDIR Copy the player.
Remember the sprites, then turn the copy into sparkles.
51932 LD A,(53601) Fetch the sprite of the bottom half.
51935 LD (53617),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.
51938 LD A,(53633) Fetch the sprite of the top half.
51941 LD (53649),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.
51944 LD A,120 Write 120 to PlayerCopy and PlayerCopy_TopHalf.
51946 LD (53601),A
51949 LD (53633),A
51952 JP RunGame Start the game loop again, which builds the new room.
View the equivalent code in;
Prev: 51858 Up: Map Next: 51955