public void Start() { var generator = new RoomMazeGenerator(); this.Map = generator.Generate(new RoomMazeGenerator.Settings { Width = 21, Height = 21, MinRoomSize = 5, MaxRoomSize = 9, }); this.Astar = new VectorGridGraph(Map.Regions.GetLength(0), Map.Regions.GetLength(1)); for (var x = 0; x < Map.Regions.GetLength(0); x++) { for (var y = 0; y < Map.Regions.GetLength(1); y++) { if (!Map.Regions[x, y].HasValue) { this.Astar.Walls.Add(new Vector2(x, y)); } } } Connect("Bot1"); }
public static void StartNewGame(GameStateComponent gameState) { gameState.AtEnd.Clear(); var maze = new RoomMazeGenerator().Generate(new RoomMazeGenerator.Settings { Width = 71, Height = 41, AdditionalPassages = 20, WindingPercent = 50, RoomSize = 3 }); gameState.Map = new RegionValue[maze.Regions.GetLength(0), maze.Regions.GetLength(1)]; gameState.Doors.Clear(); for (var i = 0; i < maze.Junctions.Count; i++) { gameState.Doors.Add(new Point(maze.Junctions[i].X, maze.Junctions[i].Y)); } for (var x = 0; x < gameState.Map.GetLength(0); x++) { for (var y = 0; y < gameState.Map.GetLength(1); y++) { gameState.Map[x, y] = maze.Regions[x, y] == null ? RegionValue.Wall : RegionValue.Path; } } var roomIdx = 0; foreach (var player in gameState.Players) { var room = maze.Rooms[roomIdx]; roomIdx++; player.Value.Units[0].Position = new Point(room.X + room.Width / 2 - 1, room.Y + room.Height / 2); player.Value.Units[1].Position = new Point(room.X + room.Width / 2 + 1, room.Y + room.Height / 2); player.Value.Units[2].Position = new Point(room.X + room.Width / 2, room.Y + room.Height / 2 - 1); player.Value.Units[3].Position = new Point(room.X + room.Width / 2, room.Y + room.Height / 2 + 1); player.Value.LevelScore = 0; for (var i = 0; i < player.Value.Units.Count; i++) { player.Value.Units[i].Hp = player.Value.Units[i].MaxHp; } } gameState.Exit = new Point(maze.Rooms[maze.Rooms.Count - 1].X + maze.Rooms[maze.Rooms.Count - 1].Width / 2, maze.Rooms[maze.Rooms.Count - 1].Y + maze.Rooms[maze.Rooms.Count - 1].Height / 2); }