Prev: 862E Up: Map Next: 86F2
8672: Handle Spikey And Ghost
The handler for the spikey (sprite IDs 5E and 5F) and the ghost (68 and 69). The counter at offset 0A runs from -07 up to 06 and half of it is added to the Y position, which makes the creature bob up and down as it moves. A new random velocity is chosen every time that the counter wraps round. The movement itself is done by MoveCreature.
Input
IX The creature entity
HandlerSpikey 8672 CALL StoreEntity Call StoreEntity to save the position of the creature.
8675 LD A,($EA91) Fetch the room of the player from PlayerRoom.
8678 CP (IX+$01) Jump to CountDownCreature if the creature is not in the same room as the player.
867B JP NZ,CountDownCreature
867E LD HL,$5E25 Point HL at the number of creatures at NumCreatures.
8681 INC (HL) Increment the number of creatures by one.
8682 LD (IX+$0F),$00 Write 00 to offset 0F of the creature, so it is not removed.
8686 CALL CheckPlayerTouch Call CheckPlayerTouch to check whether the entity is touching the player.
8689 DEC E Jump to HandleTouchingCreature if the creature touched the player.
868A JP Z,HandleTouchingCreature
868D CALL CheckWeaponHit Call CheckWeaponHit to check whether the weapon has hit the entity.
8690 DEC E Jump to PopCreature if the creature was hit by a weapon.
8691 JP Z,PopCreature
Animate the creature by changing the sprite every other step.
8694 LD A,(IX+$0A) Fetch the bobbing counter from offset 0A.
8697 RRA Halve the bobbing counter.
8698 AND %00000001 Keep only bit 0.
869A LD C,A Keep the animation frame in C.
869B LD A,(IX+$00) Fetch the sprite ID of the creature.
869E AND %11111110 Reset bit 0.
86A0 ADD A,C Add the animation frame to the sprite ID.
86A1 LD (IX+$00),A Update the sprite ID of the creature.
86A4 LD DE,($5E1D) Fetch the size of the room from CurrentRoom_Width.
Move on to the next step of the bobbing. A new velocity is chosen when the counter reaches 07.
86A8 INC (IX+$0A) Increment the bobbing counter.
86AB LD A,(IX+$0A) Fetch the bobbing counter.
86AE CP $07 Jump to HandlerSpikey_Bob unless it has reached 07.
86B0 JR NZ,HandlerSpikey_Bob
86B2 CALL RandomiseVelocity Call RandomiseVelocity to give the creature a new random velocity.
86B5 LD (IX+$0A),$F9 Set the bobbing counter to -07.
Add half of the counter to the Y position of the creature and keep it inside the room.
HandlerSpikey_Bob 86B9 SRA A Halve the counter, keeping its sign.
86BB ADD A,(IX+$04) Add the Y position of the creature.
86BE LD C,A Keep the new Y position in C.
86BF SUB $68 Subtract 68 (the vertical centre of the room).
86C1 JP P,HandlerSpikey_CheckBottom Jump to HandlerSpikey_CheckBottom if the new position is below the centre.
86C4 NEG Make the distance from the centre positive.
86C6 CP D Jump to HandlerSpikey_Store if the new position is still inside the room.
86C7 JR C,HandlerSpikey_Store
86C9 LD (IX+$09),$02 Set the Y velocity of the creature to 02.
86CD SET 1,(IX+$06) Set bit 1 of the direction of the creature, so it is heading down.
86D1 BIT 7,(IX+$0A) Jump to HandlerSpikey_Store if the bobbing counter is positive.
86D5 JR Z,HandlerSpikey_Store
86D7 LD (IX+$0A),$00 Reset the bobbing counter to 00.
HandlerSpikey_Store 86DB LD (IX+$04),C Update the Y position of the creature.
86DE JP MoveCreature Jump to MoveCreature to move the creature.
HandlerSpikey_CheckBottom 86E1 CP D Jump to HandlerSpikey_Store if the new position is still inside the room.
86E2 JR C,HandlerSpikey_Store
86E4 RES 1,(IX+$06) Reset bit 1 of the direction of the creature, so it is heading up.
86E8 LD (IX+$09),$FE Set the Y velocity of the creature to -02.
86EC LD (IX+$0A),$F9 Set the bobbing counter to -07.
86F0 JR HandlerSpikey_Store Jump to HandlerSpikey_Store to store the Y position of the creature.
Prev: 862E Up: Map Next: 86F2