Challenge 4: Pop the Leader

Many Tower Defense games default to targeting the invader that's closest to the end of the map. This is logical - it's the most dangerous invader.

We coded our monkeys to attack the first bloon within range. But what does "first" really mean? In this case, it's the first bloon that was created and added to the list. If bloons were moving at different speeds, like in the full game, they might overtake one another and confuse matters.

Fortunately, you can get a more accurate definition of "first".

Each bloon tracks total distance in a property called totalDistance. This is updated in the function moveTowardsNextWaypoint. For your targeting script to read this value, you'll need to set a key whenever you update the property (see the "Configurable Monkeys" challenge for more on keys).

Your challenge is to pop the leader by preference. Remember, you should still only target bloons within the monkey's attack radius. You'll need to add another register for the bloon with the highest totalDistance (hence progress towards the exit), and more conditionals to check whether a given bloon is both within range and closer to the exit than any previous bloon.

Mastering this challenge indicates an excellent understanding of conditional logic and communicating information around a program.

results matching ""

    No results matching ""