So I’m trying to place 20 circles around the screen randomly without touching each other and the collision detection doesn’t work. I’ve tried so many solutions that don’t work. Can anybody help me? If I need to put more code in here just lmk. Thank you in advance.
code from Handler class
public void createLevel() {
rand = new Random();
Blob lastBlob = new Blob(0,0, ObjectId.Blob); //to hold last blob
for (int i = 0; i < 20; i++){
Blob blob = new Blob(rand.nextInt(Game.WIDTH - 32), rand.nextInt(Game.HEIGHT - 32), ObjectId.Blob); //makes blob at random postion on-screen
addObject(blob);
if(blob.collidesWith(lastBlob)){
removeObject(blob);
i--; //makes certain that we only get 20 blobs
System.out.println("INTERSECTION"); //for debugging
}
lastBlob = blob; //makes the added blob the last blob
}
}
code from Blob class
public boolean collidesWith(GameObject object){
if(getBounds().intersects(object.getBounds()))
return true;
else
return false;
}
public Rectangle getBounds() {
return new Rectangle((int) x, (int) y, 32, 32);
}