Right, in my TD game, I am making a tesla tower. If you dont know, a tesla tower has small radius and every once and a while shoots out lightning in all directions harming every mob in radius. I am trying to get an array of all the mobs in radius so I can simply go through a for loop every time the tower “electrocutes” so I can harm all of them. Here is the code:
public void getMobs() {
for (int i = 0; i < Screen.mobs.length; i++) {
if (Screen.mobs[i] != null && circle != null) {
if (Screen.mobs[i].inGame) {
if (circle.intersects(Screen.mobs[i])) {
for (int s = 0; s < mobsIR.length; s++) {
if (mobsIR[s] == null) {
mobsIR[s] = Screen.mobs[i];
System.out.println("TARGETED: " + Screen.mobs[i] + " AT INDEX: " + s);
return;
}
}
}
}
}
}
}
The problem is that every time this is called it takes the first mob in radius and assigns it to every number in the the array “mobsIR[]”. I know it seems simple but I cant think of a way to do this :P. Thanks for any help, cMp