From a33be9f9e6adba7505795046a4834aba2fb7c84e Mon Sep 17 00:00:00 2001 From: jasonplojo Date: Fri, 4 Mar 2016 09:47:14 -0800 Subject: [PATCH 1/5] First attempt of appending corridors --- Assets/Scripts/ProcGen/BoardCreator.cs | 76 ++++++++++++++++++++++++- Assets/Scripts/ProcGen/Corridor.cs | 39 +++++++++++++ ProjectSettings/ProjectSettings.asset | Bin 37337 -> 37337 bytes ProjectSettings/ProjectVersion.txt | 2 +- 4 files changed, 114 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/ProcGen/BoardCreator.cs b/Assets/Scripts/ProcGen/BoardCreator.cs index 4ebc715..be83de4 100644 --- a/Assets/Scripts/ProcGen/BoardCreator.cs +++ b/Assets/Scripts/ProcGen/BoardCreator.cs @@ -9,7 +9,6 @@ public enum TileType Wall, Floor, } - public int columns = 100; // The number of columns on the board (how wide it will be). public int rows = 100; // The number of rows on the board (how tall it will be). public IntRange numRooms = new IntRange(15, 20); // The range of the number of rooms there can be. @@ -27,6 +26,7 @@ public enum TileType private TileType[][] tiles; // A jagged array of tile types representing the board, like a grid. private Room[] rooms; // All the rooms that are created for this board. private Corridor[] corridors; // All the corridors that connect the rooms. + private Corridor[] aCorridors; // All the appending corridors that connects to the main corridor. private GameObject boardHolder; // GameObject that acts as a container for all other tiles. @@ -68,10 +68,15 @@ void CreateRoomsAndCorridors() // There should be one less corridor than there is rooms. corridors = new Corridor[rooms.Length - 1]; - + + // There will be a specified number of appending corridor + aCorridors = new Corridor[(rooms.Length - 1) / 2]; + // Create the first room and corridor. rooms[0] = new Room(); corridors[0] = new Corridor(); + + int numAppend = 0; // Setup the first room, there is no previous corridor so we do not use one. rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows); @@ -87,13 +92,22 @@ void CreateRoomsAndCorridors() for (int i = 2; i < rooms.Length; i++) { bool goodRoomPlacement = false; + bool appendCorridor = false; // If room overlaps with any other rooms, create entirely new corridor leaving from the last created room while (!goodRoomPlacement) { // Create test corridor and room Corridor corridorToBePlaced = new Corridor(); + Corridor corridorToAppend = new Corridor(); + if (numAppend < (rooms.Length - 1) / 2) + { + appendCorridor = true; + } + corridorToBePlaced.SetupCorridor (rooms [i-1], corridorLength, roomWidth, roomHeight, columns, rows, false); + if (appendCorridor) + corridorToAppend.appendCorridor (corridorToBePlaced, corridorLength, corridorToBePlaced.EndPositionX, corridorToBePlaced.EndPositionY); Room roomToBePlaced = new Room (); roomToBePlaced.SetupRoom (roomWidth, roomHeight, columns, rows, corridorToBePlaced); @@ -121,6 +135,9 @@ void CreateRoomsAndCorridors() if (goodRoomPlacement) { corridors [i - 1] = corridorToBePlaced; + if (appendCorridor) + aCorridors[numAppend] = corridorToAppend; + rooms [i] = roomToBePlaced; //Rolls the dice @@ -190,6 +207,61 @@ void SetTilesValuesForCorridors() { Corridor 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; + + // 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; + } + + //Widens the corridor to set width + for ( int k = 0; k < currentCorridor.corridorWidth; k++) { + switch(currentCorridor.direction) + { + case Direction.North: + xCoord++; + break; + case Direction.East: + yCoord++; + break; + case Direction.South: + xCoord++; + break; + case Direction.West: + yCoord++; + break; + + } + // Set the tile at these coordinates to Floor. + tiles[xCoord][yCoord] = TileType.Floor; + } + + } + } + + // Go through every corridor... + for (int i = 0; i < aCorridors.Length; i++) + { + Corridor currentCorridor = aCorridors[i]; + // and go through it's length. for (int j = 0; j < currentCorridor.corridorLength; j++) { diff --git a/Assets/Scripts/ProcGen/Corridor.cs b/Assets/Scripts/ProcGen/Corridor.cs index 76007f7..2008127 100644 --- a/Assets/Scripts/ProcGen/Corridor.cs +++ b/Assets/Scripts/ProcGen/Corridor.cs @@ -108,6 +108,45 @@ public void SetupCorridor(Room room, IntRange length, IntRange roomWidth, IntRan break; } + // We clamp the length of the corridor to make sure it doesn't go off the board. + corridorLength = Mathf.Clamp(corridorLength, 1, maxLength); + } + + public void appendCorridor(Corridor corridor, IntRange length, int xStart, int yStart) + { + startXPos = xStart; + startYPos = yStart; + + // Set a random direction (a random index from 0 to 3, cast to Direction). + //First corridor cannot head West because it is in the West most room + direction = (Direction)Random.Range (0, 4); + + // 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)corridor.direction + 2) % 4); + + // If this is noth the first corridor and the randomly selected direction is opposite to the previous corridor's direction... + if (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; + // We clamp the length of the corridor to make sure it doesn't go off the board. corridorLength = Mathf.Clamp(corridorLength, 1, maxLength); } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 70fdf2daa2a20c9683e92fc095e8013d90ea7d73..eb2181a84b3e2dd944445a75c04c2dac993d4507 100644 GIT binary patch delta 14 Wcmcb)nCa$XrU_Dvh8v~#O#}chVFmO6 delta 14 Wcmcb)nCa$XrU_Dv#v7&gO#}chYX$ZI diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 5cc3b78..d0aa952 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 5.3.2p3 +m_EditorVersion: 5.3.2p1 m_StandardAssetsVersion: 0 From e27dd2b7e521ba617276f2e307514c4b2599ed20 Mon Sep 17 00:00:00 2001 From: jasonplojo Date: Fri, 4 Mar 2016 11:57:06 -0800 Subject: [PATCH 2/5] Early Corridor Append Added: Method to append addition corridor to the current corridor Needed: Tweak the position of the appending corridor to connect better Issues: When generating tiles, get an index out of array bounds. Most likely since there is no validation check for the appending corridor being inside the board creator. --- Assets/Scripts/ProcGen/BoardCreator.cs | 20 ++++++++++++++++---- ProjectSettings/GraphicsSettings.asset | Bin 4256 -> 4256 bytes 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/ProcGen/BoardCreator.cs b/Assets/Scripts/ProcGen/BoardCreator.cs index be83de4..89c3ab6 100644 --- a/Assets/Scripts/ProcGen/BoardCreator.cs +++ b/Assets/Scripts/ProcGen/BoardCreator.cs @@ -92,25 +92,32 @@ void CreateRoomsAndCorridors() for (int i = 2; i < rooms.Length; i++) { bool goodRoomPlacement = false; - bool appendCorridor = false; // If room overlaps with any other rooms, create entirely new corridor leaving from the last created room while (!goodRoomPlacement) { + bool appendCorridor = false; + // Create test corridor and room Corridor corridorToBePlaced = new Corridor(); Corridor corridorToAppend = new Corridor(); if (numAppend < (rooms.Length - 1) / 2) { + Debug.Log("Appending..."); appendCorridor = true; } corridorToBePlaced.SetupCorridor (rooms [i-1], corridorLength, roomWidth, roomHeight, columns, rows, false); + + Room roomToBePlaced = new Room (); + if (appendCorridor) + { corridorToAppend.appendCorridor (corridorToBePlaced, corridorLength, corridorToBePlaced.EndPositionX, corridorToBePlaced.EndPositionY); - - Room roomToBePlaced = new Room (); - roomToBePlaced.SetupRoom (roomWidth, roomHeight, columns, rows, corridorToBePlaced); + roomToBePlaced.SetupRoom(roomWidth, roomHeight, columns, rows, corridorToAppend); + } + else + roomToBePlaced.SetupRoom (roomWidth, roomHeight, columns, rows, corridorToBePlaced); // Loop over all other rooms created, except for one to be placed for (int j = 0; j < i; j++) @@ -136,7 +143,11 @@ void CreateRoomsAndCorridors() { corridors [i - 1] = corridorToBePlaced; if (appendCorridor) + { + Debug.Log("Saving..."); aCorridors[numAppend] = corridorToAppend; + numAppend++; + } rooms [i] = roomToBePlaced; @@ -265,6 +276,7 @@ void SetTilesValuesForCorridors() // and go through it's length. for (int j = 0; j < currentCorridor.corridorLength; j++) { + Debug.Log("Corridor..."); // Start the coordinates at the start of the corridor. int xCoord = currentCorridor.startXPos; int yCoord = currentCorridor.startYPos; diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 5af2e3911a09713e0cafbbc73b326b811a1fbb3c..ca561d25281dca30f08d5a6f2d701589fdc44b34 100644 GIT binary patch delta 12 TcmZ3WxIl4&6r Date: Fri, 4 Mar 2016 15:58:20 -0800 Subject: [PATCH 3/5] Append Corridor Refinement --- Assets/Scripts/ProcGen/BoardCreator.cs | 13 +++++---- Assets/Scripts/ProcGen/Corridor.cs | 37 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/ProcGen/BoardCreator.cs b/Assets/Scripts/ProcGen/BoardCreator.cs index 89c3ab6..3a085dc 100644 --- a/Assets/Scripts/ProcGen/BoardCreator.cs +++ b/Assets/Scripts/ProcGen/BoardCreator.cs @@ -14,7 +14,7 @@ public enum TileType public IntRange numRooms = new IntRange(15, 20); // The range of the number of rooms there can be. public IntRange roomWidth = new IntRange(3, 10); // The range of widths rooms can have. public IntRange roomHeight = new IntRange(3, 10); // The range of heights rooms can have. - public IntRange corridorLength = new IntRange(6, 10); // The range of lengths corridors between rooms can have. + public IntRange corridorLength = new IntRange(2, 5); // The range of lengths corridors between rooms can have. public GameObject[] floorTiles; // An array of floor tile prefabs. public GameObject[] wallTiles; // An array of wall tile prefabs. public GameObject[] outerWallTiles; // An array of outer wall tile prefabs. @@ -28,6 +28,7 @@ public enum TileType private Corridor[] corridors; // All the corridors that connect the rooms. private Corridor[] aCorridors; // All the appending corridors that connects to the main corridor. private GameObject boardHolder; // GameObject that acts as a container for all other tiles. + private int numAppend = 0; private void Start() @@ -70,13 +71,11 @@ void CreateRoomsAndCorridors() corridors = new Corridor[rooms.Length - 1]; // There will be a specified number of appending corridor - aCorridors = new Corridor[(rooms.Length - 1) / 2]; + aCorridors = new Corridor[rooms.Length - 1]; // Create the first room and corridor. rooms[0] = new Room(); corridors[0] = new Corridor(); - - int numAppend = 0; // Setup the first room, there is no previous corridor so we do not use one. rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows); @@ -101,7 +100,7 @@ void CreateRoomsAndCorridors() // Create test corridor and room Corridor corridorToBePlaced = new Corridor(); Corridor corridorToAppend = new Corridor(); - if (numAppend < (rooms.Length - 1) / 2) + if (numAppend < rooms.Length - 1) { Debug.Log("Appending..."); appendCorridor = true; @@ -113,7 +112,7 @@ void CreateRoomsAndCorridors() if (appendCorridor) { - corridorToAppend.appendCorridor (corridorToBePlaced, corridorLength, corridorToBePlaced.EndPositionX, corridorToBePlaced.EndPositionY); + corridorToAppend.appendCorridor (corridorToBePlaced, corridorLength, corridorToBePlaced.EndPositionX, corridorToBePlaced.EndPositionY, columns, rows); roomToBePlaced.SetupRoom(roomWidth, roomHeight, columns, rows, corridorToAppend); } else @@ -269,7 +268,7 @@ void SetTilesValuesForCorridors() } // Go through every corridor... - for (int i = 0; i < aCorridors.Length; i++) + for (int i = 0; i < numAppend; i++) { Corridor currentCorridor = aCorridors[i]; diff --git a/Assets/Scripts/ProcGen/Corridor.cs b/Assets/Scripts/ProcGen/Corridor.cs index 2008127..b409150 100644 --- a/Assets/Scripts/ProcGen/Corridor.cs +++ b/Assets/Scripts/ProcGen/Corridor.cs @@ -112,11 +112,8 @@ public void SetupCorridor(Room room, IntRange length, IntRange roomWidth, IntRan corridorLength = Mathf.Clamp(corridorLength, 1, maxLength); } - public void appendCorridor(Corridor corridor, IntRange length, int xStart, int yStart) - { - startXPos = xStart; - startYPos = yStart; - + public void appendCorridor(Corridor corridor, IntRange length, int xStart, int yStart, int columns, int rows) + { // Set a random direction (a random index from 0 to 3, cast to Direction). //First corridor cannot head West because it is in the West most room direction = (Direction)Random.Range (0, 4); @@ -138,15 +135,39 @@ public void appendCorridor(Corridor corridor, IntRange length, int xStart, int y directionInt++; directionInt = directionInt % 4; direction = (Direction)directionInt; + } + + int maxLength = length.m_Max; + + 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 = xStart - corridorWidth; + // 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 - corridorLength; + break; + case Direction.East: + startXPos = xStart - (corridorWidth / 2) - 1; + maxLength = columns - startXPos - corridorLength; + break; + case Direction.South: + startXPos = xStart - corridorWidth; + maxLength = columns - startYPos - corridorLength; + break; + case Direction.West: + startXPos = xStart + (corridorWidth / 2) - 2; + maxLength = rows - startXPos - corridorLength; + break; } + + startYPos = yStart; // 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; - // We clamp the length of the corridor to make sure it doesn't go off the board. corridorLength = Mathf.Clamp(corridorLength, 1, maxLength); } From 91928cbca415765c8cfd4f148dcfe1fc11f49aa9 Mon Sep 17 00:00:00 2001 From: jasonplojo Date: Wed, 9 Mar 2016 20:07:51 -0800 Subject: [PATCH 4/5] Adjusted Appending Corridor Placement Added: Corridors now append with correct positioning resulting in maintained corridor width Issue: Rooms with puzzles that are at the edge of the board will not create the puzzle prefab in the correct location Issue: After the rooms and corridors have been placed on the board, at times the appending corridor will result in the corridor/room being placed outside the board. This results in an error when placing the tiles. --- Assets/Scripts/ProcGen/BoardCreator.cs | 8 ++-- Assets/Scripts/ProcGen/Corridor.cs | 56 +++++++++++++++++++++----- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/ProcGen/BoardCreator.cs b/Assets/Scripts/ProcGen/BoardCreator.cs index 3a085dc..77288d6 100644 --- a/Assets/Scripts/ProcGen/BoardCreator.cs +++ b/Assets/Scripts/ProcGen/BoardCreator.cs @@ -9,12 +9,12 @@ public enum TileType Wall, Floor, } - public int columns = 100; // The number of columns on the board (how wide it will be). - public int rows = 100; // The number of rows on the board (how tall it will be). + public int columns = 200; // The number of columns on the board (how wide it will be). + public int rows = 200; // The number of rows on the board (how tall it will be). public IntRange numRooms = new IntRange(15, 20); // The range of the number of rooms there can be. public IntRange roomWidth = new IntRange(3, 10); // The range of widths rooms can have. public IntRange roomHeight = new IntRange(3, 10); // The range of heights rooms can have. - public IntRange corridorLength = new IntRange(2, 5); // The range of lengths corridors between rooms can have. + public IntRange corridorLength = new IntRange(6, 10); // The range of lengths corridors between rooms can have. public GameObject[] floorTiles; // An array of floor tile prefabs. public GameObject[] wallTiles; // An array of wall tile prefabs. public GameObject[] outerWallTiles; // An array of outer wall tile prefabs. @@ -71,7 +71,7 @@ void CreateRoomsAndCorridors() corridors = new Corridor[rooms.Length - 1]; // There will be a specified number of appending corridor - aCorridors = new Corridor[rooms.Length - 1]; + aCorridors = new Corridor[rooms.Length - 2]; // Create the first room and corridor. rooms[0] = new Room(); diff --git a/Assets/Scripts/ProcGen/Corridor.cs b/Assets/Scripts/ProcGen/Corridor.cs index b409150..9300737 100644 --- a/Assets/Scripts/ProcGen/Corridor.cs +++ b/Assets/Scripts/ProcGen/Corridor.cs @@ -82,6 +82,7 @@ public void SetupCorridor(Room room, IntRange length, IntRange roomWidth, IntRan { // If the choosen direction is North (up)... case Direction.North: + Debug.Log("Setting 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 - corridorWidth - 1); @@ -92,16 +93,19 @@ public void SetupCorridor(Room room, IntRange length, IntRange roomWidth, IntRan maxLength = rows - startYPos - roomHeight.m_Min; break; case Direction.East: + Debug.Log("Setting East..."); startXPos = room.xPos + room.roomWidth; startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight - corridorWidth - 1); maxLength = columns - startXPos - roomWidth.m_Min; break; case Direction.South: + Debug.Log("Setting South..."); startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth - corridorWidth); startYPos = room.yPos; maxLength = startYPos - roomHeight.m_Min; break; case Direction.West: + Debug.Log("Setting West..."); startXPos = room.xPos; startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight - corridorWidth); maxLength = startXPos - roomWidth.m_Min; @@ -139,34 +143,66 @@ public void appendCorridor(Corridor corridor, IntRange length, int xStart, int y int maxLength = length.m_Max; + //int maxLength; + switch (direction) { - // If the choosen direction is North (up)... + // If the chosen direction is North (up)... case Direction.North: + + Debug.Log("North"); // ... the starting position in the x axis can be random but within the width of the room. startXPos = xStart - corridorWidth; // 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 - corridorLength; + maxLength = rows - startYPos; + + startYPos = yStart - corridorWidth + 1; break; case Direction.East: - startXPos = xStart - (corridorWidth / 2) - 1; - maxLength = columns - startXPos - corridorLength; + + Debug.Log("East"); + if (oppositeDirection == Direction.North || oppositeDirection == Direction.South) + startXPos = xStart - corridorWidth + 1; + else + startXPos = xStart + 1; + + maxLength = columns - startXPos; + startYPos = yStart - corridorWidth; + break; case Direction.South: + + Debug.Log("South"); startXPos = xStart - corridorWidth; - maxLength = columns - startYPos - corridorLength; + maxLength = startYPos; + startYPos = yStart; break; case Direction.West: - startXPos = xStart + (corridorWidth / 2) - 2; - maxLength = rows - startXPos - corridorLength; + + Debug.Log("West"); + if (corridor.direction == Direction.North || corridor.direction == Direction.South) + startXPos = xStart; + else + startXPos = xStart + 1; + + maxLength = columns - startXPos; + startYPos = yStart - corridorWidth; break; } - - startYPos = yStart; // Set a random length. - corridorLength = length.Random; + do + { + Debug.Log("Resetting length..."); + corridorLength = length.Random; + }while(corridorLength <= corridorWidth + 1); + + if(maxLength <= corridorLength + 1) + maxLength = corridorLength + 1; + + Debug.Log("Corridor Length: " + corridorLength); + Debug.Log("Max Length: " + maxLength); // We clamp the length of the corridor to make sure it doesn't go off the board. corridorLength = Mathf.Clamp(corridorLength, 1, maxLength); From 2caa251b87d850109af004bdbfbde5c48c710f47 Mon Sep 17 00:00:00 2001 From: jasonplojo Date: Wed, 9 Mar 2016 20:16:55 -0800 Subject: [PATCH 5/5] Code Clean up Removed: Debug Logs Modified: Arrangement of statement for consistent code --- Assets/Scripts/ProcGen/BoardCreator.cs | 6 +---- Assets/Scripts/ProcGen/Corridor.cs | 34 ++++++-------------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/Assets/Scripts/ProcGen/BoardCreator.cs b/Assets/Scripts/ProcGen/BoardCreator.cs index 77288d6..aad41d6 100644 --- a/Assets/Scripts/ProcGen/BoardCreator.cs +++ b/Assets/Scripts/ProcGen/BoardCreator.cs @@ -100,11 +100,9 @@ void CreateRoomsAndCorridors() // Create test corridor and room Corridor corridorToBePlaced = new Corridor(); Corridor corridorToAppend = new Corridor(); + if (numAppend < rooms.Length - 1) - { - Debug.Log("Appending..."); appendCorridor = true; - } corridorToBePlaced.SetupCorridor (rooms [i-1], corridorLength, roomWidth, roomHeight, columns, rows, false); @@ -143,7 +141,6 @@ void CreateRoomsAndCorridors() corridors [i - 1] = corridorToBePlaced; if (appendCorridor) { - Debug.Log("Saving..."); aCorridors[numAppend] = corridorToAppend; numAppend++; } @@ -275,7 +272,6 @@ void SetTilesValuesForCorridors() // and go through it's length. for (int j = 0; j < currentCorridor.corridorLength; j++) { - Debug.Log("Corridor..."); // Start the coordinates at the start of the corridor. int xCoord = currentCorridor.startXPos; int yCoord = currentCorridor.startYPos; diff --git a/Assets/Scripts/ProcGen/Corridor.cs b/Assets/Scripts/ProcGen/Corridor.cs index 9300737..f8674ab 100644 --- a/Assets/Scripts/ProcGen/Corridor.cs +++ b/Assets/Scripts/ProcGen/Corridor.cs @@ -82,7 +82,6 @@ public void SetupCorridor(Room room, IntRange length, IntRange roomWidth, IntRan { // If the choosen direction is North (up)... case Direction.North: - Debug.Log("Setting 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 - corridorWidth - 1); @@ -93,19 +92,16 @@ public void SetupCorridor(Room room, IntRange length, IntRange roomWidth, IntRan maxLength = rows - startYPos - roomHeight.m_Min; break; case Direction.East: - Debug.Log("Setting East..."); startXPos = room.xPos + room.roomWidth; startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight - corridorWidth - 1); maxLength = columns - startXPos - roomWidth.m_Min; break; case Direction.South: - Debug.Log("Setting South..."); startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth - corridorWidth); startYPos = room.yPos; maxLength = startYPos - roomHeight.m_Min; break; case Direction.West: - Debug.Log("Setting West..."); startXPos = room.xPos; startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight - corridorWidth); maxLength = startXPos - roomWidth.m_Min; @@ -129,7 +125,7 @@ public void appendCorridor(Corridor corridor, IntRange length, int xStart, int y // Overall effect is if the direction was South then that is 2, becomes 4, remainder is 0, which is north. Direction oppositeDirection = (Direction)(((int)corridor.direction + 2) % 4); - // If this is noth the first corridor and the randomly selected direction is opposite to the previous corridor's direction... + // If this is north the first corridor and the randomly selected direction is opposite to the previous corridor's direction... if (direction == oppositeDirection) { // Rotate the direction 90 degrees clockwise (North becomes East, East becomes South, etc). @@ -147,62 +143,46 @@ public void appendCorridor(Corridor corridor, IntRange length, int xStart, int y switch (direction) { - // If the chosen direction is North (up)... case Direction.North: - - Debug.Log("North"); - // ... the starting position in the x axis can be random but within the width of the room. startXPos = xStart - corridorWidth; - - // 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; - startYPos = yStart - corridorWidth + 1; + maxLength = rows - startYPos; break; case Direction.East: - Debug.Log("East"); if (oppositeDirection == Direction.North || oppositeDirection == Direction.South) startXPos = xStart - corridorWidth + 1; else startXPos = xStart + 1; - maxLength = columns - startXPos; startYPos = yStart - corridorWidth; - + maxLength = columns - startXPos; break; case Direction.South: - - Debug.Log("South"); startXPos = xStart - corridorWidth; - maxLength = startYPos; startYPos = yStart; + maxLength = startYPos; break; case Direction.West: - - Debug.Log("West"); if (corridor.direction == Direction.North || corridor.direction == Direction.South) startXPos = xStart; else startXPos = xStart + 1; - maxLength = columns - startXPos; startYPos = yStart - corridorWidth; + maxLength = columns - startXPos; break; } - // Set a random length. + // Set a random length, ensure the length is greater than corridor width + // for proper corridor appending do { - Debug.Log("Resetting length..."); corridorLength = length.Random; }while(corridorLength <= corridorWidth + 1); if(maxLength <= corridorLength + 1) maxLength = corridorLength + 1; - - Debug.Log("Corridor Length: " + corridorLength); - Debug.Log("Max Length: " + maxLength); // We clamp the length of the corridor to make sure it doesn't go off the board. corridorLength = Mathf.Clamp(corridorLength, 1, maxLength);