コード例 #1
0
 /// <summary>
 /// Create a new A* path.
 /// </summary>
 /// <param name="pathingGrid">The aStarGrid the path is on.</param>
 public AStarContext(PathingGrid pathingGrid)
 {
     _pathingGrid = pathingGrid;
     _openSet     = new HashSet <AStarNode>();
     _closedSet   = new HashSet <AStarNode>();
     _cache       = new Dictionary <int, AStarNode>();
 }
コード例 #2
0
ファイル: PathingGrid.cs プロジェクト: Cryru/Emotion
        /// <summary>
        /// Create a grid from a TileMap object.
        /// </summary>
        /// <param name="tileMap">The map to create the grid from.</param>
        /// <param name="layerId">The tile layer to create the grid from.</param>
        /// <param name="impassableTiles">The list of image ids considered impassable.</param>
        public static PathingGrid FromTileMap <T>(TileMap <T> tileMap, int layerId, int[] impassableTiles) where T : TransformRenderable
        {
            if (layerId == -1 || tileMap.TiledMap == null || layerId > tileMap.TiledMap.Layers.Count - 1)
            {
                return(null);
            }
            TmxLayer layer = tileMap.TiledMap.Layers[layerId];

            var newGrid = new PathingGrid(layer.Width, layer.Height, tileMap.TileSize);

            for (var x = 0; x < newGrid.Width; x++)
            {
                for (var y = 0; y < newGrid.Height; y++)
                {
                    int  tileId  = x + y * layer.Width;
                    int  imageId = tileMap.GetTileImageIdInLayer(tileId, layerId, out int _);
                    bool solid   = impassableTiles.IndexOf(imageId) != -1;
                    if (solid)
                    {
                        newGrid.SetWalkable(x, y, false);
                    }
                }
            }

            return(newGrid);
        }
コード例 #3
0
 /// <summary>
 /// Destroy, and free memory.
 /// </summary>
 public void Dispose()
 {
     _closedSet.Clear();
     _openSet.Clear();
     _cache.Clear();
     _closedSet   = null;
     _openSet     = null;
     _pathingGrid = null;
 }