Source code for wannabe

This code is part of the SoccerClient class, so you don't have to write it yourself. It's just here to show you how it works.

public int wannabe(int loc, int dx, int dy) {
  getVel(v);
  // v is the velocity in pixels per second
  // now we want to find out how far we are from the desired location
  ping(loc, pt, false);
  // add in the offset, and subtract out the stopping distance
  // (the /6 was found experimentally to give good results)
  pt.x+= dx-v.x/6;
  pt.y+= dy-v.y/6;
  // convert it to polar coordinates (x=distance, y=angle)
  cart2polar(pt, pt);
  // and go there!
  accelerate(pt.y, (pt.x*pt.x)<<1);
  // if we're close to the desired location and not moving very fast,
  // signal that we're ready, and return the forward direction
  if (pt.x<3 && Math.abs(v.x)<10 && Math.abs(v.y)<10) {
    setReady(true);
    return 90;
  } else {
    // otherwise, we're not ready.  Return the direction we accelerated.
    setReady(false);
    return ang;
  }
}