Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDavid.M

Posted 12 August 2012 - 04:26 PM

Any special reason for having both a width and height? If it's a circle those are the same so you can have just one field, radius, to cover width and height.

To your Ball class you can add getX(), getY(), and getRadius() methods.

ArrayList<Ball> balls = new ArrayList<Ball>();

ballPositionX = balls.get(0).getX(); // gets the first ball's x position
ballPositionY = balls.get(0).getY(); //gets the first ball's y position
ballRadius = balls.get(0).getRadius(); //gets the first ball's radius

Then, circle collision detection is easy. Take two balls. Grab the x and y positions (centers) of both of them. If those positions are within (<) ball1.radius + ball2.radius then they are colliding.

#1David.M

Posted 12 August 2012 - 04:24 PM

Any special reason for having both a width and height? If it's a circle those are the same so you can have just one field radius to cover width and height.

To your Ball class you can add getX(), getY(), and getRadius() methods.

ArrayList<Ball> balls = new ArrayList<Ball>();

ballPositionX = balls.get(0).getX(); // gets the first ball's x position
ballPositionY = balls.get(0).getY(); //gets the first ball's y position
ballRadius = balls.get(0).getRadius(); //gets the first ball's radius

PARTNERS