Prev: 84CD Up: Map Next: 8598
8566: Check Weapon Hit
Checks whether the weapon of the player is touching an entity. The weapon touches an entity if it is in the same room and within 0B pixels of it on both axes. When it touches, the weapon is flagged by setting its byte at offset 02 to 01.
Input
IX The entity to check
Output
E 01 if the weapon touches the entity, otherwise 00
CheckWeaponHit 8566 LD A,($EA99) Fetch the room of the weapon from EA99.
8569 LD E,$00 Set the result in E to 00 (not touching).
856B CP (IX+$01) Compare the room of the weapon with the room of the entity.
856E RET NZ Return if they are in different rooms.
856F LD A,($EA98) Fetch the sprite ID of the weapon from PlayerWeapon.
8572 AND A Return if there is no weapon.
8573 RET Z
8574 LD A,($EA9B) Fetch the X position of the weapon from EA9B.
8577 SUB (IX+$03) Subtract the X position of the entity.
857A JP P,CheckWeaponHit_Test_X Jump to CheckWeaponHit_Test_X if the difference is positive.
857D NEG Make the difference positive.
CheckWeaponHit_Test_X 857F CP $0C Return if the weapon is too far away on the X axis.
8581 RET NC
8582 LD A,($EA9C) Fetch the Y position of the weapon from EA9C.
8585 SUB (IX+$04) Subtract the Y position of the entity.
8588 JP P,CheckWeaponHit_Test_Y Jump to CheckWeaponHit_Test_Y if the difference is positive.
858B NEG Make the difference positive.
CheckWeaponHit_Test_Y 858D CP $0C Return if the weapon is too far away on the Y axis.
858F RET NC
8590 LD A,$01 Flag that the weapon has hit an entity.
8592 LD ($EA9A),A
8595 LD E,$01 Set the result in E to 01 (touching).
8597 RET Return.
Prev: 84CD Up: Map Next: 8598