public override void Initialize() { GridCount = new Vector2(32, 32); CreepEnd = new Vector2(GridCount.X - 1, 15); LevelGrid = new byte[(int)GridCount.X, (int)GridCount.Y]; Background = CurrGame.SpriteBatch; GridSize.X = CurrGame.CreepFieldWidth / GridCount.X; GridSize.Y = CurrGame.CreepFieldHeight / GridCount.Y; ResetLevel(); WallTex = CurrGame.Content.Load <Texture2D>("Tower\\Textures\\Wall"); Origin = Vector2.Zero; Size = new Vector2(GridSize.X, GridSize.Y); Scale = new Vector2(Size.X / WallTex.Width, Size.Y / WallTex.Height); LoadLevel(); EndPositions = WaveManager.GenerateRandomList(32); PathFinder = new PathFinder(LevelGrid) { Diagonals = false, HeuristicEstimate = 100, SearchLimit = 99999 }; base.Initialize(); }
public Queue <Vector2> FindPath(Vector2 start) { var tmpList = new Queue <Vector2>(); CreepEnd = new Vector2(GridCount.X - 1, EndPositions.Dequeue()); if (EndPositions.Count == 0) { EndPositions = WaveManager.GenerateRandomList(32); } List <PathFinderNode> pathList = PathFinder.FindPath(start, CreepEnd); if (pathList != null) { for (int i = pathList.Count - 1; i >= 0; i--) { PathFinderNode node = pathList[i]; tmpList.Enqueue(new Vector2(node.X, node.Y)); } } return(tmpList); }