Prev: 882D Up: Map Next: 8906
8862: Handle Mummy
The handler for the mummy (sprite IDs 70 to 73). If the mummy touches the player then TakeEnergyFromPlayer_Small takes some energy. Then the mummy picks a target to steer towards with SteerCreature. If the leaf (ItemEntity_Leaf, the copy of Initialisation_Leaf) is in the room then it is the target, and when the mummy reaches it the leaf is moved to room 6B. Otherwise, when bit 7 of offset 06 is reset and the red key (ItemEntity_Red_Key, the copy of Initialisation_Key_Red) is in the room, the mummy goes backwards and forwards between two waypoints that are kept at offsets 0B and 0C and when bit 7 is set (or the red key is not in the room) the target is the player. The sprite comes from the bottom two bits of the counter at CounterLow, and then HandlerBoss_Move does the rest.
Input
IX The mummy entity
HandlerMummy 8862 CALL StoreEntity Call StoreEntity to save the position of the mummy.
8865 CALL CheckPlayerTouch Call CheckPlayerTouch to check whether the entity is touching the player.
8868 DEC E Call TakeEnergyFromPlayer_Small if the mummy touched the player.
8869 CALL Z,TakeEnergyFromPlayer_Small
See if the leaf (ItemEntity_Leaf) is in the room, and if so make it the target.
886C LD HL,$EAE0 Point HL at the leaf at ItemEntity_Leaf.
886F LD A,(HL) Fetch the sprite ID of the entity.
8870 AND A Jump to HandlerMummy_CheckFlags if the leaf is not in use.
8871 JR Z,HandlerMummy_CheckFlags
8873 INC HL Move HL on to the room of the entity.
8874 LD A,(HL) Fetch the room of the entity.
8875 CP (IX+$01) Jump to HandlerMummy_CheckFlags if the leaf is in a different room to the mummy.
8878 JR NZ,HandlerMummy_CheckFlags
887A INC HL Move HL on to the X position of the entity.
887B INC HL
887C LD E,(HL) Fetch the X position of the entity.
887D INC HL Move HL on to the Y position of the entity.
887E LD D,(HL) Fetch the Y position of the entity.
887F JR HandlerMummy_Target Jump to HandlerMummy_Target to steer the mummy towards its target.
If bit 7 of the flags is set then the target is the player.
HandlerMummy_CheckFlags 8881 BIT 7,(IX+$06) Jump to HandlerMummy_Player if bit 7 of offset 06 is set.
8885 JR NZ,HandlerMummy_Player
See if the red key (ItemEntity_Red_Key) is in the room.
8887 LD HL,$EAC8 Point HL at the red key at ItemEntity_Red_Key.
888A LD A,(HL) Fetch the sprite ID of the entity.
888B AND A Jump to HandlerMummy_SeekPlayer if the red key is not in use.
888C JR Z,HandlerMummy_SeekPlayer
888E INC HL Move HL on to the room of the entity.
888F LD A,(HL) Fetch the room of the entity.
8890 CP (IX+$01) Jump to HandlerMummy_SeekPlayer if the red key is in a different room to the mummy.
8893 JR NZ,HandlerMummy_SeekPlayer
Steer towards the current waypoint.
8895 LD D,(IX+$0C) Fetch the Y position of the waypoint.
8898 LD E,(IX+$0B) Fetch the X position of the waypoint.
889B CALL SteerCreature Call SteerCreature to steer the creature towards its target.
889E LD A,C Fetch which of the axes have been reached.
889F CP $03 Jump to HandlerMummy_NextWaypoint if the mummy is at the waypoint.
88A1 JR Z,HandlerMummy_NextWaypoint
Choose the sprite and the area that the mummy can move in.
HandlerMummy_SetSprite 88A3 LD A,($5E12) Fetch the counter from CounterLow.
88A6 RRA Divide the counter by four.
88A7 RRA
88A8 AND %00000011 Keep only bits 0-1.
88AA ADD A,$70 Add 70 to get the sprite ID of the mummy.
88AC LD (IX+$00),A Update the sprite ID of the mummy.
88AF LD DE,$3838 DE=3838 (the area).
88B2 JP HandlerBoss_Move Jump to HandlerBoss_Move to move the boss.
The mummy is at a waypoint, so change to the other one.
HandlerMummy_NextWaypoint 88B5 BIT 6,(IX+$06) Jump to HandlerMummy_FirstWaypoint if bit 6 of offset 06 is reset.
88B9 JR Z,HandlerMummy_FirstWaypoint
88BB LD (IX+$0B),$8C Set the X position of the waypoint to 8C.
88BF LD (IX+$0C),$68 Set the Y position of the waypoint to 68.
88C3 RES 6,(IX+$06) Reset bit 6 of offset 06.
88C7 JR HandlerMummy_SetSprite Jump to HandlerMummy_SetSprite to choose the sprite of the mummy.
HandlerMummy_FirstWaypoint 88C9 LD (IX+$0B),$68 Set the X position of the waypoint to 68.
88CD LD (IX+$0C),$38 Set the Y position of the waypoint to 38.
88D1 SET 6,(IX+$06) Set bit 6 of offset 06.
88D5 JR HandlerMummy_SetSprite Jump to HandlerMummy_SetSprite to choose the sprite of the mummy.
Steer towards the leaf, and when the mummy gets there move it out of the way.
HandlerMummy_Target 88D7 CALL SteerCreature Call SteerCreature to steer the creature towards its target.
88DA LD A,C Fetch which of the axes have been reached.
88DB CP $03 Jump to HandlerMummy_SetSprite if the mummy has not arrived.
88DD JR NZ,HandlerMummy_SetSprite
88DF PUSH IX Stash the mummy on the stack.
88E1 LD IX,$EAE0 Point IX at the leaf at ItemEntity_Leaf.
88E5 LD A,($EA91) Fetch the room of the player from PlayerRoom.
88E8 CP (IX+$01) Jump to HandlerMummy_Moved if the leaf is in a different room to the player.
88EB JR NZ,HandlerMummy_Moved
88ED CALL DrawEntity Call DrawEntity to draw the entity.
HandlerMummy_Moved 88F0 POP IX Restore the mummy from the stack.
88F2 LD A,$6B Write 6B to the room of the leaf, to move it out of the way.
88F4 LD ($EAE1),A
88F7 JR HandlerMummy_NextWaypoint Jump to HandlerMummy_NextWaypoint to change the mummy to its other waypoint.
There is nothing else to go for, so the target is the player.
HandlerMummy_SeekPlayer 88F9 SET 7,(IX+$06) Set bit 7 of offset 06.
HandlerMummy_Player 88FD LD DE,($EA93) Fetch the position of the player from EA93.
8901 CALL SteerCreature Call SteerCreature to steer the creature towards its target.
8904 JR HandlerMummy_SetSprite Jump to HandlerMummy_SetSprite to choose the sprite of the mummy.
Prev: 882D Up: Map Next: 8906