Class Body

java.lang.Object
  |
  +--java.util.Observable
        |
        +--Body
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Debris, Explosion, LaserShot, Ship, Stellar

public class Body
extends java.util.Observable
implements java.io.Serializable

A (possibly) moving object living on the xy-plane. Serializable for pass by value over rmi. Notes on the calls at different points in the life of a body:

See Also:
Serialized Form

Inner Class Summary
protected  class Body.CollisionCheck
          A scheduled collision check.
 class Body.CreatedLaterException
          Attempted to project the body to a time before its creation.
 class Body.DisabledException
          Exception thrown when trying to use a disabled body.
 class Body.Projection
          An extrapolated projection of the body along its current known trajectory.
 
Field Summary
protected  double angle
           
protected  long creation
           
protected  int id
           
protected  double movementX
           
protected  double movementY
           
protected  int player
           
protected  double positionX
           
protected  double positionY
           
protected  double radius
           
protected  long time
           
protected  int type
           
 
Constructor Summary
Body(long when)
          Create a new body, starting at given time.
 
Method Summary
protected  void activate()
          Called from enable, right after body has been put to world and given master reference.
 void collision(Body threat, long when)
          Override this to do what is needed on actual collision.
 long collisionCheck(Body threat, long when, Body.Projection own)
          Check one threat for collision, project soonest possible collision.
 void collisionCheck(long when)
          The collision check inspects the situation at the time it was scheduled for, instead of when it occurs, to minimize the chance of missed collisions even if the check is badly delayed.
protected  void deactivate()
          Deactivation is called from disable before master goes null.
protected  void destroy(long when)
          If a body such as a ship of laser beam wants to die a violent and spectacular death, this is the method to call.
 void disable()
          Disable kills master reference after calling deactivate to remove anything that depends on master.
 void enable(MasterEngine m, int i)
          Called by master engine to set master reference and id when body is put into the engine.
 double getAcceleration()
           
 double getAngle()
           
 int getId()
           
 MasterEngine getMaster()
           
 int getPlayer()
           
 double getRadius()
           
 long getTime()
           
 int getType()
           
 double getX()
           
 double getY()
           
 boolean isAccelerating()
           
 Body.Projection project(long when)
          Project this body along its current known trajectory to the given time.
protected  void setAcceleration(double a, long when)
           
protected  void setAngleRate(double rate, long when)
           
 void update(long newTime)
          Update position, movement and other time-dependent attributes to given moment (ms since epoch).
protected  void updateComponents(long timeDelta)
          Do the practical work of updating position, movement, and angle.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected int id

player

protected int player

type

protected int type

time

protected long time

radius

protected double radius

positionX

protected double positionX

positionY

protected double positionY

movementX

protected double movementX

movementY

protected double movementY

angle

protected double angle

creation

protected final long creation
Constructor Detail

Body

public Body(long when)
Create a new body, starting at given time.
Method Detail

getId

public int getId()

getPlayer

public int getPlayer()

getType

public int getType()

getTime

public long getTime()

getX

public double getX()

getY

public double getY()

getAngle

public double getAngle()

isAccelerating

public boolean isAccelerating()

getRadius

public double getRadius()

getAcceleration

public double getAcceleration()

getMaster

public MasterEngine getMaster()
                       throws Body.DisabledException

setAngleRate

protected void setAngleRate(double rate,
                            long when)

setAcceleration

protected void setAcceleration(double a,
                               long when)

enable

public final void enable(MasterEngine m,
                         int i)
Called by master engine to set master reference and id when body is put into the engine. When the body is 'enabled', 'activation' is possible :) Overlay 'activate' to do init stuff that needs master, like scheduling expiry on projectiles.

activate

protected void activate()
                 throws Body.DisabledException
Called from enable, right after body has been put to world and given master reference. Overlay to do inits stuff that needs master. In Body, only first collision check scheduling lives here.

update

public final void update(long newTime)
Update position, movement and other time-dependent attributes to given moment (ms since epoch). Overlay updateComponents to do actual work.

updateComponents

protected void updateComponents(long timeDelta)
Do the practical work of updating position, movement, and angle. Overlay this when adding new attributes that should change with time. Synchronization is provided by the update method from which this is called.

collision

public void collision(Body threat,
                      long when)
Override this to do what is needed on actual collision.

destroy

protected void destroy(long when)
If a body such as a ship of laser beam wants to die a violent and spectacular death, this is the method to call. Overlay to cause more interesting violent death.

deactivate

protected void deactivate()
Deactivation is called from disable before master goes null. Cancel tasks here. Overlay to cancel more tasks.

disable

public final void disable()
Disable kills master reference after calling deactivate to remove anything that depends on master. Overlay 'deactivate' to do end-of-life cleanup stuff.

collisionCheck

public long collisionCheck(Body threat,
                           long when,
                           Body.Projection own)
                    throws Body.CreatedLaterException
Check one threat for collision, project soonest possible collision.
Parameters:
threat - Another Body.
when - Absolute time in ms to consider in this check.
own - Projection of this body to when.
Returns:
Time in ms from @param when of next possible collision with threat. If no such time exists, a negative number is returned.
Throws:
Body.CreatedLaterException - If threat was not yet created at when.

collisionCheck

public void collisionCheck(long when)
                    throws Body.DisabledException
The collision check inspects the situation at the time it was scheduled for, instead of when it occurs, to minimize the chance of missed collisions even if the check is badly delayed.

project

public Body.Projection project(long when)
                        throws Body.CreatedLaterException
Project this body along its current known trajectory to the given time.
Throws:
Body.CreatedLaterException - if the body did not yet exist at the requested time.