I'm working on a Java tower defense game, but I've got a problem: I cant make the tower find enemies within a circle. My code:
if(twrsq.intersects(GameScreen.enemies[i])) {
shooting = true;
shotEnemy = i;
}
this.twrsq = new Rectangle(
x - (twrsqsize/2), y - (twrsqsize/2),
width + twrsqsize, height + twrsqsize);
twrsq
holds the current rectangle; this needs to be a circle. GameScreen.enemies[i]
holds a rectangle too. I'm trying to make a circle from twrsq
and make them intersect with the enemy.
How can I accomplish this?
Edit: I got it kinda working; I got now this screenshot:
if(cir.intersects(GameScreen.enemies[i])) {
shooting = true; shotEnemy = i;
}