dualroids
Class Bullet

java.lang.Object
  |
  +--dualroids.SpatialObject
        |
        +--dualroids.Bullet
All Implemented Interfaces:
Serializable

public final class Bullet
extends SpatialObject

The representation of a bullet.

A Note About Thread Safety

The implementation of Bullet is thread-safe in the sense that the one thread may call the setters while another calls the getters. However, there may not be multiple threads calling getTransformedShape. It is designed to be used from a single thread only.

Also, that thread should not retain references to objects returned by getTransformedShape across the method calls. When the method is called the object it returned previously will no longer be valid.

See Also:
Serialized Form

Field Summary
private static double BULLET_HALF_LENGTH
          Constant for the length of a bullet divided by 2.
private static long BULLET_TTL
          The lifetime of a bullet in milliseconds.
private static double BULLET_VELOCITY
          Constant for the bullet velocity.
private  long expires
          The moment in time when this bullet expires
private  double lineDeltaX
          The x difference of the between the center of bullet the end of the bullet line
private  double lineDeltaY
          The y difference of the between the center of bullet the end of the bullet line
private  Line2D translatableLine
          The Line2D instance used for returning the translated Shape representation of the bullet
private  Point2D translatableLocation
          The Point2D instance used for returning the translated location of the bullet
 
Fields inherited from class dualroids.SpatialObject
COLOR_TABLE, COLOR_TABLE_BLACK, COLOR_TABLE_GRAY_50, COLOR_TABLE_WHITE, geometry, locationX, locationY, timestamp, transform, velocityX, velocityY
 
Constructor Summary
Bullet()
          Contructs a new bullet.
 
Method Summary
 void fire(double locationX, double locationY, double shipVelocityX, double shipVelocityY, double angle, long timestamp)
          Fires this bullet.
 Point2D getLocation(long time)
          Returns the location of the bullet at time.
 Shape getTransformedShape(long time)
          Returns a properly transformed Shape representing the spatial object at time
 void initFromRemote(double locationX, double locationY, double velocityX, double velocityY, double lineDeltaX, double lineDeltaY, long timestamp, long expires)
          Initializes the state of the bullet from external state data.
 void invalidate()
          Marks the bullet non-flying (not visible)
 boolean readyToBeFired()
          Returns a boolean indicating whether the bullet is ready to be fired.
 void writeToConnector(int thisIndex, ClientModelConnector connector)
          Writes the state of the bullet to a ClientModelConnector
 
Methods inherited from class dualroids.SpatialObject
moveToRangeX, moveToRangeY
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

BULLET_VELOCITY

private static double BULLET_VELOCITY
Constant for the bullet velocity.

BULLET_HALF_LENGTH

private static double BULLET_HALF_LENGTH
Constant for the length of a bullet divided by 2.

BULLET_TTL

private static long BULLET_TTL
The lifetime of a bullet in milliseconds.

translatableLocation

private Point2D translatableLocation
The Point2D instance used for returning the translated location of the bullet

lineDeltaX

private double lineDeltaX
The x difference of the between the center of bullet the end of the bullet line

lineDeltaY

private double lineDeltaY
The y difference of the between the center of bullet the end of the bullet line

translatableLine

private Line2D translatableLine
The Line2D instance used for returning the translated Shape representation of the bullet

expires

private long expires
The moment in time when this bullet expires
Constructor Detail

Bullet

public Bullet()
Contructs a new bullet. The fields aren't initialized to any meaningful values. The values are supplied using the fire method.
Method Detail

getLocation

public final Point2D getLocation(long time)
Returns the location of the bullet at time. There should be one thread at maximum per arena calling this method. The returned Point2D shouldn't be retained as it will become invalid when this method is called again.
Parameters:
time - the moment in game (server) time for which the location is requested
Returns:
a Point2D

fire

public final void fire(double locationX,
                       double locationY,
                       double shipVelocityX,
                       double shipVelocityY,
                       double angle,
                       long timestamp)
Fires this bullet. Used only on the client that controls the ship that owns this bullet.
Parameters:
locationX - the x coordinate of the ship
locationY - the y coordinate of the ship
shipVelocityX - the x component of the velocity of the ship
shipVelocityY - the y component of the velocity of the ship
angle - the angle of the ship
timestamp - the moment of firing

getTransformedShape

public final Shape getTransformedShape(long time)
Returns a properly transformed Shape representing the spatial object at time
Overrides:
getTransformedShape in class SpatialObject
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

invalidate

public final void invalidate()
Marks the bullet non-flying (not visible)

readyToBeFired

public final boolean readyToBeFired()
Returns a boolean indicating whether the bullet is ready to be fired.
Returns:
a boolean indicating whether the bullet is ready to be fired

writeToConnector

public final void writeToConnector(int thisIndex,
                                   ClientModelConnector connector)
Writes the state of the bullet to a ClientModelConnector
Parameters:
thisIndex - the index of this bullet
connector - the connector to which the state is to be written

initFromRemote

public final void initFromRemote(double locationX,
                                 double locationY,
                                 double velocityX,
                                 double velocityY,
                                 double lineDeltaX,
                                 double lineDeltaY,
                                 long timestamp,
                                 long expires)
Initializes the state of the bullet from external state data.
Parameters:
locationX - the x coordinate at which the bullet was fired
locationY - the y coordinate at which the bullet was fired
velocityX - the x component of the velocity of the bullet
velocityY - the y component of the velocity of the bullet
timestamp - the moment at which the bullet was fired
expires - the moment in time at which the bullet expires


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