Hey guys! I'm trying to create an Agar.io looking game for my computer science course. I come up with this code to see if my new created circle object will overlap with any other object, however, I still get many objects overlapping with one another. Since the getObjectsAt method can only get the object based on its X and Y location, this does not help me much. I thought about perhaps making a method in my Actor class (All this work is done in the child class of World), but I'm not exactly sure how I can go about doing this.
This is my code:
This what actually happens when I execute the program:
Any help will be greatly appreciated!
private boolean placeRandomBall()
{
//Get a random location and size for the ball to be placed
int randX = Greenfoot.getRandomNumber(getWidth());
int randY = Greenfoot.getRandomNumber(getHeight());
int randSize = Greenfoot.getRandomNumber(MAXSIZE);
//Test to see if this location is already in use
if (getObjectsAt(randX, randY, Ball.class).isEmpty()) {
//Add a ball to the world
Ball tempBall = new Ball(randSize);
super.addObject (tempBall,randX,randY); //if size is too great
tempBall.updateImage();
//Successfully complete task so return true
return true;
}
//Something went wrong, so return a false value
return false;
}
Any help will be greatly appreciated!
