Exemple #1
0
 /// <summary>
 /// Creates a SquareGraph of the tilemap
 /// </summary>
 /// <param name="gidToCost">an array representing the cost to traverse each gid in the tilemap</param>
 /// <returns>A SquareGraph representing the tilemap</returns>
 public SquareGraph CreateSquareGraph(int[] gidToCost)
 {
     List<SquareGraphNode> nodes = new List<SquareGraphNode>();
     for (int z = 0; z < layerGidMaps.Count; z++)
     {
         for (int y = 0; y < Height; y++)
         {
             for (int x = 0; x < Width; x++)
             {
                 var Gid = layerGidMaps[z][y, x];
                 if(Gid < 0) continue;
                 SquareGraphNode node = new SquareGraphNode(x, y, z, gidToCost[Gid]);
                 if (node.Cost == 0)//Only node with 0 cost are the z-traversals
                 {
                     //last gid available is down->up, last-1 is up->down
                     if (layerGidMaps[z][y, x] == gidToCost.Length - 1)
                     {
                         node.HasConnectionUpwards = true;
                     }
                     else
                     {
                         node.HasConnectionDownwards = true;
                     }
                 }
                 if (node.Cost != int.MaxValue)
                     nodes.Add(node);
             }
         }
     }
     return new SquareGraph(Width, Height, TileWidth, TileHeight, nodes);
 }
Exemple #2
0
 /// <summary>
 /// Creates a SquareGraph of the tilemap
 /// </summary>
 /// <param name="gidToCost">A list representing the cost to traverse each gid in the tilemap</param>
 /// <returns>A SquareGraph representing the tilemap</returns>
 public SquareGraph CreateSquareGraph(List<int> gidToCost)
 {
     List<SquareGraphNode> nodes = new List<SquareGraphNode>();
     for (int z = 0; z < layerGidMaps.Count; z++)
     {
         for (int y = 0; y < Height; y++)
         {
             for (int x = 0; x < Width; x++)
             {
                 SquareGraphNode node = new SquareGraphNode(x, y, z, gidToCost[layerGidMaps[z][y, x]]);
                 if(node.Cost == 0)//Only node with 0 cost are the z-traversals
                 {
                     //last gid available is down->up, last-1 is up->down
                     if(layerGidMaps[z][y, x] == gidToCost.Count - 1)
                     {
                         node.HasConnectionUpwards = true;
                     }
                     else
                     {
                         node.HasConnectionDownwards = true;
                     }
                 }
                 //if the cost of the node is the max value of an int, don't add it in.
                 if(node.Cost != int.MaxValue)
                     nodes.Add(node);
             }
         }
     }
     return new SquareGraph(Width, Height, TileWidth, TileHeight, nodes);
 }