Challenge 1: Targeting Priority

In this challenge, you will get your monkey to target the closest bloon, instead of the first bloon.

Use the i... list block to create a loop in attack with: monkey. Change i to bloon, and check the bloons list property.

You can now assess each bloon in sequence. Rather than use targetX and targetY to calculate dx, dy and distance, you can use the values of every bloon.

However, this will overwrite your dx, dy and distance variables for every bloon. How to you know which one was closest?

You will need to create new variables to record these values. Initialize the recorded distance to Infinity. Replace all three recorded variables if the distance is less than the recorded distance.

You do not need to calculate the angle until you have found the shortest distance.

This is a more complicated challenge, and requires advanced programming skills.

Mastering this challenge indicates an understanding of loop logic and the way variables change within a function.

results matching ""

    No results matching ""