void SetTilesValuesForCorridors() { // Go through every corridor... for (int i = 0; i < corridors.Length; i++) { Corridor3D currentCorridor = corridors[i]; // and go through it's length. for (int j = 0; j < currentCorridor.corridorLength; j++) { // Start the coordinates at the start of the corridor. int xCoord = currentCorridor.startXPos; int yCoord = currentCorridor.startYPos; int CorridDepth = currentCorridor.Depth - 1; // Depending on the direction, add or subtract from the appropriate // coordinate based on how far through the length the loop is. switch (currentCorridor.direction) { case Direction.North: yCoord += j; break; case Direction.East: xCoord += j; break; case Direction.South: yCoord -= j; break; case Direction.West: xCoord -= j; break; } // Set the tile at these coordinates to Floor. tiles[CorridDepth][xCoord][yCoord] = currentCorridor.FloorType; } } //Redo Room[0] to ensure entry room not destroyed Room3D EntryRoom = rooms[0]; //Debug.Log("Total Rooms " + rooms.Length + " Room # " + i); int EntryDepth = EntryRoom.Depth - 1; // ... and for each room go through it's width. for (int j = 0; j < EntryRoom.roomWidth; j++) { int xCoord = EntryRoom.xPos + j; // For each horizontal tile, go up vertically through the room's height. for (int k = 0; k < EntryRoom.roomHeight; k++) { int yCoord = EntryRoom.yPos + k; // The coordinates in the jagged array are based on the room's position and it's width and height. tiles[EntryDepth][xCoord][yCoord] = EntryRoom.FloorType; } } }
public void BuildFixedRoom(int width, int height, int columns, int rows, Corridor3D corridor, int level, TileType3D floorType) { // Set the entering corridor direction. enteringCorridor = corridor.direction; Depth = level; //Set value for height and width roomWidth = width; roomHeight = height; FloorType = floorType; switch (corridor.direction) { // If the corridor entering this room is going north... case Direction.North: // ... the height of the room mustn't go beyond the board so it must be clamped based // on the height of the board (rows) and the end of corridor that leads to the room. roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY); // The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room). yPos = corridor.EndPositionY; // The x coordinate can be random but the left-most possibility is no further than the width // and the right-most possibility is that the end of the corridor is at the position of the room. xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX); // This must be clamped to ensure that the room doesn't go off the board. xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); break; case Direction.East: roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX); xPos = corridor.EndPositionX; yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY); yPos = Mathf.Clamp(yPos, 0, rows - roomHeight); break; case Direction.South: roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY); yPos = corridor.EndPositionY - roomHeight + 1; xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX); xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); break; case Direction.West: roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX); xPos = corridor.EndPositionX - roomWidth + 1; yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY); yPos = Mathf.Clamp(yPos, 0, rows - roomHeight); break; } }
// This is an overload of the SetupRoom function and has a corridor parameter that represents the corridor entering the room. public void SetupRoom(IntRange widthRange, IntRange heightRange, int columns, int rows, Corridor3D corridor, int level, TileType3D roomType) { // Set the entering corridor direction. enteringCorridor = corridor.direction; Depth = level; // Set random values for width and height. roomWidth = widthRange.Random; roomHeight = heightRange.Random; FloorType = roomType; switch (corridor.direction) { // If the corridor entering this room is going north... case Direction.North: // ... the height of the room mustn't go beyond the board so it must be clamped based // on the height of the board (rows) and the end of corridor that leads to the room. roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY); // The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room). yPos = corridor.EndPositionY; // The x coordinate can be random but the left-most possibility is no further than the width // and the right-most possibility is that the end of the corridor is at the position of the room. xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX); // This must be clamped to ensure that the room doesn't go off the board. xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); break; case Direction.East: roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX); xPos = corridor.EndPositionX; yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY); yPos = Mathf.Clamp(yPos, 0, rows - roomHeight); break; case Direction.South: roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY); yPos = corridor.EndPositionY - roomHeight + 1; xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX); xPos = Mathf.Clamp(xPos, 0, columns - roomWidth); break; case Direction.West: roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX); xPos = corridor.EndPositionX - roomWidth + 1; yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY); yPos = Mathf.Clamp(yPos, 0, rows - roomHeight); break; } //Debug.Log("Room Created at " + xPos + "," + yPos + "With size " + roomHeight + "," + roomWidth + " at depth of " + Depth); }
void CreateRoomsAndCorridors() { // Create the rooms array with a random size. int TotalRooms; int RoomPerLvl; int RoomTotalLoop; RoomTotalLoop = 0; RoomPerLvl = numRooms.Random; //TotalRooms = (RoomPerLvl * Depth) + 3 + (1+(2*(Depth-1))); TotalRooms = (RoomPerLvl * Depth) + 3; Debug.Log("Total Rooms: " + TotalRooms); Debug.Log("Total Room per LVL " + RoomPerLvl); rooms = new Room3D[TotalRooms]; // There should be one less corridor than there is rooms. corridors = new Corridor3D[TotalRooms - 1]; //Create the first room and corridor. rooms[0] = new Room3D(); corridors[0] = new Corridor3D(); //Create Entry Room rooms[0].CreateEntry(1, 1, columns, rows); corridors[0].BuildEntryCorridor(rooms[0], 5); RoomTotalLoop++; rooms[1] = new Room3D(); corridors[1] = new Corridor3D(); rooms[1].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[0], 1, TileType3D.Floor); corridors[1].SetupCorridor(rooms[1], corridorLength, roomWidth, roomHeight, columns, rows, false, 1); RoomTotalLoop++; rooms[2] = new Room3D(); corridors[2] = new Corridor3D(); rooms[2].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[1], 1, TileType3D.Floor); corridors[2].SetupCorridor(rooms[2], corridorLength, roomWidth, roomHeight, columns, rows, false, 1); // Setup the first room, there is no previous corridor so we do not use one. //rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows); // Setup the first corridor using the first room. //corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true); for (int i = 0; i < RoomPerLvl; i++) { // Create a room. RoomTotalLoop++; rooms[RoomTotalLoop] = new Room3D(); //Debug.Log("Room " + RoomTotalLoop); // Setup the room based on the previous corridor. rooms[RoomTotalLoop].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[RoomTotalLoop - 1], 1, TileType3D.Floor); // If we haven't reached the end of the corridors array... if (RoomTotalLoop < corridors.Length) { // ... create a corridor. corridors[RoomTotalLoop] = new Corridor3D(); // Setup the corridor based on the room that was just created. corridors[RoomTotalLoop].SetupCorridor(rooms[RoomTotalLoop], corridorLength, roomWidth, roomHeight, columns, rows, false, 1); } } // Create an extra room on current level and next level down. Both will be classed as stair undef. for (int d = 1; d < Depth; d++) { for (int i = 0; i < RoomPerLvl; i++) { // Create a room. RoomTotalLoop++; rooms[RoomTotalLoop] = new Room3D(); //Debug.Log("Depth " + d + " Room " + RoomTotalLoop); // Setup the room based on the previous corridor. rooms[RoomTotalLoop].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[RoomTotalLoop - 1], d + 1, TileType3D.Floor); // If we haven't reached the end of the corridors array... if (RoomTotalLoop < corridors.Length) { // ... create a corridor. corridors[RoomTotalLoop] = new Corridor3D(); // Setup the corridor based on the room that was just created. corridors[RoomTotalLoop].SetupCorridor(rooms[RoomTotalLoop], corridorLength, roomWidth, roomHeight, columns, rows, false, d + 1); } } //Create same room at current level and next level for down stairs. } }