|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--objects.DrawableGameObject
Superclass for game objects that are visible on the game board.
Note that some of the subclasses may not use all of the functionality
in this class: Stars, for instance, have no direction, and ships
have no ID (the ship ID is in the Player
object.
This class doesn't know how to draw objects, so that's left
to the subclass to do by overriding the abstract draw
method.
NOTE! On the client side, all fields are not necessarily updated. It is for instance not possible to query the direction of a bomb. Or more correctly, you may query it, but you won't get the correct answer, as the server doesn't send it to us. Consult the documentation for the object you work with to see what is supported.
Field Summary | |
protected java.awt.Rectangle |
bounds
|
protected double |
dir
|
protected java.awt.Point |
loc
|
Constructor Summary | |
DrawableGameObject()
Constructor for object that doesn't need all the functionality the other constructors provide. |
|
DrawableGameObject(short id,
int x,
int y,
double dir)
Constructs a new drawable game object, with the given initial settings. |
|
DrawableGameObject(short id,
int x,
int y,
short dir)
Constructs a new drawable game object. |
Method Summary | |
abstract void |
draw(java.awt.Graphics g)
Draws the object in the given graphic context. |
java.awt.Rectangle |
getBounds()
Gets the current bounding box for this object. |
double |
getDirection()
Returns the direction of this object in radians. |
short |
getDirectionAsShort()
Returns the direction of this object in radians, encoded in a short for transfer to the game server. |
short |
getId()
Fetches the ID of this object. |
java.awt.Point |
getLocation()
|
void |
setDirection(double angle)
Sets the direction of this object as an angle in radians. |
void |
setDirectionFromShort(short angle)
Sets the direction of this object, encoded as a short, as sent from the game server. |
void |
setId(short id)
Sets the ID of this object. |
void |
setLocation(int x,
int y)
Sets the location of this object within the world. |
void |
setLocation(java.awt.Point loc)
Sets the location of this object within the world. |
protected void |
updateBounds()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.awt.Point loc
protected double dir
protected java.awt.Rectangle bounds
Constructor Detail |
public DrawableGameObject()
public DrawableGameObject(short id, int x, int y, double dir)
id
- the ID of this object.x
- x-coordinate in the world.y
- y-coordinate.dir
- direction angle in radians.public DrawableGameObject(short id, int x, int y, short dir)
short
to save some bandwidth.
id
- the ID of this object.x
- x-coordinate in the world.y
- y-coordinate.dir
- direction encoded as a short
.Method Detail |
protected void updateBounds()
public final void setId(short id)
id
- the ID of this object.public final short getId()
public void setLocation(java.awt.Point loc)
loc
- the location.public void setLocation(int x, int y)
x
- the x-coordinate.y
- the y-coordinate.public java.awt.Point getLocation()
DrawableGameObject
public final void setDirection(double angle)
angle
- the angle in radians.public final double getDirection()
public final void setDirectionFromShort(short angle)
angle
- the angle encoded as a short.public final short getDirectionAsShort()
public final java.awt.Rectangle getBounds()
public abstract void draw(java.awt.Graphics g)
Image
with the size of the entire world,
so the drawing routine doesn't need to displace it's coordinates.
g
- the graphic context.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |