void SetupTilesArray() { // Set the tiles jagged array to the correct width. tiles = new TileType3D[Depth][][]; tiles3D = new int[Depth][][]; for (int i = 0; i < tiles.Length; i++) { tiles[i] = new TileType3D[columns][]; tiles3D[i] = new int[columns][]; for (int j = 0; j < tiles[i].Length; j++) { tiles[i][j] = new TileType3D[rows]; tiles3D[i][j] = new int[rows]; } } //Debug.Log("tiles.length " + tiles.Length); //Debug.Log("tiles[depth].length " + tiles[Depth-1].Length); //Debug.Log("tiles[depth][colums].length" + tiles[Depth-1][columns-1].Length); //SetTilesValuesForCorridors a default value to each cell to show empty. for (int i = 0; i < Depth; i++) { for (int j = 0; j < tiles[i].Length; j++) { for (int k = 0; k < tiles[i][j].Length; k++) { tiles3D[i][j][k] = -1; } } } // Debug.Log("Tiles Array Done"); }
public void BuildFixedRoom(int width, int height, int column, int row, int level, TileType3D floorType) { roomWidth = width; roomHeight = height; xPos = column; yPos = row; Depth = level; FloorType = floorType; }
// 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); }
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 used for the first room. It does not have a Corridor parameter since there are no corridors yet. public void SetupRoom(IntRange widthRange, IntRange heightRange, int columns, int rows) { // Set a random width and height. roomWidth = widthRange.Random; roomHeight = heightRange.Random; FloorType = TileType3D.Floor; Depth = 1; // Set the x and y coordinates so the room is roughly in the middle of the board. xPos = Mathf.RoundToInt(columns / 2f - roomWidth / 2f); yPos = Mathf.RoundToInt(rows / 2f - roomHeight / 2f); //Debug.Log("First Room Set."); }
public void BuildEntryCorridor(Room3D room, int length) { FloorType = TileType3D.Floor; Depth = 1; switch (room.FloorType) { case TileType3D.Entry1: direction = Direction.West; break; case TileType3D.Entry2: direction = Direction.East; break; case TileType3D.Entry4: direction = Direction.North; break; case TileType3D.Entry8: direction = Direction.South; break; } switch (direction) { case Direction.North: startXPos = room.xPos; startYPos = room.yPos + 1; break; case Direction.West: startXPos = room.xPos - 1; startYPos = room.yPos; break; case Direction.South: startXPos = room.xPos; startYPos = room.yPos - 1; break; case Direction.East: startXPos = room.xPos + 1; startYPos = room.yPos; break; } corridorLength = length; }
public void CreateEntry(int width, int height, int columns, int rows) { int CornerPick = UnityEngine.Random.Range(0, 3); int ExitDir = 0; Depth = 1; roomHeight = height; roomWidth = width; switch (CornerPick) { case 0: ExitDir = UnityEngine.Random.Range(0, 1); if (ExitDir == 1) { FloorType = TileType3D.Entry8; } else { FloorType = TileType3D.Entry4; } xPos = UnityEngine.Random.Range(5, columns / 4); yPos = UnityEngine.Random.Range(5, rows / 4); break; case 1: ExitDir = UnityEngine.Random.Range(0, 1); if (ExitDir == 1) { FloorType = TileType3D.Entry8; } else { FloorType = TileType3D.Entry1; } xPos = UnityEngine.Random.Range(5, columns / 4); yPos = UnityEngine.Random.Range((rows / 4) * 3, rows - 5); break; case 2: ExitDir = UnityEngine.Random.Range(0, 1); if (ExitDir == 1) { FloorType = TileType3D.Entry1; } else { FloorType = TileType3D.Entry2; } xPos = UnityEngine.Random.Range((columns / 4) * 3, columns - 5); yPos = UnityEngine.Random.Range((rows / 4) * 3, rows - 5); break; case 3: ExitDir = UnityEngine.Random.Range(0, 1); if (ExitDir == 1) { FloorType = TileType3D.Entry4; } else { FloorType = TileType3D.Entry2; } xPos = UnityEngine.Random.Range((columns / 4) * 3, columns - 5); yPos = UnityEngine.Random.Range(5, rows / 4); break; } }
public void SetupCorridor(Room3D room, IntRange length, IntRange roomWidth, IntRange roomHeight, int columns, int rows, bool firstCorridor, int level) { // Set a random direction (a random index from 0 to 3, cast to Direction). direction = (Direction)Random.Range(0, 4); Depth = level; // Find the direction opposite to the one entering the room this corridor is leaving from. // Cast the previous corridor's direction to an int between 0 and 3 and add 2 (a number between 2 and 5). // Find the remainder when dividing by 4 (if 2 then 2, if 3 then 3, if 4 then 0, if 5 then 1). // Cast this number back to a direction. // Overall effect is if the direction was South then that is 2, becomes 4, remainder is 0, which is north. Direction oppositeDirection = (Direction)(((int)room.enteringCorridor + 2) % 4); // If this is noth the first corridor and the randomly selected direction is opposite to the previous corridor's direction... if (!firstCorridor && direction == oppositeDirection) { // Rotate the direction 90 degrees clockwise (North becomes East, East becomes South, etc). // This is a more broken down version of the opposite direction operation above but instead of adding 2 we're adding 1. // This means instead of rotating 180 (the opposite direction) we're rotating 90. int directionInt = (int)direction; directionInt++; directionInt = directionInt % 4; direction = (Direction)directionInt; } // Set a random length. corridorLength = length.Random; // Create a cap for how long the length can be (this will be changed based on the direction and position). int maxLength = length.m_Max; FloorType = TileType3D.Floor; switch (direction) { // If the choosen direction is North (up)... case Direction.North: // ... the starting position in the x axis can be random but within the width of the room. startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth - 1); // The starting position in the y axis must be the top of the room. startYPos = room.yPos + room.roomHeight; // The maximum length the corridor can be is the height of the board (rows) but from the top of the room (y pos + height). maxLength = rows - startYPos - roomHeight.m_Min; break; case Direction.East: startXPos = room.xPos + room.roomWidth; startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight - 1); maxLength = columns - startXPos - roomWidth.m_Min; break; case Direction.South: startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth); startYPos = room.yPos; maxLength = startYPos - roomHeight.m_Min; break; case Direction.West: startXPos = room.xPos; startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight); maxLength = startXPos - roomWidth.m_Min; break; } // We clamp the length of the corridor to make sure it doesn't go off the board. corridorLength = Mathf.Clamp(corridorLength, 1, maxLength); }