de.rico.engine.path
Class GridNode

java.lang.Object
  extended by de.rico.engine.path.AStarNode
      extended by de.rico.engine.path.GridNode
All Implemented Interfaces:
java.lang.Comparable

public class GridNode
extends AStarNode

Node that represents a square in the walkable area grid. This node is then used for A* path finding.

Author:
Frank Bruns

Constructor Summary
GridNode(int id, float x, float z, int width, int length)
          Creates a new grid node with the specified parameters
 
Method Summary
 void addNeighbor(GridNode node)
          Adds a neighbour to the list of neighbours of this grid node
 boolean containsPoint(float x, float z)
          Checks, if the specified coordinates lay in this grid node's bounds
 float getCost(AStarNode node)
          Gets the cost between this node and the specified adjacent (aka "neighbor" or "child") node.
 float getEstimatedCost(AStarNode node)
          Gets the estimated cost between this node and the specified node.
 int getId()
          Returns the id of this grid node.
 int getLength()
          Returns the length of the grid node
 float getMidX()
          Returns the x coordinate of the center point of the grid node
 float getMidZ()
          Returns the z coordinate of the center point of the grid node
 java.util.List<GridNode> getNeighbors()
          Gets the children (aka "neighbors" or "adjacent nodes") of this node.
 int getWidth()
          Returns the width of the grid node
 float getX()
          Returns the x coordinate of the grid node
 float getZ()
          Returns the z coordinate of the grid node
 boolean isNeighbor(GridNode node)
          Determines whether the grid node is a neighbour of the specified node.
 boolean isWalkable()
          Determines whether the grid node is walkable
 void setWalkable(boolean walkable)
          Sets the walkable status for the grid node
 
Methods inherited from class de.rico.engine.path.AStarNode
compareTo, getCost, sign
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridNode

public GridNode(int id,
                float x,
                float z,
                int width,
                int length)
Creates a new grid node with the specified parameters

Parameters:
id - a number that uniquely identifies the grid node. This is important for saving and loading the grid node status to the editor file
x - x coordinate of the grid node
z - z coordinate of the grid node
width - width of the grid node
length - height of the grid node
Method Detail

getId

public int getId()
Returns the id of this grid node.

Returns:
id of the grid node

setWalkable

public void setWalkable(boolean walkable)
Sets the walkable status for the grid node

Parameters:
walkable - set walkable? --> true=yes, false=no

getMidX

public float getMidX()
Returns the x coordinate of the center point of the grid node

Returns:
center point's x coordinate

getMidZ

public float getMidZ()
Returns the z coordinate of the center point of the grid node

Returns:
center point's z coordinate

containsPoint

public boolean containsPoint(float x,
                             float z)
Checks, if the specified coordinates lay in this grid node's bounds

Parameters:
x - x coordinates
z - z coordinates
Returns:
are coordinates within grid node's bounds? --> true=yes, false=no

isNeighbor

public boolean isNeighbor(GridNode node)
Determines whether the grid node is a neighbour of the specified node.

Parameters:
node - node to check, if naighbour
Returns:
is neighbour? --> true=yes, false=no

getLength

public int getLength()
Returns the length of the grid node

Returns:
length of the grid node

getWidth

public int getWidth()
Returns the width of the grid node

Returns:
width of the grid node

getX

public float getX()
Returns the x coordinate of the grid node

Returns:
x coordinate of the grid node

getZ

public float getZ()
Returns the z coordinate of the grid node

Returns:
z coordinate of the grid node

isWalkable

public boolean isWalkable()
Determines whether the grid node is walkable

Returns:
is grid node walkable? --> true=yes, false=no

addNeighbor

public void addNeighbor(GridNode node)
Adds a neighbour to the list of neighbours of this grid node

Parameters:
node - grid node neighbour node to add

getCost

public float getCost(AStarNode node)
Description copied from class: AStarNode
Gets the cost between this node and the specified adjacent (aka "neighbor" or "child") node.

Specified by:
getCost in class AStarNode

getEstimatedCost

public float getEstimatedCost(AStarNode node)
Description copied from class: AStarNode
Gets the estimated cost between this node and the specified node. The estimated cost should never exceed the true cost. The better the estimate, the more effecient the search.

Specified by:
getEstimatedCost in class AStarNode

getNeighbors

public java.util.List<GridNode> getNeighbors()
Description copied from class: AStarNode
Gets the children (aka "neighbors" or "adjacent nodes") of this node.

Specified by:
getNeighbors in class AStarNode