Prev: 46824 Up: Map Next: 46892
46836: Check Weapon Record Hit
Used by the routine at Check_Weapon_Hit.
Checks whether a weapon is touching an object. The weapon hits the object if it is in the same room, less than 16 pixels away horizontally and less than 16 pixels away vertically (allowing 4 pixels for the difference in their sizes). When it hits, bit 0 of byte 7 of the weapon is set, which makes Move_Thrown_Weapon remove the weapon.
Input
HL Weapon record
IX Object record
Output
D 255 if the weapon hits the object, otherwise 0
E Type of the weapon
Check_Weapon_Record_Hit 46836 LD D,0 Clear the hit flag in D.
46838 LD A,(HL) Fetch the type of the weapon.
46839 AND A Copy it to E, testing it for zero.
46840 LD E,A
46841 RET Z Return if the record is empty.
46842 INC HL Move to the x position of the weapon.
46843 LD A,(HL) Fetch the x position of the weapon.
46844 SUB (IX+1) Subtract the x position of the object.
46847 ADD A,4 Add 4.
46849 JP P,Check_Weapon_Record_Hit_Test_X Jump to Check_Weapon_Record_Hit_Test_X if the result is positive.
46852 NEG Make the result positive.
Check_Weapon_Record_Hit_Test_X 46854 CP 16 Return if they are 16 or more pixels apart horizontally.
46856 RET NC
46857 INC HL Move to the room x of the weapon.
46858 LD A,(HL) Fetch the room x of the weapon.
46859 CP (IX+2) Return if it is not the room x of the object.
46862 RET NZ
46863 INC HL Move to the y position of the weapon.
46864 LD A,(HL) Fetch the y position of the weapon.
46865 SUB (IX+3) Subtract the y position of the object.
46868 ADD A,4 Add 4.
46870 JP P,Check_Weapon_Record_Hit_Test_Y Jump to Check_Weapon_Record_Hit_Test_Y if the result is positive.
46873 NEG Make the result positive.
Check_Weapon_Record_Hit_Test_Y 46875 CP 16 Return if they are 16 or more pixels apart vertically.
46877 RET NC
46878 INC HL Move to the room y of the weapon.
46879 LD A,(HL) Fetch the room y of the weapon.
46880 CP (IX+4) Return if it is not the room y of the object.
46883 RET NZ
46884 LD D,255 Flag a hit by setting D to 255.
46886 INC HL Move to byte 7.
46887 INC HL
46888 INC HL
46889 LD (HL),1 Set bit 0 of byte 7 so that the weapon will be removed.
46891 RET Return.
Prev: 46824 Up: Map Next: 46892