// Method that creates the rooms and corridors private void CreateRoomsAndCorridors() { rooms = new Dungeon_Room[Random.Range(minNumRooms, maxNumRooms + 1)]; // Setup a random amount of rooms corridors = new Dungeon_Corridor[rooms.Length - 1]; // There is always one less corridor than the amount of rooms rooms[0] = new Dungeon_Room(); // Create the first room corridors[0] = new Dungeon_Corridor(); // Create the first corridor // Setup the first room rooms[0].SetupFirstRoom(Random.Range(minRoomWidth, maxRoomWidth + 1), Random.Range(minRoomHeight, maxRoomHeight + 1), columns, rows); // Setup the first corridor corridors[0].SetupCorridor(rooms[0], minCorridorLength, maxCorridorLength, rooms[0].roomWidth, rooms[0].roomHeight, columns, rows, true); // Create and Setup the other rooms for (int i = 1; i < rooms.Length; i++) { rooms[i] = new Dungeon_Room(); rooms[i].SetupRoom(Random.Range(minRoomWidth, maxRoomWidth + 1), Random.Range(minRoomHeight, maxRoomHeight + 1), columns, rows, corridors[i - 1]); if (i < corridors.Length) { corridors[i] = new Dungeon_Corridor(); corridors[i].SetupCorridor(rooms[i], minCorridorLength, maxCorridorLength, rooms[i].roomWidth, rooms[i].roomHeight, columns, rows, false); } } }
// Method for setting up the other rooms public void SetupRoom(int width, int height, int columns, int rows, Dungeon_Corridor corridor) { // Set the direction of the entering corridor enteringCorridor = corridor.direction; // Setup the width and height roomWidth = width; roomHeight = height; // The corridor.direction is the direction of the entering corridor // These if-statements are used to make sure the rooms are always within the size of the dungeon if (corridor.direction == CorridorDirection.Up) { roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndZPos); // Clamp the roomheight so the room won't go out of the dungeon zPos = corridor.EndZPos; // Set the Z position of the room xPos = Random.Range(corridor.EndXPos - roomWidth + 1, corridor.EndXPos + 1); // Set a random X position for the room xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); // Clamp the X position of the room so it won't go out of the dungeon } else if (corridor.direction == CorridorDirection.Right) { roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndXPos); xPos = corridor.EndXPos; zPos = Random.Range(corridor.EndZPos - roomHeight + 1, corridor.EndZPos + 1); zPos = Mathf.Clamp(zPos, 0, rows - roomHeight); } else if (corridor.direction == CorridorDirection.Down) { roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndZPos); zPos = corridor.EndZPos - roomHeight + 1; xPos = Random.Range(corridor.EndXPos - roomWidth + 1, corridor.EndXPos + 1); xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); } else if (corridor.direction == CorridorDirection.Left) { roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndXPos); xPos = corridor.EndXPos - roomWidth + 1; zPos = Random.Range(corridor.EndZPos - roomHeight + 1, corridor.EndZPos + 1); zPos = Mathf.Clamp(zPos, 0, rows - roomHeight); } }