Prev: A406 Up: Map Next: A5F1
A433: Handle Sabreman Walking
Handler for the object types 09 to 10 which are the walking sprites of Sabreman (09 to 0C when he walks to the left and 0D to 10 when he walks to the right). It is also the state that he is in when he is standing still.
Each time it saves the object state, handles being carried off (bit 6 of the redraw flags), tumbling (bit 7) and the special state at Tumble_Sabreman (bit 3), checks for contact with the bubbles, the stalactite and the creatures, reads the controls, moves him sideways, and finally keeps him inside the room, moving him to the next room when he walks off the edge.
Input
IX Object record of Sabreman
Clear the countdown and the contact flags. In the top part of the room (y position less than 48) the contact flags are set to 44 which marks both side walls as solid.
Handle_Sabreman_Walking A433 CALL StoreEntity Remember the position and sprite id of Sabreman (see StoreEntity).
A436 LD A,(IX+$0F) Fetch the redraw flags of Sabreman.
A439 AND %01000000 Keep only bit 6 (being carried).
A43B JP NZ,Start_Being_Carried Jump to Start_Being_Carried if Sabreman is being carried by an eagle (bit 6 of the redraw flags is set).
A43E LD (IX+$0A),$00 Clear the countdown of Sabreman.
A442 LD (IX+$0B),$00 Clear the contact flags of Sabreman.
A446 LD A,(IX+$03) Fetch the y position of Sabreman.
A449 CP $48 Jump to Handle_Sabreman_Walking_Check_Special_States if Sabreman is in the lower part of the room (y position 48 or more).
A44B JR NC,Handle_Sabreman_Walking_Check_Special_States
A44D LD (IX+$0B),$44 Mark the walls on both sides as solid by setting the contact flags to 44 as he is in the upper part of the room.
Check the special states.
Handle_Sabreman_Walking_Check_Special_States A451 BIT 7,(IX+$0F) Jump to Start_Tumbling if bit 7 of the redraw flags is set (Sabreman starts to tumble).
A455 JR NZ,Start_Tumbling
A457 BIT 3,(IX+$0F) Jump to Tumble_Sabreman if bit 3 of the redraw flags is set.
A45B JP NZ,Tumble_Sabreman
Check for contact with the bubbles, the stalactite and the creatures. The result of the bubble contact check is kept in byte 0E of the record of Sabreman.
A45E CALL Read_World_Map Read the world map entry of the room (the room flags are returned in E).
A461 CALL Check_Bubble_Contact Check for contact with the bubbles.
A464 LD (IX+$0E),C Store the bubble contact result in byte 0E of the record of Sabreman.
A467 CALL Check_Stalactite_Contact Check for contact with the falling stalactite.
A46A BIT 2,C Jump to Handle_Sabreman_Walking_Check_Creatures if the stalactite does not touch him (bit 2 of C is clear).
A46C JR Z,Handle_Sabreman_Walking_Check_Creatures
A46E BIT 2,(IX+$0E) Jump to Knock_Sabreman_Down to knock Sabreman down if the stalactite hit him while he was touching a bubble.
A472 JP NZ,Knock_Sabreman_Down
A475 JP Handle_Stalactite_Hit Jump to Handle_Stalactite_Hit to handle the stalactite hit.
Handle_Sabreman_Walking_Check_Creatures A478 BIT 2,(IX+$0E) Jump to Handle_Sabreman_Walking_Read_Controls if he is touching a bubble, as the creatures are only checked when he is not.
A47C JR NZ,Handle_Sabreman_Walking_Read_Controls
A47E CALL Check_Decoration_Contact Check for contact with the creatures.
A481 LD A,C Copy the creature contact result to A.
A482 AND %01111111 Keep only bits 0 to 6 (ignore which side the creature is on).
A484 CP $04 Jump to Start_Tumbling_Downwards to start tumbling downwards if a creature is touching him from the side (the contact result is 04).
A486 JP Z,Start_Tumbling_Downwards
A489 LD (IX+$0E),C Store the creature contact result in byte 0E of the record of Sabreman.
Read the controls. A clear fire bit throws a weapon, and a set fire bit sets the flag for the released fire key. Then bit 3 of the controls (clear) starts a jump, bit 0 (clear) moves him to the right and bit 1 (clear) moves him to the left.
Handle_Sabreman_Walking_Read_Controls A48C CALL ReadControls Read the controls.
A48F BIT 4,A Jump to Handle_Sabreman_Walking_Fire_Released if bit 4 of the controls is set (the fire key is not pressed).
A491 JR NZ,Handle_Sabreman_Walking_Fire_Released
A493 EX AF,AF' Keep the controls in AF' while the weapon is thrown.
A494 CALL Throw_Weapon Throw a weapon (see Throw_Weapon).
A497 JR Handle_Sabreman_Walking_Check_Movement Jump to Handle_Sabreman_Walking_Check_Movement.
Handle_Sabreman_Walking_Fire_Released A499 EX AF,AF' Keep the controls in AF'.
A49A LD A,$FF Set the flag for the released fire key (Fire_Key_Flag) to FF.
A49C LD ($AAAB),A
Handle_Sabreman_Walking_Check_Movement A49F EX AF,AF' Fetch the controls again from AF'.
A4A0 BIT 3,A Jump to Handle_Sabreman_Walking_Jump to start a jump if the up control is used (bit 3 of the controls is clear).
A4A2 JP Z,Handle_Sabreman_Walking_Jump
A4A5 BIT 0,A Jump to Handle_Sabreman_Walking_Right to walk to the right if the right control is used (bit 0 of the controls is clear).
A4A7 JP Z,Handle_Sabreman_Walking_Right
A4AA BIT 1,A Jump to Handle_Sabreman_Walking_Left to walk to the left if the left control is used (bit 1 of the controls is clear).
A4AC JP Z,Handle_Sabreman_Walking_Left
A4AF LD (IX+$06),$00 Set the x velocity to 00 as he is standing still.
Move Sabreman sideways by the x velocity, unless the contact bits of the bubble or creature that he touches (bits 0 to 2) are all set, in which case the routine goes to Handle_Sabreman_Walking_Jump_Straight_Up, which starts a jump with a y velocity of zero.
Handle_Sabreman_Walking_Move_Sideways A4B3 LD A,(IX+$0E) Fetch the bubble or creature contact result of Sabreman (byte 0E).
A4B6 AND %00000111 Keep only bits 0 to 2 (touching, on top and at the edge).
A4B8 CP $07 Jump to Handle_Sabreman_Walking_Jump_Straight_Up if all three are set (he is standing on the edge of a bubble or a creature).
A4BA JP Z,Handle_Sabreman_Walking_Jump_Straight_Up
A4BD LD A,(IX+$01) Fetch the x position of Sabreman.
A4C0 ADD A,(IX+$06) Add the x velocity of Sabreman.
A4C3 LD (IX+$01),A Store the new x position of Sabreman.
A4C6 CALL Read_World_Map Read the world map entry of the room.
A4C9 LD A,E Copy the room flags to A.
A4CA LD ($AAAC),A Store the room flags in Room_Flags.
A4CD OR (IX+$0B) Combine the room flags with the contact flags of Sabreman.
A4D0 LD E,A Keep the combined flags in E.
A4D1 LD A,(IX+$01) Fetch the x position of Sabreman.
A4D4 CP $10 Jump to Handle_Sabreman_Walking_On_Ground if Sabreman is at the left edge of the room (x position less than 10).
A4D6 JR C,Handle_Sabreman_Walking_On_Ground
A4D8 CP $E8 Jump to Handle_Sabreman_Walking_On_Ground if Sabreman is at the right edge of the room (x position E8 or more).
A4DA JR NC,Handle_Sabreman_Walking_On_Ground
A4DC EX AF,AF' Keep the controls in AF' while the room redrawn flag is fetched.
A4DD LD A,($8EF0) Fetch the room redrawn flag from Room_Redrawn_Flag.
A4E0 LD D,A Copy the flag to D.
A4E1 EX AF,AF' Fetch the controls again from AF'.
A4E2 BIT 0,D Jump to Handle_Sabreman_Walking_On_Ground if the room has just been drawn (bit 0 of the flag is set).
A4E4 JR NZ,Handle_Sabreman_Walking_On_Ground
A4E6 BIT 4,E Jump to Handle_Sabreman_Walking_No_Floor if there is no floor under him (bit 4 of E is clear), as he walks off the ledge.
A4E8 JP Z,Handle_Sabreman_Walking_No_Floor
Sabreman is on the ground, so the y velocity is cleared. Then the x position is kept inside the room. Bit 2 of the sprite id less one tells which way he is facing (set for the right).
Handle_Sabreman_Walking_On_Ground A4EB LD (IX+$09),$00 Set the y velocity to 00 as he is standing on the floor.
A4EF LD B,(IX+$00) Fetch the sprite id of Sabreman.
A4F2 DEC B Decrease it so that bit 2 tells which way he is facing.
A4F3 BIT 2,B Jump to Handle_Sabreman_Walking_Facing_Right if he is facing right (bit 2 is set).
A4F5 JR NZ,Handle_Sabreman_Walking_Facing_Right
A4F7 BIT 7,(IX+$01) Jump to Update_Object_Sprite if he is in the right half of the room (bit 7 of the x position is set), as he is far from the left wall.
A4FB JP NZ,Update_Object_Sprite
A4FE CP $18 Jump to Update_Object_Sprite if he has not reached the left wall (x position 18 or more).
A500 JP NC,Update_Object_Sprite
A503 BIT 6,E Jump to Handle_Sabreman_Walking_Left_Room_Edge if the left wall is not solid (bit 6 of E is clear).
A505 JR Z,Handle_Sabreman_Walking_Left_Room_Edge
A507 LD (IX+$01),$18 Stop him at the left wall by setting the x position to 18.
A50B JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Sabreman_Walking_Left_Room_Edge A50E CP $08 Jump to Update_Object_Sprite if he has not left the room (x position 08 or more).
A510 JP NC,Update_Object_Sprite
A513 LD (IX+$01),$F0 Put him at the right edge of the next room (x position F0).
A517 DEC (IX+$02) Decrease the room x, to go to the room on the left.
A51A CALL Draw_Room Draw the new room.
A51D JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Sabreman_Walking_Facing_Right A520 BIT 7,(IX+$01) Jump to Update_Object_Sprite if he is in the left half of the room (bit 7 of the x position is clear), as he is far from the right wall.
A524 JP Z,Update_Object_Sprite
A527 CP $D8 Jump to Update_Object_Sprite if he has not reached the right wall (x position less than D8).
A529 JP C,Update_Object_Sprite
A52C BIT 2,E Jump to Handle_Sabreman_Walking_Right_Room_Edge if the right wall is not solid (bit 2 of E is clear).
A52E JP Z,Handle_Sabreman_Walking_Right_Room_Edge
A531 LD (IX+$01),$D8 Stop him at the right wall by setting the x position to D8.
A535 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Sabreman_Walking_Right_Room_Edge A538 CP $F1 Jump to Update_Object_Sprite if he has not left the room (x position less than F1).
A53A JP C,Update_Object_Sprite
A53D LD (IX+$01),$08 Put him at the left edge of the next room (x position 08).
A541 INC (IX+$02) Increase the room x, to go to the room on the right.
A544 CALL Draw_Room Draw the new room.
A547 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Walk to the right. If the contact bits of the bubble or creature that he touches (bits 1, 2 and 7) are exactly 04 he is blocked and stands still. Otherwise the x velocity is 02 and the sprite id is 0D plus bits 1 and 2 of the animation counter.
Handle_Sabreman_Walking_Right A54A LD A,(IX+$0E) Fetch the bubble or creature contact result of Sabreman (byte 0E).
A54D AND %10000110 Keep only bits 1, 2 and 7 (on top, touching and the side).
A54F CP $04 Jump to Handle_Sabreman_Walking_Right_Free if he is not blocked on the right (the result is not 04).
A551 JR NZ,Handle_Sabreman_Walking_Right_Free
A553 LD (IX+$06),$00 Set the x velocity to 00 as he is blocked.
A557 JP Handle_Sabreman_Walking_Move_Sideways Jump to Handle_Sabreman_Walking_Move_Sideways.
Handle_Sabreman_Walking_Right_Free A55A LD (IX+$06),$02 Set the x velocity to 02 (walking right).
A55E INC (IX+$08) Increase the animation counter of Sabreman.
A561 LD A,(IX+$08) Fetch the animation counter.
A564 RRA Halve the animation counter so that the frame changes every other pass.
A565 AND %00000011 Keep only the two low bits (one of four frames).
A567 ADD A,$0D Add 0D to make the sprite id (the frames for walking right).
A569 LD (IX+$00),A Set the sprite id.
A56C JR Handle_Sabreman_Walking_Play_Tone Jump to Handle_Sabreman_Walking_Play_Tone to play the footstep sound.
Walk to the left. If the contact bits of the bubble or creature that he touches (bits 1, 2 and 7) are exactly 84 he is blocked and stands still. Otherwise the x velocity is FE and the sprite id is 09 plus bits 1 and 2 of the animation counter.
Handle_Sabreman_Walking_Left A56E LD A,(IX+$0E) Fetch the bubble or creature contact result of Sabreman (byte 0E).
A571 AND %10000110 Keep only bits 1, 2 and 7 (on top, touching and the side).
A573 CP $84 Jump to Handle_Sabreman_Walking_Left_Free if he is not blocked on the left (the result is not 84).
A575 JR NZ,Handle_Sabreman_Walking_Left_Free
A577 LD (IX+$06),$00 Set the x velocity to 00 as he is blocked.
A57B JP Handle_Sabreman_Walking_Move_Sideways Jump to Handle_Sabreman_Walking_Move_Sideways.
Handle_Sabreman_Walking_Left_Free A57E LD (IX+$06),$FE Set the x velocity to FE (walking left).
A582 INC (IX+$08) Increase the animation counter of Sabreman.
A585 LD A,(IX+$08) Fetch the animation counter.
A588 RRA Halve the animation counter so that the frame changes every other pass.
A589 AND %00000011 Keep only the two low bits (one of four frames).
A58B ADD A,$09 Add 09 to make the sprite id (the frames for walking left).
A58D LD (IX+$00),A Set the sprite id.
Handle_Sabreman_Walking_Play_Tone A590 CALL Play_Alternating_Tone Play the footstep sound (see Play_Alternating_Tone).
A593 JP Handle_Sabreman_Walking_Move_Sideways Jump to Handle_Sabreman_Walking_Move_Sideways.
Jump. The y velocity is set to D0 the countdown to 08 and the sprite id becomes 11 (facing left) or 13 (facing right), according to the direction of the x velocity or, when he is not moving sideways, to the way that he faced.
Handle_Sabreman_Walking_Jump A596 LD (IX+$09),$D0 Set the y velocity to D0 (up) to start the jump.
Handle_Sabreman_Walking_Jump_Set_Countdown A59A LD (IX+$0A),$08 Set the jump countdown to 08.
A59E LD A,(IX+$00) Fetch the sprite id of Sabreman.
A5A1 DEC A Decrease it so that bit 2 tells which way he is facing.
A5A2 AND %00000100 Keep only bit 2 (set when he faces right).
A5A4 SRL A Shift it right to make 00 (left) or 02 (right).
A5A6 ADD A,$11 Add 11 to make the jumping sprite id.
A5A8 LD (IX+$00),A Set the sprite id.
A5AB LD A,(IX+$06) Fetch the x velocity of Sabreman.
A5AE AND A Jump to Update_Object_Sprite if he is not moving sideways.
A5AF JP Z,Update_Object_Sprite
A5B2 JP M,Handle_Sabreman_Walking_Jump_Left Jump to Handle_Sabreman_Walking_Jump_Left if he is moving to the left.
A5B5 LD (IX+$00),$13 Set the sprite id to 13 (jumping right).
A5B9 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Sabreman_Walking_Jump_Left A5BC LD (IX+$00),$11 Set the sprite id to 11 (jumping left).
A5C0 JP Update_Object_Sprite Jump to Update_Object_Sprite.
The room has no floor at this position. Sabreman jumps with a y velocity of C0 and an x velocity of 02 (when his x position is below 80) or FE.
Handle_Sabreman_Walking_No_Floor A5C3 LD (IX+$09),$C0 Set the y velocity to C0 (up), as he steps off the ledge.
A5C7 BIT 7,(IX+$01) Jump to Handle_Sabreman_Walking_No_Floor_Left if bit 7 of the x position is set.
A5CB JR NZ,Handle_Sabreman_Walking_No_Floor_Left
A5CD LD (IX+$06),$02 Set the x velocity to 02.
A5D1 LD (IX+$0A),$08 Set the countdown to 08.
A5D5 LD (IX+$00),$13 Set the sprite id to 13 (jumping right).
A5D9 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Sabreman_Walking_No_Floor_Left A5DC LD (IX+$06),$FE Set the x velocity to FE.
A5E0 LD (IX+$0A),$08 Set the countdown to 08.
A5E4 LD (IX+$00),$11 Set the sprite id to 11 (jumping left).
A5E8 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Handle_Sabreman_Walking_Jump_Straight_Up A5EB LD (IX+$09),$00 Set the y velocity to 00 so that the jump has no height.
A5EF JR Handle_Sabreman_Walking_Jump_Set_Countdown Jump to Handle_Sabreman_Walking_Jump_Set_Countdown.
Prev: A406 Up: Map Next: A5F1