vehicle
Class AbstractVehicle

java.lang.Object
  |
  +--vehicle.AbstractVehicle
Direct Known Subclasses:
BasicVehicle

public abstract class AbstractVehicle
extends java.lang.Object

An AbstractVehicle has the current World and a MovementTracker.

Any subclass must implement the createShapes(), update(), and draw() methods.

The createShapes() method is called from this constructor. It should instantiate all necessary geometrical shapes associated with this vehicle and register it with the MovementTracker of this object.
The draw() method is called whenever it's time to paint/repaint the screen. This can happen at any time. State changes should not occur in this method. Presumably, this method should just set the color of the different shapes created in createShapes() and call the necessary methods in the graphics module.
The update() method is called by the world whenever it's time to update the state of the world. This occurs onces World.FPS times per second. Any changes to the state of this vehicle such as moving should occur in this method.


Field Summary
protected  MovementTracker mvTrack
           
protected  World theWorld
           
 
Constructor Summary
AbstractVehicle(World ourWorld)
          Initialize variables for the vehicle.
 
Method Summary
abstract  void draw(java.awt.Graphics2D g)
          Use the graphics system to actually paint the shapes we have created.
 double getOrientation()
          Gets the orientation changed from the inital drawing
 MovementTracker getTracker()
          Retrieves the MovementTracker.
 double getX()
          Returns the current x position of the center point of all the shapes contained in this tracker.
 double getY()
          Returns the current y position of the center point of all the shapes contained in this tracker.
 void handleCollision(AbstractVehicle av)
          Handles a collision with another vehicle.
 void moveBy(double xoffset, double yoffset)
          Move by xoffset and yoffset pixels.
 void moveTo(double x, double y)
          Move to (x, y) in the world.
 void rotateBy(double theta)
          Rotate shapes by theta with postive sign meaning clockwise
 void setOrientation(double theta)
          Set the current orientation with postive sign meaning clockwise.
abstract  void update()
          Called by World when it's time to update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theWorld

protected World theWorld

mvTrack

protected MovementTracker mvTrack
Constructor Detail

AbstractVehicle

public AbstractVehicle(World ourWorld)
Initialize variables for the vehicle.

Method Detail

getX

public double getX()
Returns the current x position of the center point of all the shapes contained in this tracker.

Returns:
x-coordinate of the shapes' center

getY

public double getY()
Returns the current y position of the center point of all the shapes contained in this tracker.

Returns:
y-coordinate of the shapes' center

getOrientation

public double getOrientation()
Gets the orientation changed from the inital drawing

Returns:
the angle in radians

setOrientation

public void setOrientation(double theta)
Set the current orientation with postive sign meaning clockwise.

Parameters:
theta - the angle in radians

rotateBy

public void rotateBy(double theta)
Rotate shapes by theta with postive sign meaning clockwise

Parameters:
theta - the angle in radians

moveTo

public void moveTo(double x,
                   double y)
Move to (x, y) in the world.

Parameters:
x - the x-coordinate to move to
y - the y-coordinate to move to

moveBy

public void moveBy(double xoffset,
                   double yoffset)
Move by xoffset and yoffset pixels.

Parameters:
xoffset - the number of pixels to move in the x-axis direction
yoffset - the number of pixelse to move in the y-axis direction

getTracker

public MovementTracker getTracker()
Retrieves the MovementTracker.

Returns:
the MovementTracker associated with this vehicle

handleCollision

public void handleCollision(AbstractVehicle av)
Handles a collision with another vehicle. The default is to do nothing. Note: The method is not required.

Parameters:
av - the other vehicle

update

public abstract void update()
Called by World when it's time to update. Any state changes to this vehicle should occur here.


draw

public abstract void draw(java.awt.Graphics2D g)
Use the graphics system to actually paint the shapes we have created.

Parameters:
g - the graphics system to use