Prev: 845F Up: Map Next: 8566
84CD: 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 31 or more). The creature is kept within the room by comparing its distance from the centre of the room (58 across and 68 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 08.
MoveCreature 84CD LD A,(IX+$03) Fetch the X position of the creature.
84D0 ADD A,(IX+$08) Add the X velocity of the creature.
84D3 LD C,A Keep the new X position in C.
84D4 SUB $58 Subtract 58 (the horizontal centre of the room).
84D6 JR C,MoveCreature_CheckLeft Jump to MoveCreature_CheckLeft if the creature is left of the centre.
84D8 CP E Jump to MoveCreature_Vertical if the new position is still inside the room.
84D9 JR C,MoveCreature_Vertical
84DB RES 0,(IX+$06) Reset bit 0 of the direction of the creature, so it is heading left.
84DF LD (IX+$08),$FE Set the X velocity of the creature to -02.
84E3 LD C,(IX+$03) Keep the old X position in C.
84E6 JR MoveCreature_Vertical Jump to MoveCreature_Vertical to move the creature vertically.
MoveCreature_CheckLeft 84E8 NEG Negate A.
84EA CP E Jump to MoveCreature_Vertical if the new position is still inside the room.
84EB JR C,MoveCreature_Vertical
84ED SET 0,(IX+$06) Set bit 0 of the direction of the creature, so it is heading right.
84F1 LD C,(IX+$03) Keep the old X position in C.
84F4 LD (IX+$08),$02 Set the X velocity of the creature to 02.
Move the creature vertically. The Y velocity is at offset 09.
MoveCreature_Vertical 84F8 LD A,(IX+$04) Fetch the Y position of the creature.
84FB ADD A,(IX+$09) Add the Y velocity of the creature.
84FE LD B,A Keep the new Y position in B.
84FF SUB $68 Subtract 68 (the vertical centre of the room).
8501 JR C,MoveCreature_CheckTop Jump to MoveCreature_CheckTop if the creature is above the centre.
8503 CP D Jump to MoveCreature_Store if the new position is still inside the room.
8504 JR C,MoveCreature_Store
8506 RES 1,(IX+$06) Reset bit 1 of the direction of the creature, so it is heading up.
850A LD (IX+$09),$FE Set the Y velocity of the creature to -02.
850E LD B,(IX+$04) Keep the old Y position in B.
8511 JR MoveCreature_Store Jump to MoveCreature_Store to save the new position of the creature.
MoveCreature_CheckTop 8513 NEG Negate A.
8515 CP D Jump to MoveCreature_Store if the new position is still inside the room.
8516 JR C,MoveCreature_Store
8518 SET 1,(IX+$06) Set bit 1 of the direction of the creature, so it is heading down.
851C LD B,(IX+$04) Keep the old Y position in B.
851F LD (IX+$09),$02 Set the Y velocity of the creature to 02.
Save the new position, and then display the creature if the player is in the same room.
MoveCreature_Store 8523 LD (IX+$03),C Update the X position of the creature.
8526 LD (IX+$04),B Update the Y position of the creature.
8529 LD A,($EA91) Fetch the room of the player from PlayerRoom.
852C CP (IX+$01) Return if the creature is not in the same room as the player.
852F RET NZ
8530 LD A,(IX+$00) Fetch the sprite ID of the creature.
8533 AND %11111100 Keep only bits 2-7.
8535 CP $9C Jump to MoveCreature_Display if the creature is a hunchback (9C to 9F).
8537 JR Z,MoveCreature_Display
8539 AND %11110000 Keep only bits 4-7.
853B CP $70 Jump to MoveCreature_Display if the creature is a boss (70 to 7F).
853D JR Z,MoveCreature_Display
853F LD A,($EA90) Fetch the sprite ID of the player from Player.
8542 CP $31 Jump to PopCreature if the player sprite ID is 31 or more.
8544 JP NC,PopCreature
MoveCreature_Display 8547 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 -02 which is used when the creature is heading left.
MoveCreature_SlowLeft 854A LD A,(IX+$08) Fetch the X velocity of the creature.
854D CP $FE Jump to HandlerPumpkin_VelocityY if it is already -02.
854F JP Z,HandlerPumpkin_VelocityY
8552 DEC (IX+$08) Decrease the X velocity by one.
8555 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 -02 which is used when the creature is heading up.
MoveCreature_SlowUp 8558 LD A,(IX+$09) Fetch the Y velocity of the creature.
855B CP $FE Jump to HandlerPumpkin_Animate if it is already -02.
855D JP Z,HandlerPumpkin_Animate
8560 DEC (IX+$09) Decrease the Y velocity by one.
8563 JP HandlerPumpkin_Animate Jump to HandlerPumpkin_Animate to animate the pumpkin.
Prev: 845F Up: Map Next: 8566