Car - yCurrent[scan] = y[scan] + yOffset; } body = new...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // Car.java Author: Lewis and Loftus // // Solution to Programming Project 8.16 //******************************************************************** import java.awt.Graphics; import java.awt.Color; import java.awt.Polygon; class Car { // Coordinates if car is drawn at position 0,0 private int[] x = { 0, 0, 20, 25, 70, 80, 105, 110 }; private int[] y = { 35, 15, 15, 0, 0, 15, 15, 35 }; private int[] xCurrent = new int [x.length]; private int[] yCurrent = new int [y.length]; private int xOffset, yOffset; private Color carColor; private Polygon body; //----------------------------------------------------------------- // Sets up the graphical car with the specified information. //----------------------------------------------------------------- public Car (int xOff, int yOff, Color color) { xOffset = xOff; yOffset = yOff; carColor = color; for (int scan = 0; scan < x.length; scan++) { xCurrent[scan] = x[scan] + xOffset;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: yCurrent[scan] = y[scan] + yOffset; } body = new Polygon (xCurrent, yCurrent, x.length); } //-----------------------------------------------------------------// Draws the car at a particular x and y offset. //-----------------------------------------------------------------public void draw (Graphics page) { page.setColor (Color.black); page.fillOval (13+xOffset, 28+yOffset, 14, 14); // rear wheel page.fillOval (83+xOffset, 28+yOffset, 14, 14); // front wheel page.drawLine (15+xOffset, 18+yOffset, 15+xOffset, 3+yOffset); page.setColor (carColor); page.fillPolygon (body); } //-----------------------------------------------------------------// Makes the car "move" for animation //-----------------------------------------------------------------public void setPosition (int newX, int newY) { body.translate (newX - xOffset, newY - yOffset); xOffset = newX; yOffset = newY; } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

Car - yCurrent[scan] = y[scan] + yOffset; } body = new...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online