![]() |
Routines |
| Prev: 8787 | Up: Map | Next: 882D |
|
The handler for the ghoul (sprite IDs 62 and 63). It is like HandlerPumpkin, but the weapon is checked before the player, and the direction at offset 06 is changed every eight steps. The velocities build up by one every other step towards 02 or -02. The movement itself is done by MoveCreature.
|
||||||||
| HandlerGhoul | 87A6 | CALL StoreEntity | Call StoreEntity to save the position of the ghoul. | |||||
| 87A9 | LD A,($EA91) | Fetch the room of the player from PlayerRoom. | ||||||
| 87AC | CP (IX+$01) | Jump to CountDownCreature if the ghoul is not in the same room as the player. | ||||||
| 87AF | JP NZ,CountDownCreature | |||||||
| 87B2 | LD HL,$5E25 | Point HL at the number of creatures at NumCreatures. | ||||||
| 87B5 | INC (HL) | Increment the number of creatures by one. | ||||||
| 87B6 | CALL CheckWeaponHit | Call CheckWeaponHit to check whether the weapon has hit the entity. | ||||||
| 87B9 | DEC E | Jump to PopCreature if the ghoul was hit by a weapon. | ||||||
| 87BA | JP Z,PopCreature | |||||||
| 87BD | CALL CheckPlayerTouch | Call CheckPlayerTouch to check whether the entity is touching the player. | ||||||
| 87C0 | DEC E | Jump to HandleTouchingCreature if the ghoul touched the player. | ||||||
| 87C1 | JP Z,HandleTouchingCreature | |||||||
| 87C4 | LD DE,($5E1D) | Fetch the size of the room from CurrentRoom_Width. | ||||||
| 87C8 | LD (IX+$0F),$00 | Write 00 to offset 0F of the ghoul, so it is not removed. | ||||||
| 87CC | LD (IX+$05),$46 | Set the attribute of the entity to INK:YELLOW, PAPER:BLACK (BRIGHT). | ||||||
| 87D0 | LD A,(IX+$07) | Fetch the step counter from offset 07. | ||||||
| 87D3 | AND %00000111 | Keep only bits 0-2. | ||||||
| 87D5 | JR NZ,HandlerGhoul_Velocity | Jump to HandlerGhoul_Velocity if the result is not zero. | ||||||
| 87D7 | LD A,R | Fetch a random number (from the refresh register). | ||||||
| 87D9 | AND %00000011 | Keep only bits 0-1. | ||||||
| 87DB | LD (IX+$06),A | Update the direction of the ghoul. | ||||||
| HandlerGhoul_Velocity | 87DE | BIT 0,(IX+$07) | Jump to HandlerGhoul_Animate if bit 0 of the step counter is set. | |||||
| 87E2 | JR NZ,HandlerGhoul_Animate | |||||||
| 87E4 | BIT 0,(IX+$06) | Jump to HandlerGhoul_SlowLeft if the ghoul is not heading right. | ||||||
| 87E8 | JR Z,HandlerGhoul_SlowLeft | |||||||
| 87EA | LD A,(IX+$08) | Fetch the X velocity of the ghoul. | ||||||
| 87ED | CP $02 | Jump to HandlerGhoul_VelocityY if it is already 02. | ||||||
| 87EF | JR Z,HandlerGhoul_VelocityY | |||||||
| 87F1 | INC (IX+$08) | Increment the X velocity by one. | ||||||
| HandlerGhoul_VelocityY | 87F4 | BIT 1,(IX+$06) | Jump to HandlerGhoul_SlowUp if the ghoul is not heading down. | |||||
| 87F8 | JR Z,HandlerGhoul_SlowUp | |||||||
| 87FA | LD A,(IX+$09) | Fetch the Y velocity of the ghoul. | ||||||
| 87FD | CP $02 | Jump to HandlerGhoul_Animate if it is already 02. | ||||||
| 87FF | JR Z,HandlerGhoul_Animate | |||||||
| 8801 | INC (IX+$09) | Increment the Y velocity by one. | ||||||
|
Move on to the next step, and animate the ghoul by changing its sprite.
|
||||||||
| HandlerGhoul_Animate | 8804 | INC (IX+$07) | Increment the step counter. | |||||
| 8807 | LD A,(IX+$07) | Fetch the step counter. | ||||||
| 880A | AND %00000001 | Keep only bit 0. | ||||||
| 880C | XOR (IX+$00) | Exclusive-or the sprite ID with A, which flips bit 0 of it on every other step. | ||||||
| 880F | LD (IX+$00),A | Write the new sprite ID back to the ghoul. | ||||||
| 8812 | JP MoveCreature | Jump to MoveCreature to move the creature. | ||||||
|
Speed up the X velocity towards -02 which is used when the ghoul is heading left.
|
||||||||
| HandlerGhoul_SlowLeft | 8815 | LD A,(IX+$08) | Fetch the X velocity of the ghoul. | |||||
| 8818 | CP $FE | Jump to HandlerGhoul_VelocityY if it is already -02. | ||||||
| 881A | JR Z,HandlerGhoul_VelocityY | |||||||
| 881C | DEC (IX+$08) | Decrease the X velocity by one. | ||||||
| 881F | JR HandlerGhoul_VelocityY | Jump to HandlerGhoul_VelocityY to work out the vertical velocity of the ghoul. | ||||||
|
Speed up the Y velocity towards -02 which is used when the ghoul is heading up.
|
||||||||
| HandlerGhoul_SlowUp | 8821 | LD A,(IX+$09) | Fetch the Y velocity of the ghoul. | |||||
| 8824 | CP $FE | Jump to HandlerGhoul_Animate if it is already -02. | ||||||
| 8826 | JR Z,HandlerGhoul_Animate | |||||||
| 8828 | DEC (IX+$09) | Decrease the Y velocity by one. | ||||||
| 882B | JR HandlerGhoul_Animate | Jump to HandlerGhoul_Animate to animate the ghoul. | ||||||
| Prev: 8787 | Up: Map | Next: 882D |