/// <summary> /// This initializes a new map given a rectangle which has /// the starting X and Y locations of the player and the /// width and size of the map (not the room). /// </summary> /// <param name="init"></param> public void Initialize(Game game, Player playerReference, ContentManager Content, Rectangle init, Texture2D tileTexture, List <Texture2D> mapDebuggingTextures, RoomDatabase roomDatabaseReference, TileDatabase tileDatabaseReference) { gameReference = game; this.shadowTexture = Content.Load <Texture2D>("shadow"); this.playerReference = playerReference; mapDefinition = init; debugTextures = mapDebuggingTextures; this.roomDatabaseReference = roomDatabaseReference; // Generate rooms int width = init.Width; int height = init.Height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Room r = new Room(gameReference, x, y, shadowTexture, tileDatabaseReference, playerReference, tileTexture); listOfRooms.Add(r); #if !KRUSKAL r.Initialize(); #else kruskalRooms.Add(r); // In Kruskal's, each room has a set of their own. List <Room> list = new List <Room>(); list.Add(r); sets.Add(list); #endif } } // Generate maze int destination_x = random.Next(width); int destination_y = random.Next(height); endLocation.X = destination_x; endLocation.Y = destination_y; #if KRUSKAL generateMaze(); #else generateMaze(destination_x, destination_y, null); #endif }
/// <summary> /// This initializes a new map given a rectangle which has /// the starting X and Y locations of the player and the /// width and size of the map (not the room). /// </summary> /// <param name="init"></param> public void Initialize(Game game, Player playerReference, ContentManager Content, Rectangle init, Texture2D tileTexture, List<Texture2D> mapDebuggingTextures, RoomDatabase roomDatabaseReference, TileDatabase tileDatabaseReference) { gameReference = game; this.shadowTexture = Content.Load<Texture2D>("shadow"); this.playerReference = playerReference; mapDefinition = init; debugTextures = mapDebuggingTextures; this.roomDatabaseReference = roomDatabaseReference; // Generate rooms int width = init.Width; int height = init.Height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Room r = new Room(gameReference, x, y, shadowTexture, tileDatabaseReference, playerReference, tileTexture); listOfRooms.Add(r); #if !KRUSKAL r.Initialize(); #else kruskalRooms.Add(r); // In Kruskal's, each room has a set of their own. List<Room> list = new List<Room>(); list.Add(r); sets.Add(list); #endif } } // Generate maze int destination_x = random.Next(width); int destination_y = random.Next(height); endLocation.X = destination_x; endLocation.Y = destination_y; #if KRUSKAL generateMaze(); #else generateMaze(destination_x, destination_y, null); #endif }
// DFS Maze creation, fixed. // TODONT: Add corners for map generation. // Deprecated /** * 22, 22, 22, 22, 12% (deadend) chance. */ private void generateMaze(int x, int y, Room prev) { int roomType, roomRotation; Room current = getRoom(x, y); /** * BASE CASE END OF RECURSIVE ALGORITHM * * This checks if the room has already been * explored or if the room is out of bounds * from the map. */ if (exploredRooms.Contains(current)) { return; } if (current == null) { return; } /** * ROOM TYPE, ROTATION, DESIGN * * This handles the room generation with * regards to room type, rotation, and design */ do { if (prev == null) { roomRotation = random.Next(4); } else { roomRotation = (prev.getRotation() + 2) % 4; } current.setRotation(roomRotation); roomType = random.Next(4) + 2; current.setRoomType(roomType); } while (!areRoomsConnected(isToTheDirectionOf(current, prev), prev, current) || getAccessibleRooms(current).Count <= 0); int[,] roomDesign = roomDatabaseReference.getRoomDesign(roomType, roomRotation); if (roomDesign != null) { current.setRoomDesign(roomDesign); current.Initialize(); } else { // TODONT: Must use room designer java application to create corners. // Deprecated. Corner rooms are done already. throw new Exception("Undefined Room Design Exception!"); } /** * MAZE CREATION * * Start the DFS creation of the maze */ // Add the current room to list of explored rooms exploredRooms.Add(current); List <Room> roomsAvailable = getAccessibleRooms(current); do { // Get a random room from the list and remove it from the list int index = random.Next(roomsAvailable.Count); Room roomToVenture = roomsAvailable.ElementAt(index); roomsAvailable.RemoveAt(index); // The room is already explored, don't go set it anymore if (exploredRooms.Contains(roomToVenture)) { continue; } // There is no room to venture to, don't go there if (roomToVenture == null) { continue; } // Determine the direction to take and the coordinate of the target room int directionToTake = isToTheDirectionOf(current, roomToVenture); Vector2 destinationCoordinate = getPointAt(current, directionToTake); // Recurse -- DEPRECATED generateMaze((int)destinationCoordinate.X, (int)destinationCoordinate.Y, current); } while (roomsAvailable.Count > 0); }