Prev: 41356 Up: Map Next: 41471
41387: Handler: Amulet Piece
Handles the four amulet pieces (sprite IDs 144 to 147), which are placed in the rooms by PlaceAmuletPieces. The piece flashes when it is in the room the player is in and when the player touches it, it is collected.
Collecting a piece sets the bit in 38669 that corresponds to the piece, sets bit 7 of the same byte so that the amulet is shown by TestPlayerProgress, and awards 7500 points.
Input
IX Actor record of the amulet piece
Do nothing unless the piece is in the same room as the player.
HandlerAmuletPiece 41387 LD A,(38659) Fetch the room of the player from 38659.
41390 CP (IX+1) Compare with the room of the amulet piece.
41393 RET NZ Return if the amulet piece is in a different room to the player.
41394 LD BC,3084 Set how far above and to the right of the amulet piece the player can be in BC to 3084 (see TestPlayerTouchingActor).
Every other frame, cycle the piece through the colours 68 to 71.
41397 LD A,(38547) Fetch the low byte of the game timer from GameTimer.
41400 AND %00000001 Keep only bit 0.
41402 JR NZ,AmuletPiece_TestTouch Jump to AmuletPiece_TestTouch if bit 0 is set (the colour only changes on alternate passes).
41404 LD A,(IX+5) Fetch the colour of the amulet piece.
41407 INC A Move on to the next colour.
41408 AND %00000011 Keep only bits 0-1.
41410 OR %01000100 Set bits 2 and 6, giving a bright ink colour of 4-7.
41412 LD (IX+5),A Set the new colour of the amulet piece.
Test whether the player is touching the piece.
AmuletPiece_TestTouch 41415 CALL TestPlayerTouchingActor Test whether the player is touching the amulet piece.
41418 JP NC,ColourPickup Jump to ColourPickup to draw the amulet piece if the player is not touching it.
The piece has been collected, so work out which bit to set.
41421 LD A,(38669) Fetch the amulet pieces collected from 38669.
41424 OR %10000000 Set bit 7 (the "show the amulet" flag).
41426 LD C,A Stash the new amulet pieces collected in C.
41427 LD A,(IX+0) Fetch the sprite ID of the amulet piece.
41430 SUB 144 Subtract 144 to get the number of the amulet piece.
41432 JR Z,AmuletPiece_First Jump to AmuletPiece_First if this is the first amulet piece.
41434 DEC A Move on to the next piece number.
41435 JR Z,AmuletPiece_Second Jump to AmuletPiece_Second if this is the second amulet piece.
41437 DEC A Move on to the next piece number.
41438 JR Z,AmuletPiece_Third Jump to AmuletPiece_Third if this is the third amulet piece.
41440 SET 3,C Set bit 3 of the amulet pieces collected, as this is the fourth piece.
AmuletPiece_Collected 41442 LD A,C Fetch the new amulet pieces collected.
41443 LD (38669),A Store the amulet pieces collected in 38669.
41446 CALL DrawEntity Erase the amulet piece from the screen.
41449 LD (IX+0),0 Remove the amulet piece by setting its sprite ID to 0.
Add 7500 points to the player's score.
41453 LD BC,29952 Set the points to award in BC to 7500 (stored as BCD).
41456 JP AddPointsToScore Jump to AddPointsToScore to add the points to the score.
Set the bit for the first, second or third piece.
AmuletPiece_First 41459 SET 0,C Set bit 0 of the amulet pieces collected for the first piece.
41461 JR AmuletPiece_Collected Jump to AmuletPiece_Collected.
AmuletPiece_Second 41463 SET 1,C Set bit 1 of the amulet pieces collected for the second piece.
41465 JR AmuletPiece_Collected Jump to AmuletPiece_Collected.
AmuletPiece_Third 41467 SET 2,C Set bit 2 of the amulet pieces collected for the third piece.
41469 JR AmuletPiece_Collected Jump to AmuletPiece_Collected.
Prev: 41356 Up: Map Next: 41471