objects
Class DrawableGameObject

java.lang.Object
  |
  +--objects.DrawableGameObject
Direct Known Subclasses:
Bomb, BombPack, Explosion, Phaser, Ship, Star

public abstract class DrawableGameObject
extends java.lang.Object

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.

Author:
Sverre H. Huseby <shh@thathost.com>

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

loc

protected java.awt.Point loc

dir

protected double dir

bounds

protected java.awt.Rectangle bounds
Constructor Detail

DrawableGameObject

public DrawableGameObject()
Constructor for object that doesn't need all the functionality the other constructors provide.


DrawableGameObject

public DrawableGameObject(short id,
                          int x,
                          int y,
                          double dir)
Constructs a new drawable game object, with the given initial settings. Also updates the bounding box of the object.

Parameters:
id - the ID of this object.
x - x-coordinate in the world.
y - y-coordinate.
dir - direction angle in radians.

DrawableGameObject

public DrawableGameObject(short id,
                          int x,
                          int y,
                          short dir)
Constructs a new drawable game object. This is used for objects that are created on server demand, as the server sends the direction encoded as a short to save some bandwidth.

Parameters:
id - the ID of this object.
x - x-coordinate in the world.
y - y-coordinate.
dir - direction encoded as a short.
Method Detail

updateBounds

protected void updateBounds()

setId

public final void setId(short id)
Sets the ID of this object. The ID is used for identifying objects when talking to the server.

Parameters:
id - the ID of this object.

getId

public final short getId()
Fetches the ID of this object. The ID is used for identifying objects when talking to the server.

Returns:
the ID of this object.

setLocation

public void setLocation(java.awt.Point loc)
Sets the location of this object within the world.

Parameters:
loc - the location.

setLocation

public void setLocation(int x,
                        int y)
Sets the location of this object within the world.

Parameters:
x - the x-coordinate.
y - the y-coordinate.

getLocation

public java.awt.Point getLocation()
See Also:
DrawableGameObject

setDirection

public final void setDirection(double angle)
Sets the direction of this object as an angle in radians.

Parameters:
angle - the angle in radians.

getDirection

public final double getDirection()
Returns the direction of this object in radians.

Returns:
the direction.

setDirectionFromShort

public final void setDirectionFromShort(short angle)
Sets the direction of this object, encoded as a short, as sent from the game server.

Parameters:
angle - the angle encoded as a short.

getDirectionAsShort

public final short getDirectionAsShort()
Returns the direction of this object in radians, encoded in a short for transfer to the game server.

Returns:
the direction.

getBounds

public final java.awt.Rectangle getBounds()
Gets the current bounding box for this object.

Returns:
the bouning box.

draw

public abstract void draw(java.awt.Graphics g)
Draws the object in the given graphic context. The graphic context controls an Image with the size of the entire world, so the drawing routine doesn't need to displace it's coordinates.

Parameters:
g - the graphic context.