Prev: B57A Up: Map Next: B6D3
B58C: Move Thrown Weapon
Used by the routines at Handle_Fire and Handle_Projectile.
Moves a weapon in flight. The projectiles (see Handle_Projectile) and the fire (see Handle_Fire) are moved by this routine too.
The object is removed if Sabreman is not in its room, or if bit 0 of byte 07 is set, which Check_Weapon_Record_Hit does when the weapon hits a creature. If it touches a decoration (see Check_Decoration_Contact) it bursts into dust (see Burst_Into_Dust) unless it lands on top, when it bounces.
The y velocity increases by four each time, up to 78. The x and y positions are moved by the velocities (multiplied by sixteen, with the fractions in bytes 0A and 0D). The weapon bursts when it hits a wall, bounces off the floor (making a puff of dust) and off the ceiling, and is removed when it leaves the room through a gap. While it is in a gap the contact flags of the weapon and the flags of the room are changed, as for a creature (see Handle_Flying_Creature_Set_Gap_Flags).
Input
IX Object record
Move_Thrown_Weapon B58C LD A,($8F1C) Fetch the room x of Sabreman.
B58F CP (IX+$02) Jump to Remove_Unseen_Weapon if the object is in a different room x.
B592 JP NZ,Remove_Unseen_Weapon
B595 LD A,($8F1E) Fetch the room y of Sabreman.
B598 CP (IX+$04) Jump to Remove_Unseen_Weapon if the object is in a different room y.
B59B JP NZ,Remove_Unseen_Weapon
B59E BIT 0,(IX+$07) Jump to Remove_Thrown_Weapon if the object has been marked for removal.
B5A2 JP NZ,Remove_Thrown_Weapon
B5A5 CALL Check_Decoration_Contact Check for contact with a decoration.
B5A8 BIT 2,C Jump to Move_Thrown_Weapon_Move if the object does not touch one.
B5AA JR Z,Move_Thrown_Weapon_Move
B5AC LD A,C Copy the result to A.
B5AD AND %00000010 Keep only bit 1.
B5AF JP Z,Burst_Into_Dust Jump to Burst_Into_Dust if the object is not on top of the decoration, so that it bursts into dust.
B5B2 LD A,(IX+$09) Fetch the y velocity.
B5B5 CPL Invert it, to bounce.
B5B6 LD (IX+$09),A Store the y velocity.
B5B9 LD A,$A0 Start from the level of the floor (A0).
B5BB SUB B Subtract B to get the y position of the top of the decoration.
B5BC LD (IX+$03),A Store the y position, so that the object is on top.
B5BF CALL Make_Dust_Puff Make a puff of dust.
B5C2 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Move the object. First the y velocity is increased by four, up to a limit of 78.
Move_Thrown_Weapon_Move B5C5 CALL Read_World_Map Read the world map entry of the room that the object is in.
B5C8 LD A,(IX+$0B) Fetch the contact flags.
B5CB OR E Combine them with the flags of the room.
B5CC LD E,A Store the result in E.
B5CD LD (IX+$0B),$00 Clear the contact flags.
B5D1 LD A,(IX+$09) Fetch the y velocity.
B5D4 ADD A,$04 Add four to the y velocity, as gravity pulls the weapon down.
B5D6 BIT 7,A Jump to Move_Thrown_Weapon_Store_Y_Velocity if the y velocity is negative.
B5D8 JR NZ,Move_Thrown_Weapon_Store_Y_Velocity
B5DA CP $78 Jump to Move_Thrown_Weapon_Store_Y_Velocity if the y velocity is less than 78.
B5DC JR C,Move_Thrown_Weapon_Store_Y_Velocity
B5DE LD A,$78 Limit the y velocity to 78.
Move_Thrown_Weapon_Store_Y_Velocity B5E0 LD (IX+$09),A Store the y velocity.
Add the x velocity, multiplied by sixteen, to the x position and its fraction. A is zero or one to say whether the velocity is positive or negative.
B5E3 LD L,(IX+$08) Fetch the x velocity into L.
B5E6 XOR A Set A to zero.
B5E7 BIT 7,L Test the sign of the x velocity.
B5E9 LD H,$00 Clear the high byte of the x velocity (as a word).
B5EB JR Z,Move_Thrown_Weapon_Add_X_Velocity Jump to Move_Thrown_Weapon_Add_X_Velocity if the x velocity is positive.
B5ED INC A Set A to one.
B5EE LD H,$FF Set the high byte of the x velocity to FF to extend the sign.
Move_Thrown_Weapon_Add_X_Velocity B5F0 ADD HL,HL Multiply the x velocity by sixteen.
B5F1 ADD HL,HL
B5F2 ADD HL,HL
B5F3 ADD HL,HL
B5F4 LD C,(IX+$0A) Fetch the fraction of the x position.
B5F7 LD B,(IX+$01) Fetch the x position.
B5FA ADD HL,BC Add the x velocity.
B5FB DEC A Jump to Move_Thrown_Weapon_Check_Wrap if the x velocity is negative.
B5FC JR Z,Move_Thrown_Weapon_Check_Wrap
B5FE CCF Invert the carry flag.
Move_Thrown_Weapon_Check_Wrap B5FF JP NC,Remove_Unseen_Weapon Jump to Remove_Unseen_Weapon if the x position has wrapped round.
B602 LD (IX+$0A),L Store the new fraction of the x position.
B605 LD A,H Fetch the new x position.
B606 BIT 7,A Jump to Move_Thrown_Weapon_Test_Left_Edge if the x position is less than 80.
B608 JP Z,Move_Thrown_Weapon_Test_Left_Edge
B60B CP $D8 Jump to Move_Thrown_Weapon_Store_X if the x position is less than D8.
B60D JR C,Move_Thrown_Weapon_Store_X
B60F BIT 2,E Jump to Move_Thrown_Weapon_Test_Right_Gap if the room has no right wall.
B611 JP Z,Move_Thrown_Weapon_Test_Right_Gap
B614 LD (IX+$01),$D7 Set the x position to D7.
B618 JP Burst_Into_Dust Jump to Burst_Into_Dust, so that the object bursts into dust against the wall.
Move_Thrown_Weapon_Store_X B61B LD (IX+$01),A Store the x position.
Do the same with the y velocity and the y position.
B61E LD L,(IX+$09) Fetch the y velocity into L.
B621 BIT 7,L Test the sign of the y velocity.
B623 LD H,$00 Clear the high byte of the y velocity (as a word).
B625 JR Z,Move_Thrown_Weapon_Add_Y_Velocity Jump to Move_Thrown_Weapon_Add_Y_Velocity if the y velocity is positive.
B627 LD H,$FF Set the high byte of the y velocity to FF to extend the sign.
Move_Thrown_Weapon_Add_Y_Velocity B629 ADD HL,HL Multiply the y velocity by sixteen.
B62A ADD HL,HL
B62B ADD HL,HL
B62C ADD HL,HL
B62D LD C,(IX+$0D) Fetch the fraction of the y position.
B630 LD B,(IX+$03) Fetch the y position.
B633 ADD HL,BC Add the y velocity.
B634 LD (IX+$0D),L Store the new fraction of the y position.
B637 LD A,H Fetch the new y position.
B638 BIT 7,A Jump to Move_Thrown_Weapon_Test_Top_Edge if the y position is less than 80.
B63A JP Z,Move_Thrown_Weapon_Test_Top_Edge
B63D CP $9F Jump to Move_Thrown_Weapon_Store_Y if the y position is less than 9F.
B63F JR C,Move_Thrown_Weapon_Store_Y
B641 BIT 4,E Jump to Move_Thrown_Weapon_Test_Bottom_Gap if the room has no floor.
B643 JP Z,Move_Thrown_Weapon_Test_Bottom_Gap
B646 LD A,(IX+$09) Fetch the y velocity.
B649 CPL Invert it, to bounce off the floor.
B64A LD (IX+$09),A Store the y velocity.
B64D CALL Make_Dust_Puff Make a puff of dust.
B650 LD A,$9F Set the y position to 9F.
Move_Thrown_Weapon_Store_Y B652 LD (IX+$03),A Store the y position.
B655 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Move_Thrown_Weapon_Test_Left_Edge B658 CP $18 Jump to Move_Thrown_Weapon_Store_X if the x position is 18 or more.
B65A JP NC,Move_Thrown_Weapon_Store_X
B65D BIT 6,E Jump to Move_Thrown_Weapon_Test_Left_Gap if the room has no left wall.
B65F JR Z,Move_Thrown_Weapon_Test_Left_Gap
B661 LD (IX+$01),$18 Set the x position to 18.
B665 JP Burst_Into_Dust Jump to Burst_Into_Dust, so that the object bursts into dust against the wall.
Move_Thrown_Weapon_Test_Left_Gap B668 CP $08 Jump to Move_Thrown_Weapon_Set_Gap_Flags if the x position is 08 or more.
B66A JR NC,Move_Thrown_Weapon_Set_Gap_Flags
B66C BIT 0,(IX+$0F) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
B670 JP NZ,Remove_Unseen_Weapon
B673 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Test_Right_Gap B676 CP $F0 Jump to Move_Thrown_Weapon_Set_Gap_Flags if the x position is less than F0.
B678 JR C,Move_Thrown_Weapon_Set_Gap_Flags
B67A BIT 0,(IX+$0F) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
B67E JP NZ,Remove_Unseen_Weapon
B681 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Set_Gap_Flags B684 EX AF,AF' Save the x position in AF'.
B685 LD A,(IX+$0B) Fetch the contact flags.
B688 OR %00010001 Set bits 0 and 4, which makes the ceiling and the floor seem to be present.
B68A LD (IX+$0B),A Store the contact flags.
B68D LD A,E Copy the flags of the room to A.
B68E OR %00010001 Set bits 0 and 4 too.
B690 LD E,A Store them in E.
B691 EX AF,AF' Restore the x position from AF'.
B692 JP Move_Thrown_Weapon_Store_X Jump to Move_Thrown_Weapon_Store_X.
Move_Thrown_Weapon_Test_Top_Edge B695 CP $40 Jump to Move_Thrown_Weapon_Store_Y if the y position is 40 or more.
B697 JR NC,Move_Thrown_Weapon_Store_Y
B699 BIT 0,E Jump to Move_Thrown_Weapon_Test_Top_Gap if the room has no ceiling.
B69B JP Z,Move_Thrown_Weapon_Test_Top_Gap
B69E LD A,(IX+$09) Fetch the y velocity.
B6A1 CPL Invert it, to bounce off the ceiling.
B6A2 LD (IX+$09),A Store the y velocity.
B6A5 LD A,$40 Set the y position to 40.
B6A7 JP Move_Thrown_Weapon_Store_Y Jump to Move_Thrown_Weapon_Store_Y.
Move_Thrown_Weapon_Test_Top_Gap B6AA CP $20 Jump to Move_Thrown_Weapon_Set_Vertical_Gap_Flags if the y position is 20 or more.
B6AC JR NC,Move_Thrown_Weapon_Set_Vertical_Gap_Flags
B6AE BIT 0,(IX+$0F) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
B6B2 JP NZ,Remove_Unseen_Weapon
B6B5 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Test_Bottom_Gap B6B8 CP $BF Jump to Move_Thrown_Weapon_Set_Vertical_Gap_Flags if the y position is less than BF.
B6BA JR C,Move_Thrown_Weapon_Set_Vertical_Gap_Flags
B6BC BIT 0,(IX+$0F) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
B6C0 JP NZ,Remove_Unseen_Weapon
B6C3 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Set_Vertical_Gap_Flags B6C6 EX AF,AF' Save the y position in AF'.
B6C7 LD A,(IX+$0B) Fetch the contact flags.
B6CA OR %01000100 Set bits 2 and 6, which makes the side walls seem to be present.
B6CC LD (IX+$0B),A Store the contact flags.
B6CF EX AF,AF' Restore the y position from AF'.
B6D0 JP Move_Thrown_Weapon_Store_Y Jump to Move_Thrown_Weapon_Store_Y.
Prev: B57A Up: Map Next: B6D3