I am creating a game program where I need to run through an array list of circle graphics set at x and y coordinates. I need to make sure that none of the circle graphics overlap each other. This is what i have and seems to work sometimes but I think it is creating an infinite loop. Would love if someone could help me with my code.
for (int i = 0; i < circles.size(); i++) {
if (circles.isEmpty()) {
graphic.setX(x);
graphic.setY(y);
continue;
}
if (this.graphic.isCollidingWith(circles.get(i).graphic)) {
x = rng.nextInt((int)Engine.getWidth());
y = rng.nextInt((int)Engine.getHeight());
i = -1;
}
else {
graphic.setX(x);
graphic.setY(y);
}
}