com.brackeen.javagamebook.game
Class GameObject

java.lang.Object
  extended bycom.brackeen.javagamebook.game.GameObject
Direct Known Subclasses:
Bot, JumpingGameObject, PathBot, Projectile

public class GameObject
extends java.lang.Object

A GameObject class is a base class for any type of object in a game that is represented by a PolygonGroup. For example, a GameObject can be a static object (like a crate), a moving object (like a projectile or a bad guy), or any other type of object (like a power-ups). GameObjects have three basic states: STATE_IDLE, STATE_ACTIVE, or STATE_DESTROYED.


Field Summary
static int STATE_ACTIVE
          Represents a GameObject that is active.
static int STATE_DESTROYED
          Represents a GameObject that has been destroyed, and should no longer be updated or drawn.
static int STATE_IDLE
          Represents a GameObject that is idle.
 
Constructor Summary
GameObject(PolygonGroup polygonGroup)
          Creates a new GameObject represented by the specified PolygonGroup.
 
Method Summary
 void addListener(GameObjectEventListener l)
          Adds a GameObjectEventListener to this object.
 PolygonGroupBounds getBounds()
          Gets the bounds of this object's PolygonGroup.
 float getCeilHeight()
          Gets the ceiling height set in the setCeilHeight method.
 float getFloorHeight()
          Gets the floor height set in the setFloorHeight method.
 GameObjectEventListener getListener()
          Gets the GameObjectEventListener for this object.
 Vector3D getLocation()
          Shortcut to get the location of this GameObject from the Transform3D.
 java.lang.String getName()
          Gets the name of this object's PolygonGroup.
 PolygonGroup getPolygonGroup()
          Gets this object's PolygonGroup.
 java.util.List getSpawns()
          Returns a list of "spawned" objects (projectiles, exploding parts, etc) or null if no objects were spawned.
 MovingTransform3D getTransform()
          Gets this object's transform.
 float getX()
          Shortcut to get the X location of this GameObject.
 float getY()
          Shortcut to get the Y location of this GameObject.
 float getZ()
          Shortcut to get the Z location of this GameObject.
 boolean isActive()
          Returns true if this GameObject is active.
 boolean isDestroyed()
          Returns true if this GameObject is destroyed.
 boolean isFlying()
          Checks if this GameObject is currently flying.
 boolean isIdle()
          Returns true if this GameObject is idle.
 boolean isJumping()
          Checks if this GameObject's jumping flag is set.
 boolean isMakingNoise()
          Returns true if this object is making a "noise".
 void makeNoise(long duration)
          Signifies that this object is making a "noise" of the specified duration.
 void removeListener(GameObjectEventListener l)
          Removes a GameObjectEventListener from this object.
 void sendTouchNotifications()
          After this object has moved and collisions have been checked, this method is called to send any touch/release notifications.
 void setCeilHeight(float ceilHeight)
          Method to record the height of the ceiling that this GameObject is under.
 void setFloorHeight(float floorHeight)
          Method to record the height of the floor that this GameObject is on.
 void setFlying(boolean isFlying)
          Sets whether this GameObject is currently flying.
 void setJumping(boolean b)
          Sets this GameObject's jumping flag.
 void setState(int state)
          Sets the state of this object.
 void update(GameObject player, long elapsedTime)
          If this GameObject is in the active state, this method updates it's PolygonGroup.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_IDLE

public static final int STATE_IDLE
Represents a GameObject that is idle. If the object is idle, it's Transform3D is not updated. By default, GameObjects are initially idle and are changed to the active state when they are initially visible. This behavior can be changed by overriding the notifyVisible() method.

See Also:
Constant Field Values

STATE_ACTIVE

public static final int STATE_ACTIVE
Represents a GameObject that is active. should no longer be updated or drawn. Once in the STATE_DESTROYED state, the GameObjectManager should remove this object from the list of GameObject it manages.

See Also:
Constant Field Values

STATE_DESTROYED

public static final int STATE_DESTROYED
Represents a GameObject that has been destroyed, and should no longer be updated or drawn. Once in the STATE_DESTROYED state, the GameObjectManager should remove this object from the list of GameObject it manages.

See Also:
Constant Field Values
Constructor Detail

GameObject

public GameObject(PolygonGroup polygonGroup)
Creates a new GameObject represented by the specified PolygonGroup. The PolygonGroup can be null.

Method Detail

getLocation

public Vector3D getLocation()
Shortcut to get the location of this GameObject from the Transform3D.


getTransform

public MovingTransform3D getTransform()
Gets this object's transform.


getPolygonGroup

public PolygonGroup getPolygonGroup()
Gets this object's PolygonGroup.


getName

public java.lang.String getName()
Gets the name of this object's PolygonGroup.


getBounds

public PolygonGroupBounds getBounds()
Gets the bounds of this object's PolygonGroup.


getX

public float getX()
Shortcut to get the X location of this GameObject.


getY

public float getY()
Shortcut to get the Y location of this GameObject.


getZ

public float getZ()
Shortcut to get the Z location of this GameObject.


setFloorHeight

public void setFloorHeight(float floorHeight)
Method to record the height of the floor that this GameObject is on.


setCeilHeight

public void setCeilHeight(float ceilHeight)
Method to record the height of the ceiling that this GameObject is under.


getFloorHeight

public float getFloorHeight()
Gets the floor height set in the setFloorHeight method.


getCeilHeight

public float getCeilHeight()
Gets the ceiling height set in the setCeilHeight method.


setState

public void setState(int state)
Sets the state of this object. Should be either STATE_IDLE, STATE_ACTIVE, or STATE_DESTROYED.


isFlying

public boolean isFlying()
Checks if this GameObject is currently flying. Flying objects should not has gravity applied to them.


setFlying

public void setFlying(boolean isFlying)
Sets whether this GameObject is currently flying. Flying objects should not has gravity applied to them.


isJumping

public boolean isJumping()
Checks if this GameObject's jumping flag is set. The GameObjectManager may treat the object differently if it is jumping.


setJumping

public void setJumping(boolean b)
Sets this GameObject's jumping flag. The GameObjectManager may treat the object differently if it is jumping.


isIdle

public boolean isIdle()
Returns true if this GameObject is idle.


isActive

public boolean isActive()
Returns true if this GameObject is active.


isDestroyed

public boolean isDestroyed()
Returns true if this GameObject is destroyed.


isMakingNoise

public boolean isMakingNoise()
Returns true if this object is making a "noise".


makeNoise

public void makeNoise(long duration)
Signifies that this object is making a "noise" of the specified duration. This is useful to determine if one object can "hear" another.


getSpawns

public java.util.List getSpawns()
Returns a list of "spawned" objects (projectiles, exploding parts, etc) or null if no objects were spawned.


update

public void update(GameObject player,
                   long elapsedTime)
If this GameObject is in the active state, this method updates it's PolygonGroup. Otherwise, this method does nothing.


getListener

public GameObjectEventListener getListener()
Gets the GameObjectEventListener for this object.


addListener

public void addListener(GameObjectEventListener l)
Adds a GameObjectEventListener to this object.


removeListener

public void removeListener(GameObjectEventListener l)
Removes a GameObjectEventListener from this object.


sendTouchNotifications

public void sendTouchNotifications()
After this object has moved and collisions have been checked, this method is called to send any touch/release notifications.