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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| 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

. Thanks for any help, cMp