public A_Star(TileInfo[,] ColMap, int _hWeight) { hWeight = _hWeight; colMap = ColMap; Path = new List<Vector2>(); Width = colMap.GetLength(0); Height = colMap.GetLength(1); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here // Create the tile objects in the array for (int x = 0; x < tileInfo.GetLength(0); x++) { for (int y = 0; y < tileInfo.GetLength(0); y++) { tileInfo[x, y] = new TileInfo(); } } // Change some tiles to walls tileInfo[4, 0].tileType = TileInfo.TileType.Wall; tileInfo[4, 1].tileType = TileInfo.TileType.Wall; tileInfo[4, 2].tileType = TileInfo.TileType.Wall; tileInfo[4, 3].tileType = TileInfo.TileType.Wall; tileInfo[4, 4].tileType = TileInfo.TileType.Wall; tileInfo[4, 5].tileType = TileInfo.TileType.Wall; tileInfo[3, 5].tileType = TileInfo.TileType.Wall; tileInfo[2, 5].tileType = TileInfo.TileType.Wall; tileInfo[1, 5].tileType = TileInfo.TileType.Wall; tileInfo[1, 4].tileType = TileInfo.TileType.Wall; tileInfo[1, 3].tileType = TileInfo.TileType.Wall; tileInfo[1, 2].tileType = TileInfo.TileType.Wall; tileInfo[7, 6].tileType = TileInfo.TileType.Wall; tileInfo[7, 7].tileType = TileInfo.TileType.Wall; tileInfo[7, 8].tileType = TileInfo.TileType.Wall; tileInfo[7, 9].tileType = TileInfo.TileType.Wall; // Pass the tile information and a weight for the H // the lower the H weight value shorter the path // the higher it is the less number of checks it take to determine // a path a_star = new A_Star(tileInfo, 100); a_star.start(startLoc.X, startLoc.Y, endLoc.X, endLoc.Y); base.Initialize(); }