Fixed room overlaps

This commit is contained in:
Max 2025-02-14 09:37:51 +01:00
parent 886370b230
commit ea1ca7a0cd
12 changed files with 31564 additions and 14 deletions

View file

@ -192,6 +192,7 @@ namespace DungeonMapGenerator
{
List<Point> unoccupiedPointsOnSide = new List<Point>();
var roomPoints = room.GetPointsInRoom();
int sideOverHang = SIDE_LENGTH_OF_NORMAL / 2;
int minX = roomPoints.Min(p => p.X);
int maxX = roomPoints.Max(p => p.X);
int minY = roomPoints.Min(p => p.Y);
@ -200,7 +201,7 @@ namespace DungeonMapGenerator
switch (side)
{
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);
if (unoccupiedPoints.Contains(point))
@ -210,7 +211,7 @@ namespace DungeonMapGenerator
}
return unoccupiedPointsOnSide;
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);
if (unoccupiedPoints.Contains(point))
@ -221,7 +222,7 @@ namespace DungeonMapGenerator
return unoccupiedPointsOnSide;
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);
if (unoccupiedPoints.Contains(point))
@ -232,7 +233,7 @@ namespace DungeonMapGenerator
return unoccupiedPointsOnSide;
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);
if (unoccupiedPoints.Contains(point))
@ -258,7 +259,7 @@ namespace DungeonMapGenerator
: unoccupiedPointsOnSide.OrderBy(p => p.X).ToList();
// 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
for (int i = 0; i < orderedPoints.Count - sizeOfNewRoom + 1; i++)
@ -292,23 +293,22 @@ namespace DungeonMapGenerator
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 (validPlacements.Any())
// If there are valid room placements, select a random one and create the room
if (validRooms.Any())
{
Point randomPlacement = validPlacements[random.Next(validPlacements.Count)];
Room newRoom = new Room(type, sizeOfNewRoom, sizeOfNewRoom, randomPlacement);
return newRoom;
// Pick one of the valid rooms at random
return validRooms[random.Next(validRooms.Count)];
}
// 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;
}

1620
Dungeons/dungeon.json Normal file

File diff suppressed because it is too large Load diff

1861
Dungeons/dungeon01.json Normal file

File diff suppressed because it is too large Load diff

1570
Dungeons/dungeon02.json Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4f7019a01bdae0d41b628c2e4a5913ca
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6a3d7630fd06699498006a33e4319c24
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: