Prev: 68ED Up: Map Next: 696B
690F: 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 690F LD A,($5E6D) A=the X position of Robbie.
6912 CP $18 Jump to FindBugTarget_Flower to use the flower if Robbie is too far to the left.
6914 JR C,FindBugTarget_Flower
6916 CP $D8 Jump to FindBugTarget_Flower to use the flower if Robbie is too far to the right.
6918 JR NC,FindBugTarget_Flower
Distance from the midges to Robbie.
691A SRL A B=the X position of Robbie / 02.
691C LD B,A
691D LD A,(IX+$01) A=the X position of the midges / 02.
6920 SRL A
6922 SUB B Subtract the X position of Robbie.
6923 JP P,FindBugTarget_Robbie_X Make sure we have a positive byte.
6926 NEG
FindBugTarget_Robbie_X 6928 LD B,A B=the horizontal distance.
6929 LD A,($5E6E) A=the Y position of Robbie.
692C SRL A C=the Y position of Robbie / 02.
692E LD C,A
692F LD A,(IX+$02) A=the Y position of the midges / 02.
6932 SRL A
6934 SUB C Subtract the Y position of Robbie.
6935 JP P,FindBugTarget_Robbie_Y Make sure we have a positive byte.
6938 NEG
FindBugTarget_Robbie_Y 693A ADD A,B Add the horizontal distance to get the distance to Robbie.
693B LD D,A D=the distance to Robbie.
Distance from the midges to the flower.
693C LD A,($5E8D) A=the X position of the flower.
693F SRL A B=the X position of the flower / 02.
6941 LD B,A
6942 LD A,(IX+$01) A=the X position of the midges / 02.
6945 SRL A
6947 SUB B Subtract the X position of the flower.
6948 JP P,FindBugTarget_Flower_X Make sure we have a positive byte.
694B NEG
FindBugTarget_Flower_X 694D LD B,A B=the horizontal distance.
694E LD A,($5E8E) A=the Y position of the flower.
6951 SRL A C=the Y position of the flower / 02.
6953 LD C,A
6954 LD A,(IX+$02) A=the Y position of the midges / 02.
6957 SRL A
6959 SUB C Subtract the Y position of the flower.
695A JP P,FindBugTarget_Flower_Y Make sure we have a positive byte.
695D NEG
FindBugTarget_Flower_Y 695F ADD A,B Add the horizontal distance to get the distance to the flower.
6960 CP D Compare the distance to the flower with the distance to Robbie.
6961 JR C,FindBugTarget_Flower Jump to FindBugTarget_Flower if the flower is nearer.
6963 LD HL,$5E6D HL=State_Robbie_Pos_X (Robbie).
6966 RET Return.
FindBugTarget_Flower 6967 LD HL,$5E8D HL=State_Flower_Pos_X (the flower).
696A RET Return.
Prev: 68ED Up: Map Next: 696B