Example #1
0
 public Path(GameLocation location, int width = -1, int height = -1)
 {
     if (width == -1)
     {
         width = location.map.GetLayer("Back").LayerWidth;
     }
     if (height == -1)
     {
         height = location.map.GetLayer("Back").LayerHeight;
     }
     this.location = location;
     this.width    = width;
     this.height   = height;
     grid          = new PathingGrid(location, width, height);
 }
Example #2
0
        public static float getWeight(Node node, PathingGrid grid)
        {
            float totalImpassableWeight = 0;

            if (node == null)
            {
                Logger.Log("Null node!");
                return(-1);
            }
            for (int x = node.x - distance; x < node.x + distance + 1; x++)
            {
                for (int y = node.y - distance; y < node.y + distance + 1; y++)
                {
                    if (x < 0 || x >= grid.width || y < 0 || y >= grid.height || !grid.getNode(x, y).traversible)
                    {
                        totalImpassableWeight += (distance) - (float)Math.Min(Math.Sqrt(Math.Pow(x - node.x, 2) + Math.Pow(y - node.y, 2)), (float)distance);
                    }
                }
            }
            return(totalImpassableWeight);
        }