game
Class Trajectory

java.lang.Object
  extended by game.Trajectory
All Implemented Interfaces:
Trackable

public class Trajectory
extends java.lang.Object
implements Trackable

Describe the trajectory of a dart with gravity present. Units are in pixels and seconds unless otherwise noted. Warning! It is a good idea to have a separate Trajectory object associated with each MovingBody. This way, the time tracking within each one is separate. If you have an instance of a Trajectory t, then you can get a copy of it by t.copyFromStart() A better design might be to have Trajectory work on absolute time rather than increments, as then it could be shared by many MvingBody objects.


Constructor Summary
Trajectory(Point start)
          Falling body constructor for default gravity
Trajectory(Point start, Vector initialVelocity)
          Constructor compatible with last week's studio.
Trajectory(Point start, Vector initialVelocity, Vector gravity)
          Most general constructor, takes in gravity as a parameter.
 
Method Summary
 int advanceTime(int milliseconds)
          Mark the time that has passed in milliseconds.
static Vector computeGravity(int numPixels, int t)
          Compute the acceleration of gravity based on the supplied parameters, starting at rest.
 Trajectory copyFromStart()
          Provide a copy of this trajectory back at time=0
 Point getLocation()
          Returns the current location.
protected  Point getLocation(int atTime)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Trajectory

public Trajectory(Point start,
                  Vector initialVelocity)
Constructor compatible with last week's studio. Assumes gravity must traverse 500 pixels in 1 second.

Parameters:
start - initial point
initialVelocity - in pixels/second, standard raster coordinates

Trajectory

public Trajectory(Point start,
                  Vector initialVelocity,
                  Vector gravity)
Most general constructor, takes in gravity as a parameter.

Parameters:
start -
initialVelocity -
gravity -

Trajectory

public Trajectory(Point start)
Falling body constructor for default gravity

Parameters:
start -
Method Detail

copyFromStart

public Trajectory copyFromStart()
Provide a copy of this trajectory back at time=0

Returns:
essentially a .clone() of this Trajectory, but with time at 0

computeGravity

public static Vector computeGravity(int numPixels,
                                    int t)
Compute the acceleration of gravity based on the supplied parameters, starting at rest.

Parameters:
numPixels - The number of pixels to be covered
t - The time taken to cover the number of pixels

getLocation

protected Point getLocation(int atTime)
Parameters:
atTime - specified time since start
Returns:
location based on elapsed time supplied as parameter

getLocation

public Point getLocation()
Returns the current location.

Specified by:
getLocation in interface Trackable
Returns:
current location

advanceTime

public int advanceTime(int milliseconds)
Mark the time that has passed in milliseconds.

Specified by:
advanceTime in interface Trackable
Returns:
The current time after the update.