com.brackeen.javagamebook.game
Class GridGameObjectManager

java.lang.Object
  extended bycom.brackeen.javagamebook.game.GridGameObjectManager
All Implemented Interfaces:
GameObjectManager

public class GridGameObjectManager
extends java.lang.Object
implements GameObjectManager

The GridGameObjectManager is a GameObjectManager that integrally arranges GameObjects on a 2D grid for visibility determination and to limit the number of tests for collision detection.


Constructor Summary
GridGameObjectManager(java.awt.Rectangle mapBounds, CollisionDetection collisionDetection)
          Creates a new GridGameObjectManager with the specified map bounds and collision detection handler.
 
Method Summary
 void add(GameObject object)
          Adds a GameObject to this manager.
 void addPlayer(GameObject player)
          Adds a GameObject to this manager, specifying it as the player object.
 boolean checkObjectCollision(GameObject object, Vector3D oldLocation)
          Checks to see if the specified object collides with any other object.
 void draw(java.awt.Graphics2D g, GameObjectRenderer r)
          Draws all visible objects and marks all objects as not visible.
 GameObject getPlayer()
          Gets the object specified as the Player object, or null if no player object was specified.
 java.util.Iterator iterator()
          Gets an iterator of all GameObjects (including the player).
 void markAllVisible()
          Marks all objects as potentially visible (should be drawn).
 void markVisible(java.awt.Rectangle bounds)
          Marks all objects within the specified 2D bounds as potentially visible (should be drawn).
 void remove(GameObject object)
          Removes a GameObject from this manager.
 void update(long elapsedTime)
          Updates all objects based on the amount of time passed from the last update and applied collision detection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridGameObjectManager

public GridGameObjectManager(java.awt.Rectangle mapBounds,
                             CollisionDetection collisionDetection)
Creates a new GridGameObjectManager with the specified map bounds and collision detection handler. GameObjects outside the map bounds will never be shown.

Method Detail

markAllVisible

public void markAllVisible()
Marks all objects as potentially visible (should be drawn).

Specified by:
markAllVisible in interface GameObjectManager

markVisible

public void markVisible(java.awt.Rectangle bounds)
Marks all objects within the specified 2D bounds as potentially visible (should be drawn).

Specified by:
markVisible in interface GameObjectManager

iterator

public java.util.Iterator iterator()
Description copied from interface: GameObjectManager
Gets an iterator of all GameObjects (including the player).

Specified by:
iterator in interface GameObjectManager

add

public void add(GameObject object)
Adds a GameObject to this manager.

Specified by:
add in interface GameObjectManager

remove

public void remove(GameObject object)
Removes a GameObject from this manager.

Specified by:
remove in interface GameObjectManager

addPlayer

public void addPlayer(GameObject player)
Adds a GameObject to this manager, specifying it as the player object. An existing player object, if any, is not removed.

Specified by:
addPlayer in interface GameObjectManager

getPlayer

public GameObject getPlayer()
Gets the object specified as the Player object, or null if no player object was specified.

Specified by:
getPlayer in interface GameObjectManager

update

public void update(long elapsedTime)
Updates all objects based on the amount of time passed from the last update and applied collision detection.

Specified by:
update in interface GameObjectManager

checkObjectCollision

public boolean checkObjectCollision(GameObject object,
                                    Vector3D oldLocation)
Checks to see if the specified object collides with any other object.


draw

public void draw(java.awt.Graphics2D g,
                 GameObjectRenderer r)
Draws all visible objects and marks all objects as not visible.

Specified by:
draw in interface GameObjectManager