diff --git a/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs b/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs
index e38ebbf..ea26823 100644
--- a/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs
+++ b/DungeonShooting_Godot/src/framework/map/DungeonConfig.cs
@@ -8,5 +8,9 @@
/// 地牢组名称
///
public string GroupName;
-
+
+ ///
+ /// 房间数量
+ ///
+ public int RoomCount = 20;
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
index 2978531..fcc1b21 100644
--- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
+++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
@@ -17,11 +17,6 @@
/// 起始房间
///
public RoomInfo StartRoom { get; private set; }
-
- ///
- /// 生成的房间数量
- ///
- private int _maxCount = 20;
//用于标记地图上的坐标是否被占用
private Grid _roomGrid { get; } = new Grid();
@@ -30,10 +25,10 @@
private int _count = 0;
//宽高
- private int _roomMinWidth = 15;
- private int _roomMaxWidth = 35;
- private int _roomMinHeight = 15;
- private int _roomMaxHeight = 30;
+ // private int _roomMinWidth = 15;
+ // private int _roomMaxWidth = 35;
+ // private int _roomMinHeight = 15;
+ // private int _roomMaxHeight = 30;
//间隔
private int _roomMinInterval = 6;
@@ -152,7 +147,7 @@
StartRoom = startRoom;
//如果房间数量不够, 就一直生成
- while (_count < _maxCount)
+ while (_count < _config.RoomCount)
{
var room = Utils.RandomChoose(RoomInfos);
var errorCode = GenerateRoom(room, Utils.RandomRangeInt(0, 3), GetNextRoomType(), out var nextRoom);
@@ -183,7 +178,7 @@
//生成房间
private GenerateRoomErrorCode GenerateRoom(RoomInfo prevRoomInfo, int direction, DungeonRoomType roomType, out RoomInfo resultRoom)
{
- if (_count >= _maxCount)
+ if (_count >= _config.RoomCount)
{
resultRoom = null;
return GenerateRoomErrorCode.RoomFull;
@@ -216,6 +211,7 @@
if (prevRoomInfo != null) //表示这不是第一个房间, 就得判断当前位置下的房间是否被遮挡
{
+ room.Layer = prevRoomInfo.Layer + 1;
//生成的位置可能会和上一个房间对不上, 需要多次尝试
var tryCount = 0; //当前尝试次数
for (; tryCount < _maxTryCount; tryCount++)
@@ -297,14 +293,15 @@
return GenerateRoomErrorCode.NoSuitableLocation;
}
}
-
- _count++;
- RoomInfos.Add(room);
- if (prevRoomInfo == null)
+ else //第一个房间
{
+ room.Layer = 0;
_roomGrid.AddRect(room.Position, room.Size, true);
}
+ _count++;
+ RoomInfos.Add(room);
+
//下一个房间
//0上, 1右, 2下, 3左
var dirList = new List(new[] { 0, 1, 2, 3 });
@@ -342,7 +339,7 @@
{
return DungeonRoomType.Inlet;
}
- else if (_count == _maxCount - 1) //生成最后一个房间
+ else if (_count == _config.RoomCount - 1) //生成最后一个房间
{
return DungeonRoomType.Outlet;
}
@@ -352,6 +349,38 @@
}
}
+ private bool RollbackRoom(RoomInfo roomInfo)
+ {
+ if (roomInfo.Next.Count > 0)
+ {
+ GD.PrintErr("当前房间还有连接的子房间, 不能回滚!");
+ return false;
+ }
+ //退掉占用的房间区域和过道占用区域
+ _roomGrid.RemoveRect(roomInfo.Position, roomInfo.Size);
+ foreach (var rect2 in roomInfo.AisleArea)
+ {
+ _roomGrid.RemoveRect(rect2.Position, rect2.Size);
+ }
+
+ //roomInfo.Doors[0].
+ if (roomInfo.Prev != null)
+ {
+ roomInfo.Prev.Next.Remove(roomInfo);
+ }
+
+ roomInfo.Prev = null;
+ foreach (var roomInfoDoor in roomInfo.Doors)
+ {
+ var connectDoor = roomInfoDoor.ConnectDoor;
+ connectDoor.RoomInfo.Doors.Remove(connectDoor);
+ }
+ roomInfo.Destroy();
+
+ _count--;
+ return true;
+ }
+
///
/// 找两个房间的门
///
@@ -1016,6 +1045,7 @@
return false;
}
+ door2.RoomInfo.AisleArea.Add(new Rect2(pos, size));
_roomGrid.AddRect(pos, size, true);
return true;
}
@@ -1072,6 +1102,8 @@
return false;
}
+ door2.RoomInfo.AisleArea.Add(new Rect2(pos1, size1));
+ door2.RoomInfo.AisleArea.Add(new Rect2(pos2, size2));
_roomGrid.AddRect(pos1, size1, true);
_roomGrid.AddRect(pos2, size2, true);
return true;
diff --git a/DungeonShooting_Godot/src/framework/map/RoomInfo.cs b/DungeonShooting_Godot/src/framework/map/RoomInfo.cs
index 02d1b4e..88cccf6 100644
--- a/DungeonShooting_Godot/src/framework/map/RoomInfo.cs
+++ b/DungeonShooting_Godot/src/framework/map/RoomInfo.cs
@@ -19,6 +19,11 @@
public int Id;
///
+ /// 层级, 也就是离初始房间间隔多少个房间
+ ///
+ public int Layer;
+
+ ///
/// 生成该房间使用的配置数据
///
public DungeonRoomSplit RoomSplit;
@@ -39,6 +44,11 @@
public List Doors = new List();
///
+ /// 连接该房间的过道占用区域信息
+ ///
+ public List AisleArea = new List();
+
+ ///
/// 下一个房间
///
public List Next = new List();
diff --git a/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs b/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs
index 4d740d1..beb8e2c 100644
--- a/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/main/MainPanel.cs
@@ -23,6 +23,7 @@
{
var config = new DungeonConfig();
config.GroupName = "testGroup";
+ config.RoomCount = 2;
GameApplication.Instance.DungeonManager.LoadDungeon(config);
HideUi();
}