Prev: A267 Up: Map Next: A3DD
A316: Handle Sabreman On Rope
Handler for the object types 01 to 08 which Sabreman has while he hangs on and swings from the rope (the type 17 object, see Handle_Rope). The sprites are the ones that are called swimming (01 to 04 when he moves to the left and 05 to 08 when he moves to the right; the frame follows the x position).
If bit 3 or bit 6 of the redraw flags is set, he lets go at Handle_Sabreman_On_Rope_Let_Go. Otherwise the routine checks for contact with the bubbles, the creatures and the falling stalactite, any of which sends him to Knock_Sabreman_Off_Rope with B=10. Next it moves the rope with Update_Rope and, if he stays in the same room, reads the controls: a bottom row key (or the joystick fire button) makes him let go at Handle_Sabreman_On_Rope_Let_Go, and the fire key throws a weapon.
The position and the velocity of the end of the rope (see Line_Step_Count) are then converted to the position and the velocity of Sabreman. If the y position is 9F or more and the room has a floor, he lets go and stands on the floor at Stand_Sabreman_On_Floor.
Input
IX Object record of Sabreman
Handle_Sabreman_On_Rope A316 CALL StoreEntity Remember the position and sprite id of Sabreman (see StoreEntity).
A319 LD A,(IX+$0F) Fetch the redraw flags of Sabreman.
A31C AND %01001000 Keep only bit 3 (the special state) and bit 6 (being carried).
A31E JP NZ,Handle_Sabreman_On_Rope_Let_Go Jump to Handle_Sabreman_On_Rope_Let_Go and let go of the rope if either of them is set.
A321 CALL Check_Bubble_Contact Check for contact with the bubbles.
A324 BIT 2,C Jump to Handle_Sabreman_On_Rope_Hit if Sabreman touches a bubble (bit 2 of C).
A326 JR NZ,Handle_Sabreman_On_Rope_Hit
A328 CALL Check_Decoration_Contact Check for contact with the creatures.
A32B BIT 2,C Test bit 2 of C (set if Sabreman touches one).
Handle_Sabreman_On_Rope_Hit A32D LD B,$10 Set B to 10 (this is not changed by the contact test above).
A32F JP NZ,Knock_Sabreman_Off_Rope Jump to Knock_Sabreman_Off_Rope to knock Sabreman off the rope if he touches a bubble or a creature.
A332 CALL Check_Stalactite_Contact Check for contact with the falling stalactite.
A335 BIT 2,C Jump to Knock_Sabreman_Off_Rope to knock Sabreman off the rope if the stalactite hits him.
A337 JP NZ,Knock_Sabreman_Off_Rope
A33A LD L,(IX+$02) Fetch the room x of Sabreman.
A33D LD H,(IX+$04) Fetch the room y of Sabreman.
A340 PUSH HL Stash the room of Sabreman on the stack.
A341 CALL Update_Rope Move the rope (see Update_Rope).
A344 POP HL Restore the room that Sabreman was in before the rope moved.
A345 LD E,(IX+$02) Fetch the room x that Sabreman is in now.
A348 LD D,(IX+$04) Fetch the room y that Sabreman is in now.
A34B AND A Compare the old room with the new room.
A34C SBC HL,DE
A34E JR NZ,Set_Position_From_Rope Jump to Set_Position_From_Rope if the swing of the rope has taken him to a different room.
A350 CALL ReadControls Read the controls.
A353 BIT 5,A Jump to Handle_Sabreman_On_Rope_Let_Go and let go of the rope if the "bottom row key" bit of the controls (bit 5) is clear.
A355 JR Z,Handle_Sabreman_On_Rope_Let_Go
A357 BIT 4,A Jump to Handle_Sabreman_On_Rope_Fire_Released if the fire key is not pressed (bit 4 of the controls is set).
A359 JR NZ,Handle_Sabreman_On_Rope_Fire_Released
A35B CALL Throw_Weapon Throw a weapon (see Throw_Weapon).
A35E JR Set_Position_From_Rope Jump to Set_Position_From_Rope.
Handle_Sabreman_On_Rope_Fire_Released A360 LD A,$FF Set the flag for the released fire key (Fire_Key_Flag) to FF.
A362 LD ($AAAB),A
This entry point is used by the routine at Handle_Sabreman_Falling.
Set the position of Sabreman from the position of the end of the rope.
Set_Position_From_Rope A365 LD HL,($AA95) Fetch the position of the end of the rope (x position in L, y position in H).
A368 LD DE,$F80C Set the offset from the end of the rope to Sabreman (0C pixels to the left and 08 pixels down).
A36B AND A Work out the position of Sabreman from the end of the rope and stash it on the stack.
A36C SBC HL,DE
A36E PUSH HL
A36F CALL Read_World_Map Read the world map entry of the room.
A372 LD A,E Copy the room flags to A.
A373 LD ($AAAC),A Store the room flags in Room_Flags.
A376 POP HL Restore the position of Sabreman.
A377 LD (IX+$01),L Set the x position of Sabreman.
A37A LD (IX+$03),H Set the y position of Sabreman.
A37D LD A,H Copy the y position of Sabreman to A.
A37E CP $9F Is Sabreman at or below the height of the floor (y position 9F)?
A380 LD A,($AAA2) Fetch the x velocity of the end of the rope.
A383 LD (IX+$06),A Give Sabreman the x velocity of the end of the rope.
A386 JR C,Handle_Sabreman_On_Rope_Choose_Frame Jump to Handle_Sabreman_On_Rope_Choose_Frame if Sabreman is still above the floor.
A388 BIT 4,E Jump to Stand_Sabreman_On_Floor if the room has a floor and Sabreman has reached it (bit 4 of the room flags).
A38A JP NZ,Stand_Sabreman_On_Floor
Handle_Sabreman_On_Rope_Choose_Frame A38D LD A,L Copy the x position of Sabreman to A.
A38E RRA Divide the x position by eight (the frame of the swimming animation follows the x position).
A38F RRA
A390 RRA
A391 AND %00000011 Keep only the two low bits.
A393 INC A Add one to make a frame from 01 to 04.
A394 BIT 7,(IX+$06) Jump to Handle_Sabreman_On_Rope_Set_Sprite if he is swinging to the left (the x velocity is negative).
A398 JR NZ,Handle_Sabreman_On_Rope_Set_Sprite
A39A ADD A,$04 Add four to use the frames for swinging to the right.
Handle_Sabreman_On_Rope_Set_Sprite A39C LD (IX+$00),A Set the sprite id.
A39F CALL Update_Object_Sprite Update the sprite of the object (see Update_Object_Sprite).
A3A2 JP Draw_Rope Jump to Draw_Rope.
Sabreman is hit or lets go of the rope, and starts to fall from the position of the end of the rope. The velocities are taken from the change in that position and the sprite id becomes 15 or 16 (falling).
Handle_Sabreman_On_Rope_Let_Go A3A5 LD HL,($AA95) Fetch the position of the end of the rope.
A3A8 LD DE,($AA97) Fetch the previous position of the end of the rope.
A3AC LD A,H Copy the y position of the end of the rope to A.
A3AD SUB D Subtract the previous y position to get how far the end of the rope moved.
A3AE SLA A Multiply the movement by eight to get the y velocity.
A3B0 SLA A
A3B2 SLA A
A3B4 LD (IX+$09),A Give Sabreman the y velocity.
A3B7 LD A,L Copy the x position of the end of the rope to A.
A3B8 SUB E Subtract the previous x position to get how far the end of the rope moved.
A3B9 LD (IX+$06),A Give Sabreman that as his x velocity.
A3BC LD A,$15 Use the sprite id for falling to the left (15).
A3BE BIT 7,(IX+$06) Jump to Handle_Sabreman_On_Rope_Let_Go_Set_Sprite if he is moving to the left (the x velocity is negative).
A3C2 JR NZ,Handle_Sabreman_On_Rope_Let_Go_Set_Sprite
A3C4 ADD A,$01 Use the sprite id for falling to the right (16).
Handle_Sabreman_On_Rope_Let_Go_Set_Sprite A3C6 LD (IX+$00),A Set the sprite id.
A3C9 LD (IX+$0A),$20 Set the countdown to 20.
A3CD LD A,(IX+$06) Fetch the x velocity.
A3D0 OR (IX+$09) Combine it with the y velocity to see if Sabreman is moving at all.
A3D3 JP NZ,Restore_Type_17_Object Jump to Restore_Type_17_Object to start him falling if Sabreman is moving.
A3D6 LD (IX+$09),$10 Set the y velocity to 10 so that he falls.
A3DA JP Restore_Type_17_Object Jump to Restore_Type_17_Object.
Prev: A267 Up: Map Next: A3DD