yeah basically im trying to get to grips with object orientated programming in processing,
so far i have a lot of balls bouncing around, now i want to make them bounce off each other aswell,
my plan is to check each ball to see if they are touching each other and then reverse the balls that touch, speed
can you tell specific object to carry out a function so something like
ball(i).reverseDirection
where i is the balls index in the array list.
this is my code that ive just written in the last 5 minutes
Code:vvoid checkCollision(){
for (int i = balls.size()-1; i >=0 ;i--){
float CollisionCheckX = (((Circle)balls.get(i)).x);
float CollisionCheckY = (((Circle)balls.get(i)).y);
float BallDiameter = (((Circle)balls.get(i)).diameter);
for (int j = balls.size()-1; j >=0 ;j--) {
float CollisionCheckX2 = (((Circle)balls.get(j)).x);
float CollisionCheckY2 = (((Circle)balls.get(j)).y);
float BallDiameter2 = (((Circle)balls.get(j)).diameter);
if (dist(CollisionCheckX,CollisionCheckX2,CollisionCheckY,CollisionCheckY2) <= BallDiameter + BallDiameter2){
changeDirection();
}
}
}
so im going to write and if statement that compares the coordinates of ball(i) to ball(j) and then run a function if they are touching.
any suggestions?
edit: added some code