Prev: 26861 Up: Map Next: 26987
26895: Find Bug Target
Used by the routine at UpdateMidges.
Finds the object that the midges are chasing. This is Robbie, unless he is too close to either edge of the play area or the flower is nearer. The distances are measured as the sum of the horizontal and vertical distances at half resolution.
Input
IX Midges object
Output
HL Address of the X position of the target (Robbie or the flower)
FindBugTarget 26895 LD A,(24173) A=the X position of Robbie.
26898 CP 24 Jump to FindBugTarget_Flower to use the flower if Robbie is too far to the left.
26900 JR C,FindBugTarget_Flower
26902 CP 216 Jump to FindBugTarget_Flower to use the flower if Robbie is too far to the right.
26904 JR NC,FindBugTarget_Flower
Distance from the midges to Robbie.
26906 SRL A B=the X position of Robbie / 2.
26908 LD B,A
26909 LD A,(IX+1) A=the X position of the midges / 2.
26912 SRL A
26914 SUB B Subtract the X position of Robbie.
26915 JP P,FindBugTarget_Robbie_X Make sure we have a positive byte.
26918 NEG
FindBugTarget_Robbie_X 26920 LD B,A B=the horizontal distance.
26921 LD A,(24174) A=the Y position of Robbie.
26924 SRL A C=the Y position of Robbie / 2.
26926 LD C,A
26927 LD A,(IX+2) A=the Y position of the midges / 2.
26930 SRL A
26932 SUB C Subtract the Y position of Robbie.
26933 JP P,FindBugTarget_Robbie_Y Make sure we have a positive byte.
26936 NEG
FindBugTarget_Robbie_Y 26938 ADD A,B Add the horizontal distance to get the distance to Robbie.
26939 LD D,A D=the distance to Robbie.
Distance from the midges to the flower.
26940 LD A,(24205) A=the X position of the flower.
26943 SRL A B=the X position of the flower / 2.
26945 LD B,A
26946 LD A,(IX+1) A=the X position of the midges / 2.
26949 SRL A
26951 SUB B Subtract the X position of the flower.
26952 JP P,FindBugTarget_Flower_X Make sure we have a positive byte.
26955 NEG
FindBugTarget_Flower_X 26957 LD B,A B=the horizontal distance.
26958 LD A,(24206) A=the Y position of the flower.
26961 SRL A C=the Y position of the flower / 2.
26963 LD C,A
26964 LD A,(IX+2) A=the Y position of the midges / 2.
26967 SRL A
26969 SUB C Subtract the Y position of the flower.
26970 JP P,FindBugTarget_Flower_Y Make sure we have a positive byte.
26973 NEG
FindBugTarget_Flower_Y 26975 ADD A,B Add the horizontal distance to get the distance to the flower.
26976 CP D Compare the distance to the flower with the distance to Robbie.
26977 JR C,FindBugTarget_Flower Jump to FindBugTarget_Flower if the flower is nearer.
26979 LD HL,24173 HL=State_Robbie_Pos_X (Robbie).
26982 RET Return.
FindBugTarget_Flower 26983 LD HL,24205 HL=State_Flower_Pos_X (the flower).
26986 RET Return.
Prev: 26861 Up: Map Next: 26987