Prev: 46458 Up: Map Next: 46803
46476: 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 7 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 120. The x and y positions are moved by the velocities (multiplied by sixteen, with the fractions in bytes 10 and 13). 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 46476 LD A,(36636) Fetch the room x of Sabreman.
46479 CP (IX+2) Jump to Remove_Unseen_Weapon if the object is in a different room x.
46482 JP NZ,Remove_Unseen_Weapon
46485 LD A,(36638) Fetch the room y of Sabreman.
46488 CP (IX+4) Jump to Remove_Unseen_Weapon if the object is in a different room y.
46491 JP NZ,Remove_Unseen_Weapon
46494 BIT 0,(IX+7) Jump to Remove_Thrown_Weapon if the object has been marked for removal.
46498 JP NZ,Remove_Thrown_Weapon
46501 CALL Check_Decoration_Contact Check for contact with a decoration.
46504 BIT 2,C Jump to Move_Thrown_Weapon_Move if the object does not touch one.
46506 JR Z,Move_Thrown_Weapon_Move
46508 LD A,C Copy the result to A.
46509 AND %00000010 Keep only bit 1.
46511 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.
46514 LD A,(IX+9) Fetch the y velocity.
46517 CPL Invert it, to bounce.
46518 LD (IX+9),A Store the y velocity.
46521 LD A,160 Start from the level of the floor (160).
46523 SUB B Subtract B to get the y position of the top of the decoration.
46524 LD (IX+3),A Store the y position, so that the object is on top.
46527 CALL Make_Dust_Puff Make a puff of dust.
46530 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 120.
Move_Thrown_Weapon_Move 46533 CALL Read_World_Map Read the world map entry of the room that the object is in.
46536 LD A,(IX+11) Fetch the contact flags.
46539 OR E Combine them with the flags of the room.
46540 LD E,A Store the result in E.
46541 LD (IX+11),0 Clear the contact flags.
46545 LD A,(IX+9) Fetch the y velocity.
46548 ADD A,4 Add four to the y velocity, as gravity pulls the weapon down.
46550 BIT 7,A Jump to Move_Thrown_Weapon_Store_Y_Velocity if the y velocity is negative.
46552 JR NZ,Move_Thrown_Weapon_Store_Y_Velocity
46554 CP 120 Jump to Move_Thrown_Weapon_Store_Y_Velocity if the y velocity is less than 120.
46556 JR C,Move_Thrown_Weapon_Store_Y_Velocity
46558 LD A,120 Limit the y velocity to 120.
Move_Thrown_Weapon_Store_Y_Velocity 46560 LD (IX+9),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.
46563 LD L,(IX+8) Fetch the x velocity into L.
46566 XOR A Set A to zero.
46567 BIT 7,L Test the sign of the x velocity.
46569 LD H,0 Clear the high byte of the x velocity (as a word).
46571 JR Z,Move_Thrown_Weapon_Add_X_Velocity Jump to Move_Thrown_Weapon_Add_X_Velocity if the x velocity is positive.
46573 INC A Set A to one.
46574 LD H,255 Set the high byte of the x velocity to 255 to extend the sign.
Move_Thrown_Weapon_Add_X_Velocity 46576 ADD HL,HL Multiply the x velocity by sixteen.
46577 ADD HL,HL
46578 ADD HL,HL
46579 ADD HL,HL
46580 LD C,(IX+10) Fetch the fraction of the x position.
46583 LD B,(IX+1) Fetch the x position.
46586 ADD HL,BC Add the x velocity.
46587 DEC A Jump to Move_Thrown_Weapon_Check_Wrap if the x velocity is negative.
46588 JR Z,Move_Thrown_Weapon_Check_Wrap
46590 CCF Invert the carry flag.
Move_Thrown_Weapon_Check_Wrap 46591 JP NC,Remove_Unseen_Weapon Jump to Remove_Unseen_Weapon if the x position has wrapped round.
46594 LD (IX+10),L Store the new fraction of the x position.
46597 LD A,H Fetch the new x position.
46598 BIT 7,A Jump to Move_Thrown_Weapon_Test_Left_Edge if the x position is less than 128.
46600 JP Z,Move_Thrown_Weapon_Test_Left_Edge
46603 CP 216 Jump to Move_Thrown_Weapon_Store_X if the x position is less than 216.
46605 JR C,Move_Thrown_Weapon_Store_X
46607 BIT 2,E Jump to Move_Thrown_Weapon_Test_Right_Gap if the room has no right wall.
46609 JP Z,Move_Thrown_Weapon_Test_Right_Gap
46612 LD (IX+1),215 Set the x position to 215.
46616 JP Burst_Into_Dust Jump to Burst_Into_Dust, so that the object bursts into dust against the wall.
Move_Thrown_Weapon_Store_X 46619 LD (IX+1),A Store the x position.
Do the same with the y velocity and the y position.
46622 LD L,(IX+9) Fetch the y velocity into L.
46625 BIT 7,L Test the sign of the y velocity.
46627 LD H,0 Clear the high byte of the y velocity (as a word).
46629 JR Z,Move_Thrown_Weapon_Add_Y_Velocity Jump to Move_Thrown_Weapon_Add_Y_Velocity if the y velocity is positive.
46631 LD H,255 Set the high byte of the y velocity to 255 to extend the sign.
Move_Thrown_Weapon_Add_Y_Velocity 46633 ADD HL,HL Multiply the y velocity by sixteen.
46634 ADD HL,HL
46635 ADD HL,HL
46636 ADD HL,HL
46637 LD C,(IX+13) Fetch the fraction of the y position.
46640 LD B,(IX+3) Fetch the y position.
46643 ADD HL,BC Add the y velocity.
46644 LD (IX+13),L Store the new fraction of the y position.
46647 LD A,H Fetch the new y position.
46648 BIT 7,A Jump to Move_Thrown_Weapon_Test_Top_Edge if the y position is less than 128.
46650 JP Z,Move_Thrown_Weapon_Test_Top_Edge
46653 CP 159 Jump to Move_Thrown_Weapon_Store_Y if the y position is less than 159.
46655 JR C,Move_Thrown_Weapon_Store_Y
46657 BIT 4,E Jump to Move_Thrown_Weapon_Test_Bottom_Gap if the room has no floor.
46659 JP Z,Move_Thrown_Weapon_Test_Bottom_Gap
46662 LD A,(IX+9) Fetch the y velocity.
46665 CPL Invert it, to bounce off the floor.
46666 LD (IX+9),A Store the y velocity.
46669 CALL Make_Dust_Puff Make a puff of dust.
46672 LD A,159 Set the y position to 159.
Move_Thrown_Weapon_Store_Y 46674 LD (IX+3),A Store the y position.
46677 JP Update_Object_Sprite Jump to Update_Object_Sprite.
Move_Thrown_Weapon_Test_Left_Edge 46680 CP 24 Jump to Move_Thrown_Weapon_Store_X if the x position is 24 or more.
46682 JP NC,Move_Thrown_Weapon_Store_X
46685 BIT 6,E Jump to Move_Thrown_Weapon_Test_Left_Gap if the room has no left wall.
46687 JR Z,Move_Thrown_Weapon_Test_Left_Gap
46689 LD (IX+1),24 Set the x position to 24.
46693 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 46696 CP 8 Jump to Move_Thrown_Weapon_Set_Gap_Flags if the x position is 8 or more.
46698 JR NC,Move_Thrown_Weapon_Set_Gap_Flags
46700 BIT 0,(IX+15) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
46704 JP NZ,Remove_Unseen_Weapon
46707 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Test_Right_Gap 46710 CP 240 Jump to Move_Thrown_Weapon_Set_Gap_Flags if the x position is less than 240.
46712 JR C,Move_Thrown_Weapon_Set_Gap_Flags
46714 BIT 0,(IX+15) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
46718 JP NZ,Remove_Unseen_Weapon
46721 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Set_Gap_Flags 46724 EX AF,AF' Save the x position in AF'.
46725 LD A,(IX+11) Fetch the contact flags.
46728 OR %00010001 Set bits 0 and 4, which makes the ceiling and the floor seem to be present.
46730 LD (IX+11),A Store the contact flags.
46733 LD A,E Copy the flags of the room to A.
46734 OR %00010001 Set bits 0 and 4 too.
46736 LD E,A Store them in E.
46737 EX AF,AF' Restore the x position from AF'.
46738 JP Move_Thrown_Weapon_Store_X Jump to Move_Thrown_Weapon_Store_X.
Move_Thrown_Weapon_Test_Top_Edge 46741 CP 64 Jump to Move_Thrown_Weapon_Store_Y if the y position is 64 or more.
46743 JR NC,Move_Thrown_Weapon_Store_Y
46745 BIT 0,E Jump to Move_Thrown_Weapon_Test_Top_Gap if the room has no ceiling.
46747 JP Z,Move_Thrown_Weapon_Test_Top_Gap
46750 LD A,(IX+9) Fetch the y velocity.
46753 CPL Invert it, to bounce off the ceiling.
46754 LD (IX+9),A Store the y velocity.
46757 LD A,64 Set the y position to 64.
46759 JP Move_Thrown_Weapon_Store_Y Jump to Move_Thrown_Weapon_Store_Y.
Move_Thrown_Weapon_Test_Top_Gap 46762 CP 32 Jump to Move_Thrown_Weapon_Set_Vertical_Gap_Flags if the y position is 32 or more.
46764 JR NC,Move_Thrown_Weapon_Set_Vertical_Gap_Flags
46766 BIT 0,(IX+15) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
46770 JP NZ,Remove_Unseen_Weapon
46773 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Test_Bottom_Gap 46776 CP 191 Jump to Move_Thrown_Weapon_Set_Vertical_Gap_Flags if the y position is less than 191.
46778 JR C,Move_Thrown_Weapon_Set_Vertical_Gap_Flags
46780 BIT 0,(IX+15) Jump to Remove_Unseen_Weapon if the object has not been drawn yet, to remove it.
46784 JP NZ,Remove_Unseen_Weapon
46787 JP Remove_Thrown_Weapon Remove the object and erase it.
Move_Thrown_Weapon_Set_Vertical_Gap_Flags 46790 EX AF,AF' Save the y position in AF'.
46791 LD A,(IX+11) Fetch the contact flags.
46794 OR %01000100 Set bits 2 and 6, which makes the side walls seem to be present.
46796 LD (IX+11),A Store the contact flags.
46799 EX AF,AF' Restore the y position from AF'.
46800 JP Move_Thrown_Weapon_Store_Y Jump to Move_Thrown_Weapon_Store_Y.
Prev: 46458 Up: Map Next: 46803