Greetings fellow developers,
Today, I have an inquiry regarding a project I am working on, akin to a Tower Defense game created using canvas. I am facing a challenge in detecting multiple circles in one coordinate. Here's an excerpt of my current dilemma:
for (var a = 0; a < buildArcherX.length; a++) {
for (var a = 0; a < buildArcherY.length; a++) {
if (Math.sqrt(Math.pow(buildArcherX[a] - this.x, 2) + Math.pow(buildArcherY[a] - this.y, 2)) <= arch.radius + 7) {
this.attackedByArcher = true;
} else {
this.attackedByArcher = false;
}
}
}
In this snippet, I am utilizing arrays to store the coordinates for my "Defenses". The nested for loops iterate through all the defense coordinates in the arrays. The if statement checks if any of the defense coordinates fall within the range of "this" coordinates, returning a boolean value to indicate if any defenses are within range.
Despite reaching this point, I have encountered a roadblock: How should I handle the scenario where multiple defenses are within range? In such a case, "this" would need to sustain more damage. Therefore, I am seeking advice on whether it is feasible to display the number of defenses within range.
Appreciate your insights!