Prev: 8598 Up: Map Next: 85EA
85B2: Check Player Touch
Checks whether an entity is touching the player. The player is touching an entity if the player is a character sprite (a sprite ID of 01 to 30), is in the same room and is within 0B pixels of it on both axes. When it touches, the byte at offset 02 of the player is set to 01 and the sound of touching is made.
Input
IX The entity to check
Output
E 01 if the player touches the entity, otherwise 00
CheckPlayerTouch 85B2 LD A,($EA91) Fetch the room of the player from PlayerRoom.
85B5 LD E,$00 Set the result in E to 00 (not touching).
85B7 CP (IX+$01) Compare the room of the player with the room of the entity.
85BA RET NZ Return if they are in different rooms.
85BB LD A,($EA90) Fetch the sprite ID of the player from Player.
85BE AND A Test whether the player is in play.
85BF RET Z Return if not.
85C0 CP $31 Return if the player is not a character sprite.
85C2 RET NC
85C3 LD A,($EA93) Fetch the X position of the player from EA93.
85C6 SUB (IX+$03) Subtract the X position of the entity.
85C9 JP P,CheckPlayerTouch_Test_X Jump to CheckPlayerTouch_Test_X if the difference is positive.
85CC NEG Make the difference positive.
CheckPlayerTouch_Test_X 85CE CP $0C Return if the player is too far away on the X axis.
85D0 RET NC
85D1 LD A,($EA94) Fetch the Y position of the player from EA94.
85D4 SUB (IX+$04) Subtract the Y position of the entity.
85D7 JP P,CheckPlayerTouch_Test_Y Jump to CheckPlayerTouch_Test_Y if the difference is positive.
85DA NEG Make the difference positive.
CheckPlayerTouch_Test_Y 85DC CP $0C Return if the player is too far away on the Y axis.
85DE RET NC
85DF LD A,$01 Flag that the player has been touched.
85E1 LD ($EA92),A
85E4 CALL SoundsTouching Call SoundsTouching to make the sound of touching.
85E7 LD E,$01 Set the result in E to 01 (touching).
85E9 RET Return.
Prev: 8598 Up: Map Next: 85EA