topical media & game development 
  
 
 
 
 
  
    
    
  
lib-flex-animation-code-04-Grid.ax
lib-flex-animation-code-04-Grid.ax
(swf
) 
[ flash
]
flex
  package
  {
          
 Holds a two-dimensional array of Nodes methods to manipulate them, start node and end node for finding a path.
  
          public class @ax-lib-flex-animation-code-04-Grid
          {
                  private var _startNode:Node;
                  private var _endNode:Node;
                  private var _nodes:Array;
                  private var _numCols:int;
                  private var _numRows:int;
                  
                  
 Constructor.
  
                  public function @ax-lib-flex-animation-code-04-Grid(numCols:int, numRows:int)
                  {
                          _numCols = numCols;
                          _numRows = numRows;
                          _nodes = new Array();
                          
                          for(var i:int = 0; i < _numCols; i++)
                          {
                                  _nodes[i] = new Array();
                                  for(var j:int = 0; j < _numRows; j++)
                                  {
                                          _nodes[i][j] = new Node(i, j);
                                  }
                          }
                  }
                  
                  
  ////////////////////////////////
                  // public methods
  ////////////////////////////////
                  
                  
 Returns the node at the given coords.
	 parameter:  x The x coord.
	 parameter:  y The y coord.
  
                  public function getNode(x:int, y:int):Node
                  {
                          return _nodes[x][y] as Node;
                  }
                  
                  
 Sets the node at the given coords as the end node.
	 parameter:  x The x coord.
	 parameter:  y The y coord.
  
                  public function setEndNode(x:int, y:int):void
                  {
                          _endNode = _nodes[x][y] as Node;
                  }
                  
                  
 Sets the node at the given coords as the start node.
	 parameter:  x The x coord.
	 parameter:  y The y coord.
  
                  public function setStartNode(x:int, y:int):void
                  {
                          _startNode = _nodes[x][y] as Node;
                  }
                  
                  
 Sets the node at the given coords as walkable or not.
	 parameter:  x The x coord.
	 parameter:  y The y coord.
  
                  public function setWalkable(x:int, y:int, value:Boolean):void
                  {
                          _nodes[x][y].walkable = value;
                  }
                  
                  
                  
  ////////////////////////////////
                  // getters / setters
  ////////////////////////////////
                  
                  
 Returns the end node.
  
                  public function get endNode():Node
                  {
                          return _endNode;
                  }
                  
                  
 Returns the number of columns in the grid.
  
                  public function get numCols():int
                  {
                          return _numCols;
                  }
                  
                  
 Returns the number of rows in the grid.
  
                  public function get numRows():int
                  {
                          return _numRows;
                  }
                  
                  
 Returns the start node.
  
                  public function get startNode():Node
                  {
                          return _startNode;
                  }
                  
          }
  }
  
  
(C) Æliens 
18/6/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. 
In case of other copyright issues, contact the author.