Prev: E285 Up: Map Next: E420
E2CB: Handle Carrying Eagle
Handler for the object types 5C to 5F an eagle that carries Sabreman (see Handle_Flying_Creature). Bit 0 of the type is the frame of the animation, which follows bit 1 of the tick counter, and bit 1 is set when the x velocity is negative.
While Sabreman is being carried his record has the sprite id 60 to 63. The eagle puts his position in bytes 08 (x) and 09 (y) of his record (at Sabreman_Carried_X_Position and Sabreman_Carried_Y_Position), where Handle_Carried_Sabreman picks it up. The y position is 10 more than that of the eagle, so he hangs below it.
The eagle flies towards a target (byte 0C is the x position and byte 0E the y position, see Choose_Eagle_Target). Each call changes each velocity by one towards the target. The x velocity is kept between D0 and 37 and the y velocity between C7 and 37. The target changes when the eagle bounces off a decoration, a bubble, the floor, the ceiling or a wall. The eagle can also fly through the gaps in the frame of a room, and into the next room. The player can nudge the eagle with the controls (see Steer_Eagle).
The eagle lets go (see Check_Eagle_Release) when the low byte of FRAMES is zero, or when Sabreman has set bit 5 of his redraw flags, if it is in the open part of the room. If the sprite id of Sabreman is less than 1C (he is not being carried), the eagle lets go at once (see Release_Sabreman).
Input
IX Object record of the eagle
Handle_Carrying_Eagle E2CB CALL StoreEntity Save the state of the eagle.
E2CE LD A,($8F1A) Fetch the sprite id of Sabreman.
E2D1 CP $1C Jump to Release_Sabreman if he is not being carried.
E2D3 JP C,Release_Sabreman
E2D6 CALL Steer_Eagle Nudge the eagle if the player presses a direction.
E2D9 CALL Read_World_Map Read the world map entry of the room that the eagle is in. The flags of the room are returned in E.
E2DC LD A,($5C78) Fetch the low byte of FRAMES.
E2DF AND A Call Check_Eagle_Release to let go of Sabreman if the low byte of FRAMES is zero.
E2E0 CALL Z,Check_Eagle_Release
E2E3 LD A,($8F29) Fetch the redraw flags of Sabreman.
E2E6 BIT 5,A Test bit 5, which Sabreman sets to ask the eagle to let go.
E2E8 RES 5,A Reset bit 5.
E2EA LD ($8F29),A Store the redraw flags of Sabreman.
E2ED CALL NZ,Check_Eagle_Release Call Check_Eagle_Release to let go of Sabreman if bit 5 was set.
This entry point is used by the routine at Handle_Flying_Creature.
Handle_Carrying_Eagle_Carry E2F0 LD A,$01 Set the flag at Type_5C_Active_Flag to show that an eagle is carrying Sabreman.
E2F2 LD ($8EF1),A
E2F5 LD A,(IX+$03) Fetch the y position of the eagle.
E2F8 ADD A,$10 Add 10.
E2FA CP $9F Jump to Handle_Carrying_Eagle_Set_Carry_Position if the result is less than 9F.
E2FC JR C,Handle_Carrying_Eagle_Set_Carry_Position
E2FE BIT 4,E Jump to Handle_Carrying_Eagle_Set_Carry_Position if the room has no floor.
E300 JR Z,Handle_Carrying_Eagle_Set_Carry_Position
E302 LD A,$9F Limit the y position to 9F.
Handle_Carrying_Eagle_Set_Carry_Position E304 LD ($8F23),A Set the y position of Sabreman.
E307 LD A,(IX+$01) Fetch the x position of the eagle.
E30A LD ($8F22),A Set the x position of Sabreman.
Work out the type of the eagle. Bit 0 follows bit 1 of the tick counter and bit 1 is set when the x velocity is negative.
E30D LD A,(IX+$00) Fetch the type of the eagle.
E310 AND %11111110 Reset bit 0.
E312 LD C,A Keep the type without bit 0 in C.
E313 LD A,($8ED6) Fetch the tick counter.
E316 RRA Move bit 1 into bit 0.
E317 AND %00000001 Keep only that bit.
E319 ADD A,C Add the type.
E31A BIT 7,(IX+$08) Jump to Handle_Carrying_Eagle_Face_Right if the x velocity is positive.
E31E JR Z,Handle_Carrying_Eagle_Face_Right
E320 OR %00000010 Set bit 1.
E322 JR Handle_Carrying_Eagle_Store_Type Jump to Handle_Carrying_Eagle_Store_Type.
Handle_Carrying_Eagle_Face_Right E324 AND %11111101 Reset bit 1.
Handle_Carrying_Eagle_Store_Type E326 LD (IX+$00),A Store the type of the eagle.
Change the x velocity by one towards the target.
E329 LD A,(IX+$01) Fetch the x position of the eagle.
E32C CP (IX+$0C) Compare it with the x position of the target.
E32F LD A,(IX+$08) Fetch the x velocity.
E332 JP NC,Accelerate_Eagle_Left Jump to Accelerate_Eagle_Left if the eagle is at or to the right of the target.
E335 INC A Add one to the x velocity.
E336 BIT 7,A Jump to Handle_Carrying_Eagle_Store_X_Velocity if the x velocity is negative.
E338 JR NZ,Handle_Carrying_Eagle_Store_X_Velocity
E33A CP $38 Jump to Handle_Carrying_Eagle_Adjust_Y_Velocity if the x velocity has reached 38.
E33C JR NC,Handle_Carrying_Eagle_Adjust_Y_Velocity
This entry point is used by the routine at Accelerate_Eagle_Left.
Handle_Carrying_Eagle_Store_X_Velocity E33E LD (IX+$08),A Store the x velocity.
This entry point is used by the routine at Accelerate_Eagle_Left.
Change the y velocity by one towards the target.
Handle_Carrying_Eagle_Adjust_Y_Velocity E341 LD A,(IX+$03) Fetch the y position of the eagle.
E344 CP (IX+$0E) Compare it with the y position of the target.
E347 LD A,(IX+$09) Fetch the y velocity.
E34A JP NC,Accelerate_Eagle_Up Jump to Accelerate_Eagle_Up if the eagle is at or below the target.
E34D INC A Add one to the y velocity.
E34E BIT 7,A Jump to Handle_Carrying_Eagle_Store_Y_Velocity if the y velocity is negative.
E350 JR NZ,Handle_Carrying_Eagle_Store_Y_Velocity
E352 CP $38 Jump to Handle_Carrying_Eagle_Check_Contact if the y velocity has reached 38.
E354 JR NC,Handle_Carrying_Eagle_Check_Contact
This entry point is used by the routine at Accelerate_Eagle_Up.
Handle_Carrying_Eagle_Store_Y_Velocity E356 LD (IX+$09),A Store the y velocity.
This entry point is used by the routine at Accelerate_Eagle_Up.
Check for contact with the decorations and the bubbles, and bounce off them.
Handle_Carrying_Eagle_Check_Contact E359 PUSH DE Stash the flags of the room.
E35A CALL Check_Decoration_Contact Check for contact with the decorations.
E35D LD D,C Store the result in D.
E35E CALL Check_Bubble_Contact Check for contact with the bubbles.
E361 LD A,C Copy the result to A.
E362 OR D Combine it with the result for the decorations.
E363 LD C,A Store the combined result in C.
E364 POP DE Restore the flags of the room.
E365 BIT 2,C Jump to Handle_Carrying_Eagle_Move_X if the eagle is not touching anything.
E367 JR Z,Handle_Carrying_Eagle_Move_X
E369 BIT 1,C Jump to Handle_Carrying_Eagle_Check_Underside if the eagle is not on top of the object.
E36B JR Z,Handle_Carrying_Eagle_Check_Underside
E36D BIT 5,C Jump to Handle_Carrying_Eagle_Check_Sides if the object is a bubble and the eagle is away from the middle of it.
E36F JR NZ,Handle_Carrying_Eagle_Check_Sides
E371 LD A,(IX+$09) Fetch the y velocity.
E374 AND A Jump to Handle_Carrying_Eagle_Move_X if the eagle is moving up already.
E375 JP M,Handle_Carrying_Eagle_Move_X
E378 CPL Invert the y velocity, to send the eagle up.
E379 LD (IX+$09),A Store the y velocity.
E37C CALL Choose_Eagle_Target Choose a new target.
E37F JR Handle_Carrying_Eagle_Move_X Jump to Handle_Carrying_Eagle_Move_X.
Handle_Carrying_Eagle_Check_Underside E381 BIT 0,C Jump to Handle_Carrying_Eagle_Check_Sides if the eagle is not near the middle of the object.
E383 JR NZ,Handle_Carrying_Eagle_Check_Sides
E385 LD A,(IX+$09) Fetch the y velocity.
E388 AND A Jump to Handle_Carrying_Eagle_Check_Sides if the eagle is moving down already.
E389 JP P,Handle_Carrying_Eagle_Check_Sides
E38C CPL Invert the y velocity, to send the eagle down.
E38D LD (IX+$09),A Store the y velocity.
Handle_Carrying_Eagle_Check_Sides E390 LD A,(IX+$08) Fetch the x velocity.
E393 BIT 7,C Jump to Handle_Carrying_Eagle_Bounce_Left if the eagle is not to the right of the object.
E395 JR Z,Handle_Carrying_Eagle_Bounce_Left
E397 AND A Jump to Handle_Carrying_Eagle_Move_X if the eagle is moving to the right already.
E398 JP P,Handle_Carrying_Eagle_Move_X
E39B CPL Invert the x velocity.
E39C LD (IX+$08),A Store the x velocity.
E39F CALL Choose_Eagle_Target Choose a new target.
E3A2 JR Handle_Carrying_Eagle_Move_X Jump to Handle_Carrying_Eagle_Move_X.
Handle_Carrying_Eagle_Bounce_Left E3A4 AND A Jump to Handle_Carrying_Eagle_Move_X if the eagle is moving to the left already.
E3A5 JP M,Handle_Carrying_Eagle_Move_X
E3A8 CPL Invert the x velocity.
E3A9 LD (IX+$08),A Store the x velocity.
E3AC CALL Choose_Eagle_Target Choose a new target.
Move the eagle horizontally.
Handle_Carrying_Eagle_Move_X E3AF LD A,(IX+$0B) Fetch the contact flags.
E3B2 AND %11101110 Reset bits 0 and 4 (the ceiling and the floor).
E3B4 LD (IX+$0B),A Store the contact flags.
E3B7 LD L,(IX+$08) Fetch the x velocity into L.
E3BA BIT 7,L Test the sign of the x velocity.
E3BC LD H,$00 Clear the high byte of the x velocity (as a word).
E3BE JR Z,Handle_Carrying_Eagle_Set_Sabreman_Velocity Jump to Handle_Carrying_Eagle_Set_Sabreman_Velocity if the x velocity is positive.
E3C0 LD H,$FF Set the high byte of the x velocity to FF to extend the sign.
Handle_Carrying_Eagle_Set_Sabreman_Velocity E3C2 LD A,L Copy the x velocity to A.
E3C3 SRA A Divide it by sixteen, keeping its sign.
E3C5 SRA A
E3C7 SRA A
E3C9 SRA A
E3CB LD ($8F20),A Set the x velocity of Sabreman.
E3CE CALL Move_Object_Horizontally Move the eagle horizontally (see Move_Object_Horizontally). The new x position is returned in A.
E3D1 JP Z,Limit_Eagle_Sideways_Movement Jump to Limit_Eagle_Sideways_Movement if the new x position is less than 80.
E3D4 CP $D0 Jump to Handle_Carrying_Eagle_Store_X if the new x position is less than D0.
E3D6 JR C,Handle_Carrying_Eagle_Store_X
E3D8 BIT 2,E Jump to Limit_Eagle_Sideways_Movement_Right_Gap if the room has no wall on the right.
E3DA JP Z,Limit_Eagle_Sideways_Movement_Right_Gap
E3DD LD A,(IX+$08) Fetch the x velocity.
E3E0 CPL Invert it.
E3E1 LD (IX+$08),A Store the x velocity.
E3E4 CALL Choose_Eagle_Target Choose a new target.
E3E7 LD A,$CF Set the x position to CF.
This entry point is used by the routine at Limit_Eagle_Sideways_Movement.
Handle_Carrying_Eagle_Store_X E3E9 LD (IX+$01),A Store the x position.
E3EC LD A,(IX+$0B) Fetch the contact flags.
E3EF AND %10111011 Reset bits 2 and 6 (the right and left walls).
E3F1 LD (IX+$0B),A Store the contact flags.
Move the eagle vertically.
E3F4 LD L,(IX+$09) Fetch the y velocity into L.
E3F7 BIT 7,L Test the sign of the y velocity.
E3F9 LD H,$00 Clear the high byte of the y velocity (as a word).
E3FB JR Z,Handle_Carrying_Eagle_Move_Y Jump to Handle_Carrying_Eagle_Move_Y if the y velocity is positive.
E3FD LD H,$FF Set the high byte of the y velocity to FF to extend the sign.
Handle_Carrying_Eagle_Move_Y E3FF CALL Move_Object_Vertically Move the eagle vertically (see Move_Object_Vertically). The new y position is returned in A.
E402 JP Z,Limit_Eagle_Vertical_Movement Jump to Limit_Eagle_Vertical_Movement if the new y position is less than 80.
E405 CP $9F Jump to Handle_Carrying_Eagle_Store_Y if the new y position is less than 9F.
E407 JR C,Handle_Carrying_Eagle_Store_Y
E409 BIT 4,E Jump to Limit_Eagle_Vertical_Movement_Bottom_Gap if the room has no floor.
E40B JP Z,Limit_Eagle_Vertical_Movement_Bottom_Gap
E40E LD A,(IX+$09) Fetch the y velocity.
E411 CPL Invert it.
E412 LD (IX+$09),A Store the y velocity.
E415 CALL Choose_Eagle_Target Choose a new target.
E418 LD A,$9F Set the y position to 9F.
This entry point is used by the routine at Limit_Eagle_Vertical_Movement.
Handle_Carrying_Eagle_Store_Y E41A LD (IX+$03),A Store the y position.
E41D JP Update_Object_Sprite Jump to Update_Object_Sprite.
Prev: E285 Up: Map Next: E420