import java.awt.*;public class Vehichle {	String name;	int clickX=0; int clickY=0;	boolean clicked=false;	int pixels[];	int distance=3;	// The ammount of change in position	int s1x, s2x, s1y, s2y;	// Sensor points x and y	int red1, green1, blue1;	int x = 0, y = 0, newX = 0, newY = 0, deg = 0, oldx = 0, oldy = 0, oldDegree=0;	int height = 12; int width = 8;  			// Actually 1/2 of the real height and width	int wheelHeight = 7; int wheelWidth = 4;	// Actually 1/2 of the real height and width	boolean s1 = false, s2 = false;				// Sensors (start with OFF)	boolean wheel1 = true, wheel2 = true;		// Wheel states on or off (true or false)	int w1x,w1y,w2x,w2y,w3x,w3y,w4x,w4y;		// Wheel x and y coordinates	int oldw1x,oldw1y,oldw2x,oldw2y,oldw3x,oldw3y,oldw4x,oldw4y,olds1x,olds1y,olds2x,olds2y;	Color carColor = Color.green.darker().darker().darker().darker();	// car color	boolean showingSensors = false;	boolean oneLastTime = false;	private DigitalPart s1a,s1b,s1c,s1d,s2a,s2b,s2c,s2d,w1a,w1b,w1c,w1d,w2a,w2b,w2c,w2d;	public Vehichle(int xCoord, int yCoord, String n) {		// The initial position of a car		x = xCoord; y = yCoord;		oldx = xCoord; oldy= yCoord;		oldw1x=50; oldw1y=50; oldw2x=50; oldw2y=50; oldw3x=50; oldw3y=50; oldw4x=50; oldw4y=50;		name=n;		s1a = new DigitalPart(445,155,false,false);		s2a = new DigitalPart(465,155,false,false);		w1a = new DigitalPart(485,155,true,true);		w2a = new DigitalPart(505,155,true,true);		s1b = new DigitalPart(445,175,false,false);		s2b = new DigitalPart(465,175,true,false);		w1b = new DigitalPart(485,175,false,true);		w2b = new DigitalPart(505,175,true,true);		s1c = new DigitalPart(445,195,true,false);		s2c = new DigitalPart(465,195,false,false);		w1c = new DigitalPart(485,195,true,true);		w2c = new DigitalPart(505,195,false,true);		s1d = new DigitalPart(445,215,true,false);		s2d = new DigitalPart(465,215,true,false);		w1d = new DigitalPart(485,215,true,true);		w2d = new DigitalPart(505,215,false,true);	}	public void resetValues() {		clickX=0; clickY=0;		clicked=false;		distance=3;		x = 100; y = 120; newX = 0; newY = 0; deg = 0; oldx = 0; oldy = 0; oldDegree=0;		height = 12;  width = 8;		wheelHeight = 7; wheelWidth = 4;		s1 = false; s2 = false;		wheel1 = true; wheel2 = true;		carColor = Color.green.darker().darker().darker().darker();		showingSensors = false;		oneLastTime = false;	}	public void move(Graphics g, boolean sen1, boolean sen2) {		s1 = sen1;		s2 = sen2;		oldDegree=deg;		if (!sen1 && !sen2) {		// These four if statements get info from the user setable table..			wheel1 = w1a.getState();			wheel2 = w2a.getState();			}		if (!sen1 && sen2) {			wheel1 = w1b.getState();			wheel2 = w2b.getState();			}		if (sen1 && !sen2) {			wheel1 = w1c.getState();			wheel2 = w2c.getState();			}		if (sen1 && sen2) {			wheel1 = w1d.getState();			wheel2 = w2d.getState();			}									// ACTIONS HAPPEN DEPENDING ON:		if (!wheel1 && !wheel2)	{	//  wheel 1 is OFF and wheel 2 is OFF			distance=0;			}		if (!wheel1 && wheel2)	{	//  wheel 1 is OFF and wheel 2 is ON			distance=3;			deg-=5;			}		if (wheel1 && !wheel2)	{	//  wheel 1 is ON and wheel 2 is OFF			distance=3;			deg+=5;			}		if (wheel1 && wheel2)	{	//  wheel 1 is ON and wheel 2 is ON			distance=4;			}		if (deg>360) deg = deg - 360;				// fix for the degree, to keep it under			else if (deg<0) deg = deg + 360;		// 360 and above 0....		if (x<20) { oldx=x; x=440; }			else if (x>440) { oldx=x; x=20; }		// also makes the edges connect...		if (y<20) { oldy=y; y=380; }			else if (y>380) { oldy=y; y=20; }		display(g);		}	public void checkTable(Graphics g,int x,int y) {  // only checks for wheels, not sensors...		if (w1a.inside(x,y)) { w1a.toggle(); showTable(g); }		if (w1b.inside(x,y)) { w1b.toggle(); showTable(g); }		if (w1c.inside(x,y)) { w1c.toggle(); showTable(g); }		if (w1d.inside(x,y)) { w1d.toggle(); showTable(g); }		if (w2a.inside(x,y)) { w2a.toggle(); showTable(g); }		if (w2b.inside(x,y)) { w2b.toggle(); showTable(g); }		if (w2c.inside(x,y)) { w2c.toggle(); showTable(g); }		if (w2d.inside(x,y)) { w2d.toggle(); showTable(g); }	}	public void resetAllThings() {		w1a.setState(true);		w2a.setState(true);		w1b.setState(false);	w2b.setState(true);		w1c.setState(true);		w2c.setState(false);		w1d.setState(true);		w2d.setState(false);		s1a.setState(false);	s2a.setState(false);		s1b.setState(false);	s2b.setState(true);		s1c.setState(true);		s2c.setState(false);		s1d.setState(true);		s2d.setState(true);	}	public void showTable(Graphics g) {			// This displays the truth table...		g.setColor(Color.black);		g.setFont(new Font("Courier", Font.PLAIN, 10));		g.drawString("Lookup Table:",440,120);		g.drawString("S1",442,135);		g.drawString("S2",462,135);		g.drawString("W1",482,135);		g.drawString("W2",502,135);		g.setColor(Color.black);		s1a.display(g);    s1b.display(g);		s1c.display(g);    s1d.display(g);		s2a.display(g);    s2b.display(g);		s2c.display(g);    s2d.display(g);		w1a.display(g);    w1b.display(g);		w1c.display(g);    w1d.display(g);		w2a.display(g);    w2b.display(g);		w2c.display(g);    w2d.display(g);		}	public void display(Graphics g) {		g.setColor(Color.white);	// First, fill in the old position with white (background) color...		g.fillPolygon(makeCar(oldx,oldy,width,height,oldDegree));		g.drawPolygon(makeCar(oldx,oldy,width,height,oldDegree));		g.fillPolygon(makeWheel(oldw1x,oldw1y,wheelWidth,wheelHeight,oldDegree));		g.fillPolygon(makeWheel(oldw2x,oldw2y,wheelWidth,wheelHeight,oldDegree));		g.fillPolygon(makeWheel(oldw3x,oldw3y,wheelWidth,wheelHeight,oldDegree));		g.fillPolygon(makeWheel(oldw4x,oldw4y,wheelWidth,wheelHeight,oldDegree));		if (oneLastTime || showingSensors) {			g.setColor(Color.white);			g.fillOval(s1x-5,s1y-5,10,10);			g.fillOval(s2x-5,s2y-5,10,10);			oneLastTime = false;			}			// Then figure out the new x and y coordinates based on distance and degree of angle...		double tempX = distance*Math.cos(deg*Math.PI/180), tempY = distance*Math.sin(deg*Math.PI/180);		x = (int)Math.round(x+tempX);		y = (int)Math.round(y+tempY);			// carShape holds the new shape and position (but does not display yet)		Polygon carShape = makeCar(x,y,width,height,deg);			// Wheels are drawn in black first, so they appear underneath the car itself...		g.setColor(Color.black);		g.fillPolygon(makeWheel(w1x,w1y,wheelWidth,wheelHeight,deg));	// front right		g.fillPolygon(makeWheel(w4x,w4y,wheelWidth,wheelHeight,deg));	// front left		g.fillPolygon(makeWheel(w2x,w2y,wheelWidth,wheelHeight,deg));	// rear right		g.fillPolygon(makeWheel(w3x,w3y,wheelWidth,wheelHeight,deg));	// rear left		g.setColor(carColor);		// now draw the car over the wheels		g.fillPolygon(carShape);		g.setColor(Color.green.darker().darker());		g.drawPolygon(carShape);		g.setColor(Color.black);		if (showingSensors) {			g.setColor(Color.black);			g.drawLine(s1x,s1y,s1x,s1y);			g.drawLine(s2x,s2y,s2x,s2y);			}		oldx = x;		oldy = y;			// assign values to "old" variables, so that it can be erased		oldw1x = w1x;	oldw1y = w1y;		oldw2x = w2x;	oldw2y = w2y;		oldw3x = w3x;	oldw3y = w3y;		oldw4x = w4x;	oldw4y = w4y;		olds1x = s1x;	olds1y = s1y;		olds2x = s2x; 	olds2y = s2y;	}		// this method takes an x and y, width and height and angle to plot out the position		// and appearance of the car...  it also figures out the x and y for each of the wheels.		// it returns a polygon which is the car (p)	public Polygon makeCar(int cx,int cy,int width,int height,int angleInDegrees) {		double angle = angleInDegrees*Math.PI/180;		double piAngle = angle+Math.PI/2;		double heightx = height*Math.cos(angle), heighty = height*Math.sin(angle);		double widthx = width*Math.cos(piAngle), widthy = width*Math.sin(piAngle);		Polygon p = new Polygon();		p.addPoint ((int)Math.round(cx+widthx+heightx),(int)Math.round(cy+widthy+heighty));			w1x = (int)Math.round(cx+widthx+heightx); // Wheel 1 x			w1y = (int)Math.round(cy+widthy+heighty); // Wheel 1 y			s2x = sendOutXBeam((int)Math.round(cx+widthx+heightx));	// Sensor two x			s2y = sendOutYBeam((int)Math.round(cy+widthy+heighty));	// Sensor two y		p.addPoint ((int)Math.round(cx+widthx-heightx),(int)Math.round(cy+widthy-heighty));			w2x = (int)Math.round(cx+widthx-heightx); // Wheel 2 x			w2y = (int)Math.round(cy+widthy-heighty); // Wheel 2 y		p.addPoint ((int)Math.round(cx-widthx-heightx),(int)Math.round(cy-widthy-heighty));			w3x = (int)Math.round(cx-widthx-heightx); // Wheel 3 x			w3y = (int)Math.round(cy-widthy-heighty); // Wheel 3 y		p.addPoint ((int)Math.round(cx-widthx+heightx),(int)Math.round(cy-widthy+heighty));			w4x = (int)Math.round(cx-widthx+heightx); // Wheel 4 x			w4y = (int)Math.round(cy-widthy+heighty); // Wheel 4 y			s1x = sendOutXBeam((int)Math.round(cx-widthx+heightx));	// Sensor one x			s1y = sendOutYBeam((int)Math.round(cy-widthy+heighty));	// Sensor two y		return p;	}			// Basically this next method is just a smaller version of the above method...			// It returns polygons for wheels, based on each x and y sent to it...	public Polygon makeWheel(int cx,int cy,int width,int height,int angleInDegrees) {		double angle = angleInDegrees*Math.PI/180;		double piAngle = angle+Math.PI/2;		double heightx = height*Math.cos(angle), heighty = height*Math.sin(angle);		double widthx = width*Math.cos(piAngle), widthy = width*Math.sin(piAngle);		Polygon p = new Polygon();		p.addPoint ((int)Math.round(cx+widthx+heightx),(int)Math.round(cy+widthy+heighty));		p.addPoint ((int)Math.round(cx+widthx-heightx),(int)Math.round(cy+widthy-heighty));		p.addPoint ((int)Math.round(cx-widthx-heightx),(int)Math.round(cy-widthy-heighty));		p.addPoint ((int)Math.round(cx-widthx+heightx),(int)Math.round(cy-widthy+heighty));		return p;	}	public void clickInsideCar(int x, int y) {		clickX = x; clickY = y;	}	public void setSensorDisplayOn() {		showingSensors = true;		}	public void setSensorDisplayOff() {		showingSensors = false;		oneLastTime = true;		}	public int sendOutXBeam(int coord) {		double tempX = 38*Math.cos(deg*Math.PI/180);		return (int)Math.round(coord+tempX);	}	public int sendOutYBeam(int coord) {		double tempY = 38*Math.sin(deg*Math.PI/180);		return (int)Math.round(coord+tempY);	}	public int sensorOneX() {		return s1x;		}	public int sensorOneY() {		return s1y;		}	public int sensorTwoX() {		return s2x;		}	public int sensorTwoY() {		return s2y;		}}