dualroids
Class SpatialObject

java.lang.Object
  |
  +--dualroids.SpatialObject
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Asteroid, Bullet, SpaceShip

public abstract class SpatialObject
extends Object
implements Serializable

The common superclass for all spatial objects.

See Also:
Serialized Form

Field Summary
static Color[] COLOR_TABLE
          17 shades of gray ready to use in Asteroid and SpaceShip objects
static int COLOR_TABLE_BLACK
          The index of black in COLOR_TABLE.
static int COLOR_TABLE_GRAY_50
          The index of 50% gray in COLOR_TABLE.
static int COLOR_TABLE_WHITE
          The index of white in COLOR_TABLE.
protected  GeneralPath geometry
          The untranslated geometric representation of the spatial object
protected  double locationX
          The x coordinate of the center of the spatial object at the moment indicated by timestamp.
protected  double locationY
          The y coordinate of the center of the spatial object at the moment indicated by timestamp.
protected  long timestamp
          The moment in game (server) time for which the other fields are valid.
protected  AffineTransform transform
          The AffineTransform used for calculating the translated geometry.
protected  double velocityX
          The x component of the valocity of the spatial object at the moment indicated by timestamp.
protected  double velocityY
          The y component of the valocity of the spatial object at the moment indicated by timestamp.
 
Constructor Summary
protected SpatialObject()
          Dummy constructor for keeping the serialization framework happy.
protected SpatialObject(double locationX, double locationY, double velocityX, double velocityY, long timestamp)
          Contructs a new SpatialObject.
 
Method Summary
abstract  Shape getTransformedShape(long time)
          Returns a properly translated Shape representing the spatial object at time
static double moveToRangeX(double value)
          Moves value to the range 0.0...Arena.WIDTH so that the coordinate wraps around.
static double moveToRangeY(double value)
          Moves value to the range 0.0...Arena.HEIGHT so that the coordinate wraps around.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

COLOR_TABLE_BLACK

public static final int COLOR_TABLE_BLACK
The index of black in COLOR_TABLE.

COLOR_TABLE_WHITE

public static final int COLOR_TABLE_WHITE
The index of white in COLOR_TABLE.

COLOR_TABLE_GRAY_50

public static final int COLOR_TABLE_GRAY_50
The index of 50% gray in COLOR_TABLE.

COLOR_TABLE

public static final Color[] COLOR_TABLE
17 shades of gray ready to use in Asteroid and SpaceShip objects

timestamp

protected long timestamp
The moment in game (server) time for which the other fields are valid.

geometry

protected transient GeneralPath geometry
The untranslated geometric representation of the spatial object

locationX

protected double locationX
The x coordinate of the center of the spatial object at the moment indicated by timestamp.

locationY

protected double locationY
The y coordinate of the center of the spatial object at the moment indicated by timestamp.

velocityX

protected double velocityX
The x component of the valocity of the spatial object at the moment indicated by timestamp.

velocityY

protected double velocityY
The y component of the valocity of the spatial object at the moment indicated by timestamp.

transform

protected transient AffineTransform transform
The AffineTransform used for calculating the translated geometry. Stored here in order to avoid unnecessary feeding of the GC.
Constructor Detail

SpatialObject

protected SpatialObject(double locationX,
                        double locationY,
                        double velocityX,
                        double velocityY,
                        long timestamp)
Contructs a new SpatialObject.
Parameters:
locationX - the x coordinate of the initial location
locationY - the y coordinate of the initial location
velocityX - the x component of the velocity
velocityY - the y component of the velocity
angle - the angle in radians
timestamp - the moment in game (server) time for which the other data is valid

SpatialObject

protected SpatialObject()
Dummy constructor for keeping the serialization framework happy.
Method Detail

moveToRangeX

public static final double moveToRangeX(double value)
Moves value to the range 0.0...Arena.WIDTH so that the coordinate wraps around.
Parameters:
value - the value to wrap
Returns:
the wrapped value

moveToRangeY

public static final double moveToRangeY(double value)
Moves value to the range 0.0...Arena.HEIGHT so that the coordinate wraps around.
Parameters:
value - the value to wrap
Returns:
the wrapped value

getTransformedShape

public abstract Shape getTransformedShape(long time)
Returns a properly translated Shape representing the spatial object at time
Parameters:
time - the moment in game (server) time for which the representation is requested
Returns:
the Shape representation at time or null if the object isn't visible


Dualroids was written by Oskar Ojala, Yrjö Kari-Koskinen and Henri Sivonen