Prev: A8EF Up: Map Next: AA3C
A925: Handle Sabreman Tumbling
Handler for the object types 18 to 1B which are the tumbling sprites of Sabreman. The sprite id is 18 plus bits 1 and 2 of the tick counter at GameTimer, so the frames follow each other as time passes.
He tumbles after the stalactite or a creature has hit him and when he bumps into a side wall while he is falling. The routine decreases the countdown, checks for contact with the bubbles and the creatures (which push him sideways with an x velocity of 02 or FE), moves him sideways and applies gravity in the same way as Handle_Sabreman_Falling, and goes on at Handle_Sabreman_Falling_Above_Floor once the y position is less than 9F.
Unlike the falling handler the y velocity here has a limit of 76.
Input
IX Object record of Sabreman
Handle_Sabreman_Tumbling A925 CALL StoreEntity Remember the position and sprite id of Sabreman.
This entry point is used by the routines at Handle_Sabreman_Jumping, Handle_Sabreman_Falling and Tumble_Sabreman.
Deal with the special states in the same way as Handle_Sabreman_Walking.
Continue_Sabreman_Tumbling A928 BIT 6,(IX+$0F) Jump to Start_Being_Carried if Sabreman is being carried (bit 6 of the redraw flags).
A92C JP NZ,Start_Being_Carried
A92F BIT 7,(IX+$0F) Jump to Start_Tumbling if Sabreman is tumbling (bit 7 of the redraw flags).
A933 JP NZ,Start_Tumbling
Read the world map entry and decrease the countdown unless it is zero.
A936 CALL Read_World_Map Read the world map entry of the room.
A939 LD A,(IX+$0A) Fetch the countdown of Sabreman.
A93C AND A Jump to Handle_Sabreman_Tumbling_Save_Room_Flags if the countdown is zero.
A93D JR Z,Handle_Sabreman_Tumbling_Save_Room_Flags
A93F DEC (IX+$0A) Decrease the countdown of Sabreman.
Handle_Sabreman_Tumbling_Save_Room_Flags A942 LD A,E Store the room flags in Room_Flags.
A943 LD ($AAAC),A
Check for contact with the bubbles and the creatures.
A946 CALL Check_Bubble_Contact Check for contact with the bubbles.
A949 BIT 2,C Jump to Handle_Sabreman_Tumbling_Bubble_Contact if Sabreman touches a bubble (bit 2 of C is set).
A94B JR NZ,Handle_Sabreman_Tumbling_Bubble_Contact
A94D PUSH DE Stash the world map entry on the stack.
A94E CALL Check_Decoration_Contact Check for contact with the creatures.
A951 POP DE Restore the world map entry from the stack.
A952 BIT 2,C Jump to Handle_Sabreman_Tumbling_Combine_Flags if Sabreman touches no creature (bit 2 of C is not set).
A954 JR Z,Handle_Sabreman_Tumbling_Combine_Flags
Handle_Sabreman_Tumbling_Creature_Check_Side A956 BIT 0,C Jump to Handle_Sabreman_Tumbling_Creature_Check_Top if he is touching the middle of it (bit 0 of C is clear).
A958 JR Z,Handle_Sabreman_Tumbling_Creature_Check_Top
A95A BIT 1,C Jump to Handle_Sabreman_Tumbling_Combine_Flags if he is on top of the edge of it (bit 1 of C is set).
A95C JR NZ,Handle_Sabreman_Tumbling_Combine_Flags
Handle_Sabreman_Tumbling_Creature_Bounce A95E BIT 7,C Jump to Handle_Sabreman_Tumbling_Creature_Bounce_Left if he is on the left of it (bit 7 of C is clear).
A960 JR Z,Handle_Sabreman_Tumbling_Creature_Bounce_Left
A962 LD B,$02 Set the new x velocity to 02 (pushed to the right).
A964 JR Handle_Sabreman_Tumbling_Set_Velocity Jump to Handle_Sabreman_Tumbling_Set_Velocity.
Handle_Sabreman_Tumbling_Creature_Bounce_Left A966 LD B,$FE Set the new x velocity to FE (pushed to the left).
A968 JR Handle_Sabreman_Tumbling_Set_Velocity Jump to Handle_Sabreman_Tumbling_Set_Velocity.
Handle_Sabreman_Tumbling_Creature_Check_Top A96A BIT 1,C Jump to Handle_Sabreman_Tumbling_Creature_Bounce and push him away sideways if he is not on top of it (bit 1 of C is clear).
A96C JR Z,Handle_Sabreman_Tumbling_Creature_Bounce
A96E LD A,B Set the y position so that Sabreman stands on top of the creature.
A96F DEC A
A970 NEG
A972 ADD A,$A0
A974 LD (IX+$03),A
A977 JP Land_Sabreman Jump to Land_Sabreman.
Handle_Sabreman_Tumbling_Bubble_Contact A97A LD A,C Copy the bubble contact result to A.
A97B AND %00000011 Keep only bits 0 and 1.
A97D CP $02 Jump to Handle_Sabreman_Tumbling_Creature_Check_Side unless he is on top of the middle of the bubble (the result is 02).
A97F JR NZ,Handle_Sabreman_Tumbling_Creature_Check_Side
A981 LD (IX+$09),$00 Stop him falling by setting the y velocity to 00.
A985 JR Handle_Sabreman_Tumbling_Creature_Check_Top Jump to Handle_Sabreman_Tumbling_Creature_Check_Top.
Handle_Sabreman_Tumbling_Set_Velocity A987 LD A,B Copy the new x velocity to A.
A988 XOR (IX+$06) Combine it with the old x velocity using XOR to find out if the direction has changed.
A98B LD (IX+$06),B Set the new x velocity of Sabreman.
A98E AND %10000000 Keep only bit 7 (set when the direction has changed).
A990 EXX Switch to the shadow registers to keep BC, DE and HL.
A991 CALL NZ,Play_Low_Tone Play a low tone if the direction has changed.
A994 EXX Switch back to the main registers.
Combine the room flags with the contact flags and clear the contact flags. The sprite id is set to 18 plus bits 1 and 2 of the tick counter.
Handle_Sabreman_Tumbling_Combine_Flags A995 LD A,E Combine the contact flags of Sabreman with the contact flags of the room.
A996 OR (IX+$0B)
A999 LD E,A
A99A XOR A Clear the contact flags of Sabreman.
A99B LD (IX+$0B),A
A99E LD A,($8ED6) Fetch the tick counter from GameTimer.
A9A1 RRA Rotate the tick counter right, so that the frame changes every other tick.
A9A2 AND %00000011 Keep only bits 0-1.
A9A4 ADD A,$18 Add 18 to make the sprite id of a tumbling frame.
A9A6 LD (IX+$00),A Set the sprite id of Sabreman.
A9A9 LD A,(IX+$06) Fetch the x velocity of Sabreman.
A9AC AND A Test the x velocity.
Move Sabreman sideways. This is done when the x velocity is not zero or the x position is less than 80.
A9AD LD A,(IX+$01) Fetch the x position of Sabreman.
A9B0 JR NZ,Handle_Sabreman_Tumbling_Move_Sideways Jump to Handle_Sabreman_Tumbling_Move_Sideways if he is moving sideways (the x velocity is not zero).
A9B2 BIT 7,A Jump to Handle_Sabreman_Tumbling_Check_Left_Edge if he is in the left half of the room (bit 7 of the x position is clear).
A9B4 JR Z,Handle_Sabreman_Tumbling_Check_Left_Edge
Handle_Sabreman_Tumbling_Move_Sideways A9B6 ADD A,(IX+$06) Add the x velocity of Sabreman.
A9B9 LD (IX+$01),A Store the new x position of Sabreman.
A9BC BIT 7,A Jump to Handle_Tumbling_At_Right_Edge if he is in the right half of the room (bit 7 of the x position is set).
A9BE JP NZ,Handle_Tumbling_At_Right_Edge
Handle_Sabreman_Tumbling_Check_Left_Edge A9C1 CP $18 Jump to Apply_Tumbling_Gravity if he is clear of the left wall (x position 18 or more).
A9C3 JP NC,Apply_Tumbling_Gravity
A9C6 BIT 6,E Jump to Handle_Sabreman_Tumbling_No_Left_Wall if the left wall is not solid (bit 6 of E is clear).
A9C8 JR Z,Handle_Sabreman_Tumbling_No_Left_Wall
A9CA LD A,(IX+$06) Fetch the x velocity of Sabreman.
A9CD NEG Negate the x velocity, so that he bounces off the wall.
A9CF LD (IX+$06),A Store the new x velocity of Sabreman.
A9D2 LD (IX+$01),$18 Stop him at the left wall by setting the x position to 18.
A9D6 JR Apply_Tumbling_Gravity Jump to Apply_Tumbling_Gravity.
Handle_Sabreman_Tumbling_No_Left_Wall A9D8 EX AF,AF' Mark the ceiling and the floor as solid (bits 0 and 4 of the contact flags of Sabreman), as he is in the gap in the wall, keeping the new x position in AF'.
A9D9 LD A,$11
A9DB OR (IX+$0B)
A9DE LD (IX+$0B),A
A9E1 EX AF,AF'
A9E2 SET 4,E Mark the room as having a floor (bit 4 of E).
A9E4 CP $08 Jump to Apply_Tumbling_Gravity if he has not left the room (x position 08 or more).
A9E6 JR NC,Apply_Tumbling_Gravity
A9E8 DEC (IX+$02) Decrease the room x, to go to the room on the left.
A9EB LD (IX+$01),$E7 Put him at the right edge of the next room (x position E7).
A9EF CALL Draw_Room Draw the new room.
A9F2 JP Update_Object_Sprite Jump to Update_Object_Sprite.
This entry point is used by the routine at Handle_Tumbling_At_Right_Edge.
Apply gravity. The y velocity is increased by 02 each time up to a limit of 76 and the y position is changed by the y velocity divided by 10. A y position of 9F or more sends him to Handle_Sabreman_Falling_Reach_Floor when the room has a floor.
Apply_Tumbling_Gravity A9F5 LD A,(IX+$09) Fetch the y velocity of Sabreman.
A9F8 BIT 7,A Jump to Apply_Tumbling_Gravity_Increase_Velocity if he is moving up (bit 7 of the y velocity is set).
A9FA JR NZ,Apply_Tumbling_Gravity_Increase_Velocity
A9FC CP $76 Jump to Apply_Tumbling_Gravity_Move_Vertically if he is falling at full speed (the y velocity is 76 or more).
A9FE JR NC,Apply_Tumbling_Gravity_Move_Vertically
Apply_Tumbling_Gravity_Increase_Velocity AA00 INC (IX+$09) Increase the y velocity (gravity pulls him down).
AA03 INC (IX+$09) Increase the y velocity again.
Apply_Tumbling_Gravity_Move_Vertically AA06 SRA A Divide the y velocity by sixteen, keeping the sign.
AA08 SRA A
AA0A SRA A
AA0C SRA A
AA0E ADD A,(IX+$03) Add the y position of Sabreman to get the new y position.
AA11 LD (IX+$03),A Store the new y position of Sabreman.
AA14 CP $9F Jump to Handle_Sabreman_Falling_Above_Floor if he has not reached the bottom of the room (the y position is less than 9F).
AA16 JP C,Handle_Sabreman_Falling_Above_Floor
AA19 EX AF,AF' Mark both side walls as solid (bits 2 and 6 of the contact flags of Sabreman), keeping the new y position in AF'.
AA1A LD A,$44
AA1C OR (IX+$0B)
AA1F LD (IX+$0B),A
AA22 EX AF,AF'
AA23 BIT 4,E Jump to Apply_Tumbling_Gravity_Check_Bottom_Edge if the room has no floor (bit 4 of E is clear).
AA25 JR Z,Apply_Tumbling_Gravity_Check_Bottom_Edge
AA27 JP Handle_Sabreman_Falling_Reach_Floor Jump to Handle_Sabreman_Falling_Reach_Floor to land on the floor.
Apply_Tumbling_Gravity_Check_Bottom_Edge AA2A CP $BC Jump to Update_Object_Sprite if he has not reached the bottom of the room (the y position is less than BC).
AA2C JP C,Update_Object_Sprite
AA2F INC (IX+$04) Increase the room y, to go to the room below.
AA32 LD (IX+$03),$2C Put him at the top of the room below (y position 2C).
AA36 CALL Draw_Room Draw the new room.
AA39 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Prev: A8EF Up: Map Next: AA3C