Prev: 33887 Up: Map Next: 34150
33997: Move Creature
Moves a creature by its velocities, and turns it around if it would leave the room. Then, if the player is in the room, the creature is displayed by HandlerCharacter_Display. The creatures that are not bosses are removed instead if the player is not a character sprite any more (the sprite ID is 49 or more). The creature is kept within the room by comparing its distance from the centre of the room (88 across and 104 down) to the size of the room.
Input
IX The creature entity
DE The size of the room (width in E and height in D)
Move the creature horizontally. The X velocity is at offset 8.
MoveCreature 33997 LD A,(IX+3) Fetch the X position of the creature.
34000 ADD A,(IX+8) Add the X velocity of the creature.
34003 LD C,A Keep the new X position in C.
34004 SUB 88 Subtract 88 (the horizontal centre of the room).
34006 JR C,MoveCreature_CheckLeft Jump to MoveCreature_CheckLeft if the creature is left of the centre.
34008 CP E Jump to MoveCreature_Vertical if the new position is still inside the room.
34009 JR C,MoveCreature_Vertical
34011 RES 0,(IX+6) Reset bit 0 of the direction of the creature, so it is heading left.
34015 LD (IX+8),254 Set the X velocity of the creature to -2.
34019 LD C,(IX+3) Keep the old X position in C.
34022 JR MoveCreature_Vertical Jump to MoveCreature_Vertical to move the creature vertically.
MoveCreature_CheckLeft 34024 NEG Negate A.
34026 CP E Jump to MoveCreature_Vertical if the new position is still inside the room.
34027 JR C,MoveCreature_Vertical
34029 SET 0,(IX+6) Set bit 0 of the direction of the creature, so it is heading right.
34033 LD C,(IX+3) Keep the old X position in C.
34036 LD (IX+8),2 Set the X velocity of the creature to 2.
Move the creature vertically. The Y velocity is at offset 9.
MoveCreature_Vertical 34040 LD A,(IX+4) Fetch the Y position of the creature.
34043 ADD A,(IX+9) Add the Y velocity of the creature.
34046 LD B,A Keep the new Y position in B.
34047 SUB 104 Subtract 104 (the vertical centre of the room).
34049 JR C,MoveCreature_CheckTop Jump to MoveCreature_CheckTop if the creature is above the centre.
34051 CP D Jump to MoveCreature_Store if the new position is still inside the room.
34052 JR C,MoveCreature_Store
34054 RES 1,(IX+6) Reset bit 1 of the direction of the creature, so it is heading up.
34058 LD (IX+9),254 Set the Y velocity of the creature to -2.
34062 LD B,(IX+4) Keep the old Y position in B.
34065 JR MoveCreature_Store Jump to MoveCreature_Store to save the new position of the creature.
MoveCreature_CheckTop 34067 NEG Negate A.
34069 CP D Jump to MoveCreature_Store if the new position is still inside the room.
34070 JR C,MoveCreature_Store
34072 SET 1,(IX+6) Set bit 1 of the direction of the creature, so it is heading down.
34076 LD B,(IX+4) Keep the old Y position in B.
34079 LD (IX+9),2 Set the Y velocity of the creature to 2.
Save the new position, and then display the creature if the player is in the same room.
MoveCreature_Store 34083 LD (IX+3),C Update the X position of the creature.
34086 LD (IX+4),B Update the Y position of the creature.
34089 LD A,(60049) Fetch the room of the player from PlayerRoom.
34092 CP (IX+1) Return if the creature is not in the same room as the player.
34095 RET NZ
34096 LD A,(IX+0) Fetch the sprite ID of the creature.
34099 AND %11111100 Keep only bits 2-7.
34101 CP 156 Jump to MoveCreature_Display if the creature is a hunchback (156 to 159).
34103 JR Z,MoveCreature_Display
34105 AND %11110000 Keep only bits 4-7.
34107 CP 112 Jump to MoveCreature_Display if the creature is a boss (112 to 127).
34109 JR Z,MoveCreature_Display
34111 LD A,(60048) Fetch the sprite ID of the player from Player.
34114 CP 49 Jump to PopCreature if the player sprite ID is 49 or more.
34116 JP NC,PopCreature
MoveCreature_Display 34119 JP HandlerCharacter_Display Jump to HandlerCharacter_Display to display the creature.
This entry point is used by the routine at HandlerPumpkin.
Speed up the X velocity towards -2 which is used when the creature is heading left.
MoveCreature_SlowLeft 34122 LD A,(IX+8) Fetch the X velocity of the creature.
34125 CP 254 Jump to HandlerPumpkin_VelocityY if it is already -2.
34127 JP Z,HandlerPumpkin_VelocityY
34130 DEC (IX+8) Decrease the X velocity by one.
34133 JP HandlerPumpkin_VelocityY Jump to HandlerPumpkin_VelocityY to work out the vertical velocity of the pumpkin.
This entry point is used by the routine at HandlerPumpkin.
Speed up the Y velocity towards -2 which is used when the creature is heading up.
MoveCreature_SlowUp 34136 LD A,(IX+9) Fetch the Y velocity of the creature.
34139 CP 254 Jump to HandlerPumpkin_Animate if it is already -2.
34141 JP Z,HandlerPumpkin_Animate
34144 DEC (IX+9) Decrease the Y velocity by one.
34147 JP HandlerPumpkin_Animate Jump to HandlerPumpkin_Animate to animate the pumpkin.
Prev: 33887 Up: Map Next: 34150