Fixed room overlaps
This commit is contained in:
parent
886370b230
commit
ea1ca7a0cd
12 changed files with 31564 additions and 14 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -192,6 +192,7 @@ namespace DungeonMapGenerator
|
||||||
{
|
{
|
||||||
List<Point> unoccupiedPointsOnSide = new List<Point>();
|
List<Point> unoccupiedPointsOnSide = new List<Point>();
|
||||||
var roomPoints = room.GetPointsInRoom();
|
var roomPoints = room.GetPointsInRoom();
|
||||||
|
int sideOverHang = SIDE_LENGTH_OF_NORMAL / 2;
|
||||||
int minX = roomPoints.Min(p => p.X);
|
int minX = roomPoints.Min(p => p.X);
|
||||||
int maxX = roomPoints.Max(p => p.X);
|
int maxX = roomPoints.Max(p => p.X);
|
||||||
int minY = roomPoints.Min(p => p.Y);
|
int minY = roomPoints.Min(p => p.Y);
|
||||||
|
|
@ -200,7 +201,7 @@ namespace DungeonMapGenerator
|
||||||
switch (side)
|
switch (side)
|
||||||
{
|
{
|
||||||
case RoomSide.Top:
|
case RoomSide.Top:
|
||||||
for (int x = minX - SIDE_LENGTH_OF_NORMAL; x <= maxX + SIDE_LENGTH_OF_NORMAL; x++)
|
for (int x = minX - sideOverHang; x <= maxX + sideOverHang; x++)
|
||||||
{
|
{
|
||||||
Point point = new Point(x, minY - SIDE_LENGTH_OF_NORMAL);
|
Point point = new Point(x, minY - SIDE_LENGTH_OF_NORMAL);
|
||||||
if (unoccupiedPoints.Contains(point))
|
if (unoccupiedPoints.Contains(point))
|
||||||
|
|
@ -210,7 +211,7 @@ namespace DungeonMapGenerator
|
||||||
}
|
}
|
||||||
return unoccupiedPointsOnSide;
|
return unoccupiedPointsOnSide;
|
||||||
case RoomSide.Bottom:
|
case RoomSide.Bottom:
|
||||||
for (int x = minX - SIDE_LENGTH_OF_NORMAL; x <= maxX + SIDE_LENGTH_OF_NORMAL; x++)
|
for (int x = minX - sideOverHang; x <= maxX + sideOverHang; x++)
|
||||||
{
|
{
|
||||||
Point point = new Point(x, maxY + SIDE_LENGTH_OF_NORMAL);
|
Point point = new Point(x, maxY + SIDE_LENGTH_OF_NORMAL);
|
||||||
if (unoccupiedPoints.Contains(point))
|
if (unoccupiedPoints.Contains(point))
|
||||||
|
|
@ -221,7 +222,7 @@ namespace DungeonMapGenerator
|
||||||
|
|
||||||
return unoccupiedPointsOnSide;
|
return unoccupiedPointsOnSide;
|
||||||
case RoomSide.Left:
|
case RoomSide.Left:
|
||||||
for (int y = minY - SIDE_LENGTH_OF_NORMAL; y <= maxY + SIDE_LENGTH_OF_NORMAL; y++)
|
for (int y = minY - sideOverHang; y <= maxY + sideOverHang; y++)
|
||||||
{
|
{
|
||||||
Point point = new Point(minX - SIDE_LENGTH_OF_NORMAL, y);
|
Point point = new Point(minX - SIDE_LENGTH_OF_NORMAL, y);
|
||||||
if (unoccupiedPoints.Contains(point))
|
if (unoccupiedPoints.Contains(point))
|
||||||
|
|
@ -232,7 +233,7 @@ namespace DungeonMapGenerator
|
||||||
|
|
||||||
return unoccupiedPointsOnSide;
|
return unoccupiedPointsOnSide;
|
||||||
case RoomSide.Right:
|
case RoomSide.Right:
|
||||||
for (int y = minY - SIDE_LENGTH_OF_NORMAL; y <= maxY + SIDE_LENGTH_OF_NORMAL; y++)
|
for (int y = minY - sideOverHang; y <= maxY + sideOverHang; y++)
|
||||||
{
|
{
|
||||||
Point point = new Point(maxX + SIDE_LENGTH_OF_NORMAL, y);
|
Point point = new Point(maxX + SIDE_LENGTH_OF_NORMAL, y);
|
||||||
if (unoccupiedPoints.Contains(point))
|
if (unoccupiedPoints.Contains(point))
|
||||||
|
|
@ -258,7 +259,7 @@ namespace DungeonMapGenerator
|
||||||
: unoccupiedPointsOnSide.OrderBy(p => p.X).ToList();
|
: unoccupiedPointsOnSide.OrderBy(p => p.X).ToList();
|
||||||
|
|
||||||
// List to store possible valid room placements (top-left points of the room)
|
// List to store possible valid room placements (top-left points of the room)
|
||||||
List<Point> validPlacements = new List<Point>();
|
List<Room> validRooms = new List<Room>();
|
||||||
|
|
||||||
// Iterate over the ordered points to find potential placements
|
// Iterate over the ordered points to find potential placements
|
||||||
for (int i = 0; i < orderedPoints.Count - sizeOfNewRoom + 1; i++)
|
for (int i = 0; i < orderedPoints.Count - sizeOfNewRoom + 1; i++)
|
||||||
|
|
@ -292,23 +293,22 @@ namespace DungeonMapGenerator
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!potentialPoints.Any(occupiedPoints.Contains))
|
Room testRoom = new Room(type, sizeOfNewRoom, sizeOfNewRoom, adjustedPoint);
|
||||||
|
if (!testRoom.GetPointsInRoom().Any(occupiedPoints.Contains))
|
||||||
{
|
{
|
||||||
validPlacements.Add(adjustedPoint); // First point is the top-left point of the room
|
validRooms.Add(testRoom); // First point is the top-left point of the room
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are valid placements, select a random one and create the room
|
// If there are valid room placements, select a random one and create the room
|
||||||
if (validPlacements.Any())
|
if (validRooms.Any())
|
||||||
{
|
{
|
||||||
Point randomPlacement = validPlacements[random.Next(validPlacements.Count)];
|
// Pick one of the valid rooms at random
|
||||||
Room newRoom = new Room(type, sizeOfNewRoom, sizeOfNewRoom, randomPlacement);
|
return validRooms[random.Next(validRooms.Count)];
|
||||||
|
|
||||||
return newRoom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no valid placements are found, return null or handle it as necessary
|
// If no valid rooms are found, return null or handle it as necessary
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
1620
Dungeons/dungeon.json
Normal file
1620
Dungeons/dungeon.json
Normal file
File diff suppressed because it is too large
Load diff
1861
Dungeons/dungeon01.json
Normal file
1861
Dungeons/dungeon01.json
Normal file
File diff suppressed because it is too large
Load diff
1570
Dungeons/dungeon02.json
Normal file
1570
Dungeons/dungeon02.json
Normal file
File diff suppressed because it is too large
Load diff
12612
PuzzleGameProject/Assets/Scenes/TestDungeons/Test_03.unity
Normal file
12612
PuzzleGameProject/Assets/Scenes/TestDungeons/Test_03.unity
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4f7019a01bdae0d41b628c2e4a5913ca
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
13873
PuzzleGameProject/Assets/Scenes/TestDungeons/Test_04.unity
Normal file
13873
PuzzleGameProject/Assets/Scenes/TestDungeons/Test_04.unity
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6a3d7630fd06699498006a33e4319c24
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Add table
Add a link
Reference in a new issue