Prev: 33770 Up: Map Next: 33997
33887: Handle Pumpkin And Spider
The handler for the pumpkin (sprite IDs 76 and 77) and the spider (92 and 93). If the player is in another room then CountDownCreature counts the creature down until it is removed. Otherwise the creature is counted and checked for being hit by a weapon (CheckWeaponHit) or touching the player (CheckPlayerTouch). Offset 6 of the creature holds the direction it is heading in (bit 0 is set for right and bit 1 is set for down). A new direction is chosen at random every sixteen steps, and the velocities at offsets 8 and 9 build up by one every other step towards 2 or -2. The movement itself is done by MoveCreature.
Input
IX The creature entity
HandlerPumpkin 33887 CALL StoreEntity Call StoreEntity to save the position of the creature.
33890 LD A,(60049) Fetch the room of the player from PlayerRoom.
33893 CP (IX+1) Jump to CountDownCreature if the creature is not in the same room as the player.
33896 JP NZ,CountDownCreature
33899 LD HL,24101 Point HL at the number of creatures at NumCreatures.
33902 INC (HL) Increment the number of creatures by one.
Check whether the creature has been hit by a weapon or touched the player.
33903 CALL CheckWeaponHit Call CheckWeaponHit to check whether the weapon has hit the entity.
33906 DEC E Jump to PopCreature if the creature was hit by a weapon.
33907 JP Z,PopCreature
33910 CALL CheckPlayerTouch Call CheckPlayerTouch to check whether the entity is touching the player.
33913 DEC E Jump to HandleTouchingCreature if the creature touched the player.
33914 JP Z,HandleTouchingCreature
33917 LD DE,(24093) Fetch the size of the room from CurrentRoom_Width.
33921 LD (IX+15),0 Write 0 to offset 15 of the creature, so it is not removed.
33925 LD (IX+5),70 Set the attribute of the entity to INK:YELLOW, PAPER:BLACK (BRIGHT).
Choose a new direction every sixteen steps.
33929 LD A,(IX+7) Fetch the step counter of the creature.
33932 AND %00001111 Keep only bits 0-3.
33934 JR NZ,HandlerPumpkin_Velocity Jump to HandlerPumpkin_Velocity if the result is not zero.
33936 LD A,R Fetch a random number (from the refresh register).
33938 AND %00000011 Keep only bits 0-1.
33940 LD (IX+6),A Update the direction of the creature.
Only change the velocities on every other step.
HandlerPumpkin_Velocity 33943 BIT 0,(IX+7) Jump to HandlerPumpkin_Animate if bit 0 of the step counter is set.
33947 JR NZ,HandlerPumpkin_Animate
33949 BIT 0,(IX+6) Jump to MoveCreature_SlowLeft if the creature is not heading right.
33953 JP Z,MoveCreature_SlowLeft
33956 LD A,(IX+8) Fetch the X velocity of the creature.
33959 CP 2 Jump to HandlerPumpkin_VelocityY if it is already 2.
33961 JR Z,HandlerPumpkin_VelocityY
33963 INC (IX+8) Increment the X velocity by one.
This entry point is used by the routine at MoveCreature.
HandlerPumpkin_VelocityY 33966 BIT 1,(IX+6) Jump to MoveCreature_SlowUp if the creature is not heading down.
33970 JP Z,MoveCreature_SlowUp
33973 LD A,(IX+9) Fetch the Y velocity of the creature.
33976 CP 2 Jump to HandlerPumpkin_Animate if it is already 2.
33978 JR Z,HandlerPumpkin_Animate
33980 INC (IX+9) Increment the Y velocity by one.
This entry point is used by the routine at MoveCreature.
Move on to the next step, and animate the creature by changing its sprite.
HandlerPumpkin_Animate 33983 INC (IX+7) Increment the step counter of the creature.
33986 LD A,(IX+7) Fetch the step counter of the creature.
33989 AND %00000001 Keep only bit 0.
33991 XOR (IX+0) Exclusive-or the sprite ID with A, which flips bit 0 of it on every other step.
33994 LD (IX+0),A Write the new sprite ID back to the creature.
Prev: 33770 Up: Map Next: 33997