|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--dualroids.SpatialObject | +--dualroids.SpaceShip
The representation of a space ship.
The implementation of SpaceShip
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
and getVertices
.
They are designed to be used from a single thread only.
Also, that thread should not retain references to
objects returned by getTransformedShape
and
getVertices
across the method calls.
When the methods are called the objects they returned
previously will no longer be valid.
Field Summary | |
private static double |
ACCELERATION
The acceleration of the ship when the ship is thrusting. |
private double |
angle
The rotation angle (in radians) of the spatial object at the moment indicated by timestamp . |
private static double |
ANGULAR_VELOCITY
The angular velocity of the ship when the ship is turning. |
private static long |
BULLET_INTERVAL
The minimum delay between firing bullets. |
private int |
bulletFireIndex
The index of the previously fired bullet. |
private Bullet[] |
bullets
An array holding all the (recyclable) bullets owned by this ship. |
private static float[] |
CENTER_POINTS
The coordinated of the center poins of the edges of the ship. |
private static float |
COLOR_STEP
The amount of time used for one outline color in explosion |
private ClientModelConnector |
connector
The ClientModelConnector through
which this ship can send its state to the server. |
private static double |
DEBRIS_ANGULAR_VELOCITY
The angular velocity of ship debris. |
private static float[] |
DEBRIS_POINTS
An array holding coordinate constants used when drawing debris. |
private static float |
DEBRIS_VELOCITY_FACTOR
A factor used when calculating the velocity of debris. |
private long |
earliestNextBullet
Indicates when the next bullet can fired at the earliest. |
private static double |
MAX_VELOCITY
The maximum velocity of the ship. |
private long |
newAppears
Indicates when a 'new' ship appears after the ship has exploded. |
private static int |
NUM_OF_BULLETS
The number of bullets this ship can have flying at a time. |
private static int |
NUM_OF_VERTICES
A constant indicating the number of vertices in the ship polygon. |
private int |
outlineColor
the outline color as an index to SpatialObject.COLOR_TABLE |
private boolean |
thrustOn
Indicates whether the ship is thrusting. |
private Point2D[] |
translatableVertices
An array holding the translated copies of the vertices ship polygon. |
private static int |
TURN_CCW
A constant for indicating that the ship is turning counter-clockwise. |
private static int |
TURN_CW
A constant for indicating that the ship is turning clockwise. |
private static int |
TURN_NO
A constant for indicating that the ship is not turning. |
private int |
turning
Indicates turning state of the ship. |
private Point2D[] |
vertices
An array holding the untranslated vertices of the ship polygon. |
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 | |
SpaceShip(double locationX,
double locationY,
long timestamp)
Contructs a new SpaceShip |
Method Summary | |
void |
explode(long newAppears)
Makes the ship explode. |
void |
fireBullet(long time)
Fires a bullet and marks it fired at time . |
Bullet[] |
getBullets()
Returns the Bullet array of this ship. |
Color |
getOutlineColor()
Returns the outline color of the ship. |
Shape |
getTransformedShape(long time)
Returns a properly transformed Shape representing
the spatial object at time |
Point2D[] |
getVertices(long time)
Returns the vertices of the ship polygon at time . |
private void |
init()
Does real ship initialization. |
private void |
readObject(ObjectInputStream in)
Deserializes the ship on the client side. |
void |
registerConnector(ClientModelConnector connector)
Registers a ClientModelConnector with the ship for
sending ship state to the server. |
void |
setStateFromRemote(double locationX,
double locationY,
double velocityX,
double velocityY,
double angle,
long timestamp)
Sets the state of the ship to values received from the network. |
void |
startThrust(long time)
Starts thrusting. |
void |
startTurnCCW(long time)
Starts turning counter-clockwise. |
void |
startTurnCW(long time)
Starts turning clockwise. |
void |
stopThrust(long time)
Stops thrusting. |
void |
stopTurnCCW(long time)
Stops turning counter-clockwise. |
void |
stopTurnCW(long time)
Stops turning clockwise. |
void |
updateState(long time)
Updates the state of this ship to the values corresponding to a moment in time given as the argument. |
private void |
updateTransformation(long time)
A helper method for updating the transormation. |
private void |
writeObject(ObjectOutputStream out)
Serializes the ship for sending to the clients. |
void |
writeToConnector()
Writes the state of ship to the registered ClientModelConnector |
Methods inherited from class dualroids.SpatialObject |
moveToRangeX, moveToRangeY |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static final int NUM_OF_VERTICES
private static final int NUM_OF_BULLETS
private static final int TURN_NO
private static final int TURN_CCW
private static final int TURN_CW
private static final double ANGULAR_VELOCITY
private static final double DEBRIS_ANGULAR_VELOCITY
private static final double ACCELERATION
private static final double MAX_VELOCITY
private static final long BULLET_INTERVAL
private static final float DEBRIS_VELOCITY_FACTOR
private static final float COLOR_STEP
private static final float[] DEBRIS_POINTS
private static final float[] CENTER_POINTS
private double angle
timestamp
.private transient Point2D[] vertices
private transient Point2D[] translatableVertices
private transient Bullet[] bullets
private transient int bulletFireIndex
private transient long earliestNextBullet
private transient ClientModelConnector connector
ClientModelConnector
through
which this ship can send its state to the server.private transient long newAppears
private transient boolean thrustOn
private transient int turning
private transient int outlineColor
SpatialObject.COLOR_TABLE
Constructor Detail |
public SpaceShip(double locationX, double locationY, long timestamp)
SpaceShip
Method Detail |
private final void updateTransformation(long time)
time
- the point of time for which the transformation
is needed.public final Point2D[] getVertices(long time)
time
.
The caller should not write to the returned array.time
- the point of time for which the vertices
are needed.public final Shape getTransformedShape(long time)
Shape
representing
the spatial object at time
getTransformedShape
in class SpatialObject
time
- the moment in game (server) time for which the
representation is requestedShape
representation at time
or null if the object isn't visibleprivate void init()
public final void fireBullet(long time)
time
.time
- when the bullet was firedpublic final void registerConnector(ClientModelConnector connector)
ClientModelConnector
with the ship for
sending ship state to the server. Used only for the ship
controlled by the client itself.connector
- the ClientModelConnector
to be
registeredpublic final Bullet[] getBullets()
Bullet
array of this ship. The caller
should not write to the array.Bullet
array of this shippublic final Color getOutlineColor()
public final void explode(long newAppears)
newAppears
- when the new ship appearspublic final void updateState(long time)
time
- the new timestamppublic final void startThrust(long time)
time
- when the thrusting was startedpublic final void stopThrust(long time)
time
- when the thrusting was stoppedpublic final void startTurnCCW(long time)
time
- when the turning was startedpublic final void stopTurnCCW(long time)
time
- when the turning was stoppedpublic final void startTurnCW(long time)
time
- when the turning was startedpublic final void stopTurnCW(long time)
time
- when the turning was stoppedpublic final void setStateFromRemote(double locationX, double locationY, double velocityX, double velocityY, double angle, long timestamp)
locationX
- the x coordinate of the space shiplocationY
- the y coordinate of the space shipvelocityX
- the x component of the velocity of the space shipvelocityY
- the y component of the velocity of the space shipangle
- the rotational angle of the space shiptimestamp
- the timestamppublic final void writeToConnector()
ClientModelConnector
private void writeObject(ObjectOutputStream out) throws IOException
out
- the target streamprivate void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
in
- the source stream
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Dualroids was written by Oskar Ojala, Yrjö Kari-Koskinen and Henri Sivonen