|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--dualroids.SpatialObject | +--dualroids.Asteroid
The representation of an asteroid in the model.
The length of the asteroid table is required to be a multiple
of 7. The first large asteroid is at index 0
. The
second is at 7
, etc.
When a large asteroid is at index i
, its residual
medium-sized asteroids are at indeces i + 1
and
i + 4
.
When a medium-sized asteroid is at index i
, its
residual small asteroids are at indeces i + 1
and
i + 2
.
The setters of an Asteroid
may be used from
multiple threads. Also, the getters may be used from
a single thread safely even when there are other
thread using the setters. 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.
Field Summary | |
private double |
angle
The rotation angle (in radians) of the spatial object at the moment indicated by timestamp . |
private double |
angularVelocity
The angular velocity (radians per millisecond) of the asteroid. |
private float[] |
centers
An array for storing the coordinates of the centers of the edges of this asteroid. |
static float |
COLOR_STEP
The amount of time used for one outline color in an explosion. |
static float |
DEBRIS_LIFETIME
The lifetime of asteroid debris. |
static float |
DEBRIS_VELOCITY_FACTOR
Constant used when calculating the movement of asteroid debris. |
private boolean |
exploding
A boolean indicating whether the asteroid is currently exploding (that is, whether debris is visible). |
private int |
hitsToExplosion
The number of hits it takes to make this asteroid explode. |
static int |
LARGE
Constant for indicating that the asteroid is large |
static double |
LARGE_EXPLOSION_EXTRA
Constant used when modeling the extra energy released when a large asteroid explodes. |
static int |
MEDIUM
Constant for indicating that the asteroid is medium-sized |
static double |
MEDIUM_EXPLOSION_EXTRA
Constant used when modeling the extra energy released when a medium-sized asteroid explodes. |
private int |
outlineColor
the outline color as an index to SpatialObject.COLOR_TABLE |
private int |
points
|
private int |
size
The size of the asteroid. |
static int |
SMALL
Constant for indicating that the asteroid is small |
private float[] |
vertices
An array for storing the coordinates of the vertices of this asteroid. |
private boolean |
visible
A boolean indicating whether the asteroid is visible. |
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 | |
Asteroid(double locationX,
double locationY,
double velocityX,
double velocityY,
long timestamp,
int size)
Contructs a new asteroid. |
Method Summary | |
static void |
blowUpAsteroid(Asteroid[] asteroids,
int index,
double locationX,
double locationY,
long timestamp,
boolean onServer)
Makes an asteroid explode and initalizes the residual asteroids accordingly. |
void |
explode(long time)
Tells the asteroid to explode. |
void |
explodeOnServer()
Tells the asteroid to explode withou debris effects. |
static void |
generateResidualAsteroids(Asteroid[] asteroids)
Generates residual asteroids in the array of asteroids passed as the argument. |
double |
getLocationX(long time)
Returns the x coordinate of the location of the asteroid at time . |
double |
getLocationY(long time)
Returns the y coordinate of the location of the asteroid at time . |
Color |
getOutlineColor()
Returns the outline color of the asteroid. |
int |
getPoints()
Returns the points awarded for blowing up this asteroid. |
int |
getSize()
Indicates the size of the asteroid. |
Shape |
getTransformedShape(long time)
Returns a properly transformed Shape representing
the spatial object at time |
boolean |
isVisible()
Indicates whether the asteroid is visible. |
void |
makeVisible()
Makes the asteroid visible. |
private void |
readObject(ObjectInputStream in)
Deserializes the asteroid on the client side. |
boolean |
registerHit()
Registers a bullet hit to the asteroid and checks whether it explodes. |
void |
setLocationAndAngle(double locationX,
double locationY,
double angle,
long timestamp)
Sets the location and angle of this asteroid. |
void |
updateLocationAndAngle(long time)
Updates the location and angle of this asteroid to the values corresponding to a moment in time given as the argument. |
private void |
writeObject(ObjectOutputStream out)
Serializes the asteroid for sending to the clients. |
void |
writeToConnector(int thisIndex,
ServerModelConnector connector)
Writes the state of this asteroid to a ServerModelConnector . |
Methods inherited from class dualroids.SpatialObject |
moveToRangeX, moveToRangeY |
Methods inherited from class java.lang.Object |
|
Field Detail |
public static final int SMALL
public static final int MEDIUM
public static final int LARGE
public static final double LARGE_EXPLOSION_EXTRA
public static final double MEDIUM_EXPLOSION_EXTRA
public static final float DEBRIS_VELOCITY_FACTOR
public static final float DEBRIS_LIFETIME
public static final float COLOR_STEP
private transient int outlineColor
SpatialObject.COLOR_TABLE
private double angularVelocity
private int size
SMALL
, MEDIUM
or
LARGE
private boolean visible
private boolean exploding
private double angle
timestamp
.private transient int hitsToExplosion
private float[] vertices
AffineTransform
:
x0, y0, ... xn, yn.private transient int points
private transient float[] centers
AffineTransform
:
x0, y0, ... xn, yn.Constructor Detail |
public Asteroid(double locationX, double locationY, double velocityX, double velocityY, long timestamp, int size)
locationX
- the x coordinate of the initial locationlocationY
- the y coordinate of the initial locationvelocityX
- the x component of the velocityvelocityY
- the y component of the velocitytimestamp
- the moment in game (server) time for which the
location is validsize
- the size of the asteroid: SMALL
,
MEDIUM
or LARGE
Method Detail |
public static void generateResidualAsteroids(Asteroid[] asteroids)
asteroids
- the asteroid tablepublic static void blowUpAsteroid(Asteroid[] asteroids, int index, double locationX, double locationY, long timestamp, boolean onServer)
asteroids
- the asteroid tableindex
- the index of the asteroid to be blown uplocationX
- the x coordinate of the asteroid at the time of the
explosionlocationY
- the y coordinate of the asteroid at the time of the
explosiontimestamp
- the point in time when the explosion happensonServer
- a boolean indicating whether this method is called
from the server threadpublic 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 visiblepublic void setLocationAndAngle(double locationX, double locationY, double angle, long timestamp)
ClientModelController
.locationX
- the x coordinate of the new locationlocationY
- the y coordinate of the new locationangle
- the new angletimestamp
- the moment in game (server) time for which
at which the other values were valid.public void updateLocationAndAngle(long time)
time
- the new timestamppublic final void makeVisible()
setLocationAndAngle
first.public final void explode(long time)
time
- the point in time when the explosion startspublic void explodeOnServer()
public final boolean isVisible()
public boolean registerHit()
true
if the hit causes the asteroid to explode
and false
otherwisepublic final int getSize()
public final Color getOutlineColor()
public final double getLocationX(long time)
time
.time
- the point in time for which the x coordinate is requestedtime
public final double getLocationY(long time)
time
.time
- the point in time for which the y coordinate is requestedtime
public final int getPoints()
public final void writeToConnector(int thisIndex, ServerModelConnector connector)
ServerModelConnector
.thisIndex
- the index of this asteroidconnector
- the target ServerModelConnector
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