Heres my code:
public class Ball extends Thread{
int x = 100,y = (HEIGHT/2);
int xVel, yVel;
public void run(){
xVel = 10;
yVel = -14;
boolean win = false;
this.setPriority(10);
while(true){
try{
if(win == false){
x += xVel;
y += yVel;
}
if(ballRect != null){
if(ballRect.intersects(p1Win) || ballRect.intersects(p1Win)){
System.out.println("INTERSECT");
win = true;
if(ballRect.intersects(p1Win))
win("Player 1");
if(ballRect.intersects(p2Win))
win("Player 2");
break;
}
if(ballRect.intersects(p1Rect) || ballRect.intersects(p2Rect)){
xVel *= -1;
yVel *= -1;
if(ballRect.intersects(p1Rect))
x += 11;
else if(ballRect.intersects(p2Rect))
x -= 11;
System.out.println(xVel);
System.out.println(yVel);
System.out.println("INTERSECT IN PADDLE");
}
}
if(y <= 0 || y >= HEIGHT){
yVel *= -1;
System.out.println("Collision");
}
Thread.sleep(60);
repaint();
}catch(Exception e){
e.printStackTrace();
break;
}
}
System.out.println("BALL THREAD TERMINATED");
}
}
Any help would be greatly appreciated.