Prev: 28841 Up: Map Next: 28885
28842: Check whether a policeman can spot Sam
Used by the routine at 29218. Compares the policeman's coordinates with Sam's, and returns with the carry flag set if they are close enough that the policeman has a chance of spotting Sam (if other conditions are favourable).
Input
H 222 or 223 (policeman)
28842 LD L,1 Point HL at byte 1 of the policeman's buffer
28844 LD A,(58881) A=Sam's x-coordinate
28847 SUB (HL) Subtract the policeman's x-coordinate
28848 DEC HL Point HL at byte 0 of the policeman's buffer
28849 JR NC,28859 Jump if the policeman's x-coordinate is less than or equal to Sam's
28851 NEG A=horizontal distance between Sam and the policeman
28853 BIT 7,(HL) Is the policeman facing left (and thus facing Sam)?
28855 JR Z,28866 Jump if so
28857 JR 28863
28859 BIT 7,(HL) Is the policeman facing right (and thus facing Sam)?
28861 JR NZ,28866 Jump if so
28863 CP 3 Is the policeman (who is not facing Sam) at least 3 x-coordinates away from Sam?
28865 RET NC Return with the carry flag reset if so
28866 CP 16 Is the policeman at least 16 x-coordinates away from Sam?
28868 RET NC Return with the carry flag reset if so
At this point, the policeman is either facing Sam and located less than 16 x-coordinates away from him, or facing away from Sam and located less than 3 x-coordinates away from him. Now we check the vertical distance between the two characters.
28869 LD E,A E=horizontal distance between Sam and the policeman
28870 LD L,2 Point HL at byte 2 of the policeman's buffer
28872 LD A,(58882) A=Sam's y-coordinate
28875 SUB (HL) Subtract the policeman's y-coordinate
28876 JR NC,28880 Jump if the policeman's y-coordinate is less than or equal to Sam's
28878 NEG
28880 LD D,A D=vertical distance between Sam and the policeman
28881 ADD A,E Add the horizontal distance between Sam and the policeman
28882 CP 33 Set the carry flag if the result is less than 33
28884 RET
Prev: 28841 Up: Map Next: 28885