import java.awt.Rectangle; import java.util.*; public class MyThread extends Thread { /* Used to check for collisions and edit the left/ right/up/ down variable to make the ball change directions */ private final ArrayList aList; public MyThread(ArrayList myballs){ aList = myballs; } public void run(){ // System.out.println("MyThread running"); int count =0; for(int i=0; i bounds2.x && bounds.y < bounds2.y + bounds2.height && bounds.y + bounds.height >bounds2.y) { // collision detected! //collision rand select direction Random rand = new Random(); int n = rand.nextInt(3); if(up) { aList.get(i).setUp(false); aList.get(i).setDown(true); if(right) { aList.get(i).setRight(false); aList.get(i).setLeft(true); // - x //aList.get(i).setOneX(oneX2-1); } else { aList.get(i).setRight(true); aList.get(i).setLeft(false); //aList.get(i).setOneY(oneY2+1); } //up = false; //down=true; } else { aList.get(i).setUp(true); aList.get(i).setDown(false); if(right) { aList.get(i).setRight(false); aList.get(i).setLeft(true); } else { aList.get(i).setRight(true); aList.get(i).setLeft(false); } } //update object //System.out.println("Collison detected"); //System.out.println("oneX: " + oneX + "oneY: " + oneY + "oneX2: " + oneX2 + "oneY2: " + oneY2); } } } } } } /* private boolean up = false; private boolean down = true; private boolean left = false; private boolean right = true; */