import ddf.minim.*;
AudioPlayer player;
Minim minim;
Table t1= new Table(300, 300);
float power=0;
float dx=0;
float dy=0;
void setup()
{
  size(1000, 600);
  frameRate(20);
  minim= new Minim(this);
  player=minim.loadFile("ballsound.mp3");
}
void draw()
{
  strokeWeight(1);
  stroke(0, 0, 0); 
  strokeWeight(10);
  stroke(255, 0, 0);
  fill(26, 218, 35);
  rect(0, 0, 1000, 600);
  noStroke();
  fill(0);
  ellipse(0, 0, 80, 80);
  ellipse(1000, 0, 80, 80);
  ellipse(0, 600, 80, 80);
  ellipse(1000, 600, 80, 80);
  strokeWeight(1);
  stroke(0, 0, 0);
  fill(255);
  ellipse(t1.cue_ball.center.x, t1.cue_ball.center.y, 20, 20);
  t1.cue_ball.center.x+=dx;
  t1.cue_ball.center.y+=dy;
  dx=friction(dx);
  dy=friction(dy);
  stroke(40); 
  strokeWeight(4);
  line ( mouseX , mouseY , mouseX + cos (atan2 ( mouseY -t1.cue_ball.center.y , mouseX - t1.cue_ball.center.x) )*300 , mouseY +  sin( atan2 ( mouseY - t1.cue_ball.center.y , mouseX -t1.cue_ball.center.x ))*300);
  if (mousePressed)
  {
    power+=4;
  }
   if (t1.cue_ball.center.x+20 > 1000 || t1.cue_ball.center.x-20 < 0 )
  {
    dx*=-1;
    player.rewind();
    player.play();
  }
  if (t1.cue_ball.center.y+20 > 600 || t1.cue_ball.center.y-20 < 0)
  {
    dy*=-1;
    player.rewind();
    player.play();
  }
  if( (t1.cue_ball.center.x < 40  && (t1.cue_ball.center.y < 40 ||t1.cue_ball.center.y > 560 ) )  ||  ( t1.cue_ball.center.x > 980 && ( t1.cue_ball.center.y > 580 || t1.cue_ball.center.y < 40)))
  {
    dx=0;
    dy=0;
    fill(255);
    textSize(25);
    text("GAME OVER" ,500,300);
    player.pause();
  }
 if (t1.cue_ball.center.x +20 == 1000)
 {
   t1.cue_ball.center.x=979;
 }
 if (t1.cue_ball.center.x -20 == 0)
 {
   t1.cue_ball.center.x =21;
  }
 if(t1.cue_ball.center.y -20 == 0)
 {
   t1.cue_ball.center.y  =21;
 }
  }
void mouseReleased()
{
  dx=t1.cue_ball.center.x-mouseX;
  dy=t1.cue_ball.center.y-mouseY;
  float n= sqrt(pow(dx,2)+pow(dy,2));
  dx*=power/n;
  dy*=power/n;
}
float friction (float c)
{
  c*=0.9;
  return c;
}
class Ball 
{
  float rad;
  Point center;
  Point contact_point;
  color col;
  Ball ( float a, float b)
  {
    center = new Point (a+=dx, b+=dy);
  }
} 
class Table
{
  Ball [] b_arr;    
  Stick st;
  Ball cue_ball;
  Table ( float a, float b )
  {
    cue_ball= new Ball( a, b);
  }
}
class Point
{
  float x;
  float y;
  Point(float a, float b)
  {
    x=a;
    y=b;
  }
}
class Stick
{
  Point start_p;
  Point end_p;
  color col;
  int length;
}
Since the stick was added it has stopped being able to bounce off the walls and I can't understand why. It was working before it was added, and then it just stopped and when it gets close it gives NullPointerException. I don't see how to stick would change anything though.
 
     
    