Hi all,

I am trying to create a java pool game which monitors the users performance on how accurately they pocket balls. It is a one player game and I am having trouble with the algorithm related to motion and I used some of your code to implement that part but I am not getting the same result. 
Lets say that no collision occurs, when a force is applied upon the cue Ball, it travels along the right direction but it deviates from the trajectory more and more and end up in the wrong place. Could anyone tell me what the problem is? I am really. Thank you in advance.

Sample code from the Pool class
*************************
public void run()
{
  Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  while (Thread.currentThread() == animThread)
  {
  delta = System.currentTimeMillis() - lastTime;
  lastTime += delta;
  if (ballMoved) AI(delta / 1000.);
  startTime += delay;
  try { animThread.sleep(Math.max(0, startTime - System.currentTimeMillis())); }
  catch (InterruptedException e) {  break; }
  }
}

public void travel(double dt)
{
  for (int i = 0; i < Arr.size(); i++)
  Arr.getBallAt(i).collision(cueBall);

  cueBall.travel(dt);
 
  for (int i = 0; i < Arr.size(); i++)
  Arr.getBallAt(i).travel(dt);//ball.AI(dt);

  for (int i = 0; i < Arr.size(); i++)
  ballMoved = cueBall.check(Arr.getBallAt(i));

  repaint();
}

Sample code for Ball Class
********************
public boolean travel(double dt)
{
  if (!ballMoved)
  return false;

  double velocity = Math.sqrt(vx * vx + vy * vy);
  if (velocity != 0. && !inHole)
  {
  dx = vx / velocity;
  dy = vy / velocity;
  velocity -= 20 * dt;
  if (velocity < 0.)
  {
    vx = 0.;
    vy = 0.;
  }
  else
  {
    vx = velocity * dx;
    vy = velocity * dy;
  }
  }
  x += vx * dt; //increment the x value
  y += vy * dt; //increment the y value
 
  if(isWithinLimits(x, y))
    { /*no action taken*/ }
  else //if the x and y coordinate value are larger than the limits
    //which are the table boundary
  changeDirection();
 
  if (inHole && vx == 0 && vy == 0)
  {
  if (x < diameter)
    x = -radius;
  else if (x > xmax)
    x = xmax + radius;
  else
    x = xmax;
  if (y < diameter)
    y = -radius;
  else if (y > ymax - diameter)
    y = ymax + radius;
  ballMoved = false;
  }
  return inHole || checkhole();
}

public boolean isWithinLimits(int xx, int yy)
{
  if (xx > xmin && xx < xmax && yy > ymin && yy < ymax)
  return true;
  else
  return false;
}
public void changeDirection()
{
  if (inHole)
  {
  vx = 0.;
  vy = 0.;
  return;
  }
 
  if (x < xmin)
  {
    x = 2*xmin-x;
    vx = -vx;
  }
  else if (x > xmax)
  {
    x = 2 * xmax - x;
    vx = -vx;
  }
 
  if (y > ymax)
  {
    y = 2 * ymax - y;
    vy = -vy;
  }
  else if (y < ymin)
  {
    y = 2*ymin-y;
    vy = -vy;
  }
}//end of method