import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.Color;

/**
   A car shape that can be positioned anywhere on the screen.
   SourceCode from BigJava, modified by Jason Longshore
   03/13/07
*/
public class Car
{
   /**
      Constructs a car with a given top left corner
      @param x the x coordinate of the top left corner
      @param y the y coordinate of the top left corner
      @param c the color of the car
   */
   public Car(int x, int y, Color c)
   {
      xLeft = x;
      yTop = y;
      carColor = c;
   }

   /**
      Draws the car.
      @param g2 the graphics context
   */
   public void draw(Graphics2D g2)
   {
	  g2.setColor(carColor);

      Rectangle body
            = new Rectangle(xLeft, yTop + 10, 60, 10);
      Ellipse2D.Double frontTire
            = new Ellipse2D.Double(xLeft + 10, yTop + 20, 10, 10);
      Ellipse2D.Double rearTire
            = new Ellipse2D.Double(xLeft + 40, yTop + 20, 10, 10);

      // The bottom of the front windshield
      Point2D.Double r1
            = new Point2D.Double(xLeft + 10, yTop + 10);
      // The front of the roof
      Point2D.Double r2
            = new Point2D.Double(xLeft + 20, yTop);
      // The rear of the roof
      Point2D.Double r3
            = new Point2D.Double(xLeft + 40, yTop);
      // The bottom of the rear windshield
      Point2D.Double r4
            = new Point2D.Double(xLeft + 50, yTop + 10);

      Line2D.Double frontWindshield
            = new Line2D.Double(r1, r2);
      Line2D.Double roofTop
            = new Line2D.Double(r2, r3);
      Line2D.Double rearWindshield
            = new Line2D.Double(r3, r4);

      g2.draw(body);
      g2.draw(frontTire);
      g2.draw(rearTire);
      g2.draw(frontWindshield);
      g2.draw(roofTop);
      g2.draw(rearWindshield);
   }

   /**
   	  Translates the car's topleft corner.
      @param x amount to move on x-axis
      @param y amount to move on y-axis
   	*/
   public void translate(int x, int y)
   {
	   xLeft += x;
	   yTop += y;
   }

   /**
   		Moves the car to a specific position
   		@param x where to move the car on the x axis
   		@param y where to move the car on the y axis
   */
   public void move(int x, int y)
   {
	   xLeft = x;
	   yTop = y;
   }

   /**
   		Returns car's x position
   		@return The cars x position
   */
   public int getX()
   {
	   return xLeft;
   }

   /**
   		Returns car's y position
   		@return The cars y position
   */
   public int getY()
   {
	   return yTop;
   }

   public static int WIDTH = 60;
   public static int HEIGHT = 30;
   private int xLeft;
   private int yTop;
   private Color carColor;
}
