diff --git a/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs b/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs index 66d1bf2..36cde46 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs @@ -541,7 +541,7 @@ } else { - DrawCircle(result.Exception.Point * GenerateDungeon.TileCellSize, 10, Colors.Red); + DrawCircle(result.Exception.Point * GameConfig.TileCellSize, 10, Colors.Red); } } } diff --git a/DungeonShooting_Godot/src/framework/map/DungeonTile.cs b/DungeonShooting_Godot/src/framework/map/DungeonTile.cs index 8e83be7..2761179 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonTile.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonTile.cs @@ -152,26 +152,26 @@ switch (doorDir1) { case DoorDirection.E: - rect.Size = new Vector2(rect.Size.X, GenerateDungeon.CorridorWidth); + rect.Size = new Vector2(rect.Size.X, GameConfig.CorridorWidth); FullHorizontalAisle(config, rect); FullHorizontalAisleLeft(config, rect, doorInfo); FullHorizontalAisleRight(config, rect, doorInfo.ConnectDoor); break; case DoorDirection.W: - rect.Size = new Vector2(rect.Size.X, GenerateDungeon.CorridorWidth); + rect.Size = new Vector2(rect.Size.X, GameConfig.CorridorWidth); FullHorizontalAisle(config, rect); FullHorizontalAisleLeft(config, rect, doorInfo.ConnectDoor); FullHorizontalAisleRight(config, rect, doorInfo); break; case DoorDirection.S: - rect.Size = new Vector2(GenerateDungeon.CorridorWidth, rect.Size.Y); + rect.Size = new Vector2(GameConfig.CorridorWidth, rect.Size.Y); FullVerticalAisle(config, rect); FullVerticalAisleUp(config, rect, doorInfo); FullVerticalAisleDown(config, rect, doorInfo.ConnectDoor); break; case DoorDirection.N: - rect.Size = new Vector2(GenerateDungeon.CorridorWidth, rect.Size.Y); + rect.Size = new Vector2(GameConfig.CorridorWidth, rect.Size.Y); FullVerticalAisle(config, rect); FullVerticalAisleUp(config, rect, doorInfo.ConnectDoor); FullVerticalAisleDown(config, rect, doorInfo); @@ -195,15 +195,15 @@ doorInfo.OriginPosition.X, doorInfo.OriginPosition.Y, doorInfo.Cross.X - doorInfo.OriginPosition.X, - GenerateDungeon.CorridorWidth + GameConfig.CorridorWidth ); break; case DoorDirection.W: //← rect = new Rect2( - doorInfo.Cross.X + GenerateDungeon.CorridorWidth, + doorInfo.Cross.X + GameConfig.CorridorWidth, doorInfo.Cross.Y, - doorInfo.OriginPosition.X - (doorInfo.Cross.X + GenerateDungeon.CorridorWidth), - GenerateDungeon.CorridorWidth + doorInfo.OriginPosition.X - (doorInfo.Cross.X + GameConfig.CorridorWidth), + GameConfig.CorridorWidth ); break; case DoorDirection.S: //↓ @@ -211,7 +211,7 @@ rect = new Rect2( doorInfo.OriginPosition.X, doorInfo.OriginPosition.Y, - GenerateDungeon.CorridorWidth, + GameConfig.CorridorWidth, doorInfo.Cross.Y - doorInfo.OriginPosition.Y ); break; @@ -219,9 +219,9 @@ dir1 = 1; rect = new Rect2( doorInfo.Cross.X, - doorInfo.Cross.Y + GenerateDungeon.CorridorWidth, - GenerateDungeon.CorridorWidth, - doorInfo.OriginPosition.Y - (doorInfo.Cross.Y + GenerateDungeon.CorridorWidth) + doorInfo.Cross.Y + GameConfig.CorridorWidth, + GameConfig.CorridorWidth, + doorInfo.OriginPosition.Y - (doorInfo.Cross.Y + GameConfig.CorridorWidth) ); break; default: @@ -236,16 +236,16 @@ doorInfo.ConnectDoor.OriginPosition.X, doorInfo.ConnectDoor.OriginPosition.Y, doorInfo.Cross.X - doorInfo.ConnectDoor.OriginPosition.X, - GenerateDungeon.CorridorWidth + GameConfig.CorridorWidth ); break; case DoorDirection.W: //← rect2 = new Rect2( - doorInfo.Cross.X + GenerateDungeon.CorridorWidth, + doorInfo.Cross.X + GameConfig.CorridorWidth, doorInfo.Cross.Y, doorInfo.ConnectDoor.OriginPosition.X - - (doorInfo.Cross.X + GenerateDungeon.CorridorWidth), - GenerateDungeon.CorridorWidth + (doorInfo.Cross.X + GameConfig.CorridorWidth), + GameConfig.CorridorWidth ); break; case DoorDirection.S: //↓ @@ -253,7 +253,7 @@ rect2 = new Rect2( doorInfo.ConnectDoor.OriginPosition.X, doorInfo.ConnectDoor.OriginPosition.Y, - GenerateDungeon.CorridorWidth, + GameConfig.CorridorWidth, doorInfo.Cross.Y - doorInfo.ConnectDoor.OriginPosition.Y ); break; @@ -261,10 +261,10 @@ dir2 = 1; rect2 = new Rect2( doorInfo.Cross.X, - doorInfo.Cross.Y + GenerateDungeon.CorridorWidth, - GenerateDungeon.CorridorWidth, + doorInfo.Cross.Y + GameConfig.CorridorWidth, + GameConfig.CorridorWidth, doorInfo.ConnectDoor.OriginPosition.Y - - (doorInfo.Cross.Y + GenerateDungeon.CorridorWidth) + (doorInfo.Cross.Y + GameConfig.CorridorWidth) ); break; default: @@ -273,7 +273,7 @@ } FillRect(AisleFloorMapLayer, config.Floor, doorInfo.Cross + Vector2.One, - new Vector2(GenerateDungeon.CorridorWidth - 2, GenerateDungeon.CorridorWidth - 2)); + new Vector2(GameConfig.CorridorWidth - 2, GameConfig.CorridorWidth - 2)); //墙壁, 0横向, 1纵向 if (dir1 == 0) @@ -306,50 +306,50 @@ (doorDir2 == DoorDirection.N && doorDir1 == DoorDirection.E)) { FillRect(TopMapLayer, config.OUT_RT, - doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), + doorInfo.Cross + new Vector2(0, GameConfig.CorridorWidth - 1), Vector2.One); - FillRect(TopMapLayer, config.IN_RT, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), + FillRect(TopMapLayer, config.IN_RT, doorInfo.Cross + new Vector2(GameConfig.CorridorWidth - 1, 0), Vector2.One); - FillRect(MiddleMapLayer, config.T, doorInfo.Cross, new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); - FillRect(TopMapLayer, config.R, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 1), - new Vector2(1, GenerateDungeon.CorridorWidth - 1)); + FillRect(MiddleMapLayer, config.T, doorInfo.Cross, new Vector2(GameConfig.CorridorWidth - 1, 1)); + FillRect(TopMapLayer, config.R, doorInfo.Cross + new Vector2(GameConfig.CorridorWidth - 1, 1), + new Vector2(1, GameConfig.CorridorWidth - 1)); } else if ((doorDir1 == DoorDirection.E && doorDir2 == DoorDirection.S) || //→↓ (doorDir2 == DoorDirection.E && doorDir1 == DoorDirection.S)) { FillRect(MiddleMapLayer, config.OUT_RB, doorInfo.Cross, Vector2.One); FillRect(TopMapLayer, config.IN_RB, - doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, - GenerateDungeon.CorridorWidth - 1), + doorInfo.Cross + new Vector2(GameConfig.CorridorWidth - 1, + GameConfig.CorridorWidth - 1), Vector2.One); - FillRect(TopMapLayer, config.R, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), - new Vector2(1, GenerateDungeon.CorridorWidth - 1)); - FillRect(TopMapLayer, config.B, doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), - new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); + FillRect(TopMapLayer, config.R, doorInfo.Cross + new Vector2(GameConfig.CorridorWidth - 1, 0), + new Vector2(1, GameConfig.CorridorWidth - 1)); + FillRect(TopMapLayer, config.B, doorInfo.Cross + new Vector2(0, GameConfig.CorridorWidth - 1), + new Vector2(GameConfig.CorridorWidth - 1, 1)); } else if ((doorDir1 == DoorDirection.S && doorDir2 == DoorDirection.W) || //↓← (doorDir2 == DoorDirection.S && doorDir1 == DoorDirection.W)) { FillRect(MiddleMapLayer, config.OUT_LB, - doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), Vector2.One); - FillRect(TopMapLayer, config.IN_LB, doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), + doorInfo.Cross + new Vector2(GameConfig.CorridorWidth - 1, 0), Vector2.One); + FillRect(TopMapLayer, config.IN_LB, doorInfo.Cross + new Vector2(0, GameConfig.CorridorWidth - 1), Vector2.One); - FillRect(TopMapLayer, config.L, doorInfo.Cross, new Vector2(1, GenerateDungeon.CorridorWidth - 1)); - FillRect(TopMapLayer, config.B, doorInfo.Cross + new Vector2(1, GenerateDungeon.CorridorWidth - 1), - new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); + FillRect(TopMapLayer, config.L, doorInfo.Cross, new Vector2(1, GameConfig.CorridorWidth - 1)); + FillRect(TopMapLayer, config.B, doorInfo.Cross + new Vector2(1, GameConfig.CorridorWidth - 1), + new Vector2(GameConfig.CorridorWidth - 1, 1)); } else if ((doorDir1 == DoorDirection.W && doorDir2 == DoorDirection.N) || //←↑ (doorDir2 == DoorDirection.W && doorDir1 == DoorDirection.N)) { FillRect(TopMapLayer, config.OUT_LT, - doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, - GenerateDungeon.CorridorWidth - 1), + doorInfo.Cross + new Vector2(GameConfig.CorridorWidth - 1, + GameConfig.CorridorWidth - 1), Vector2.One); FillRect(TopMapLayer, config.IN_LT, doorInfo.Cross, Vector2.One); FillRect(MiddleMapLayer, config.T, doorInfo.Cross + new Vector2(1, 0), - new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); + new Vector2(GameConfig.CorridorWidth - 1, 1)); FillRect(TopMapLayer, config.L, doorInfo.Cross + new Vector2(0, 1), - new Vector2(1, GenerateDungeon.CorridorWidth - 1)); + new Vector2(1, GameConfig.CorridorWidth - 1)); } //在房间墙上开洞 @@ -454,18 +454,18 @@ FillRect(FloorMapLayer, config.Floor, rect.Position + new Vector2(-1, 1), new Vector2(1, rect.Size.Y - 2)); //生成门的导航区域 - var x = rect.Position.X * GenerateDungeon.TileCellSize; - var y = rect.Position.Y * GenerateDungeon.TileCellSize; + var x = rect.Position.X * GameConfig.TileCellSize; + var y = rect.Position.Y * GameConfig.TileCellSize; - var op1 = new SerializeVector2(x - GenerateDungeon.TileCellSize * 1.5f, y + GenerateDungeon.TileCellSize * 1.5f); - var op2 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 0.5f, y + GenerateDungeon.TileCellSize * 1.5f); - var op3 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 0.5f, y + GenerateDungeon.TileCellSize * 2.5f); - var op4 = new SerializeVector2(x - GenerateDungeon.TileCellSize * 1.5f, y + GenerateDungeon.TileCellSize * 2.5f); + var op1 = new SerializeVector2(x - GameConfig.TileCellSize * 1.5f, y + GameConfig.TileCellSize * 1.5f); + var op2 = new SerializeVector2(x + GameConfig.TileCellSize * 0.5f, y + GameConfig.TileCellSize * 1.5f); + var op3 = new SerializeVector2(x + GameConfig.TileCellSize * 0.5f, y + GameConfig.TileCellSize * 2.5f); + var op4 = new SerializeVector2(x - GameConfig.TileCellSize * 1.5f, y + GameConfig.TileCellSize * 2.5f); AddDoorNavigation( doorInfo, op1, op2, op3, op4, new SerializeVector2(op1), - new SerializeVector2(op1.X + GenerateDungeon.TileCellSize, op2.Y), - new SerializeVector2(op1.X + GenerateDungeon.TileCellSize, op3.Y), + new SerializeVector2(op1.X + GameConfig.TileCellSize, op2.Y), + new SerializeVector2(op1.X + GameConfig.TileCellSize, op3.Y), new SerializeVector2(op4) ); } @@ -487,19 +487,19 @@ FillRect(FloorMapLayer, config.Floor, rect.Position + new Vector2(rect.Size.X, 1), new Vector2(1, rect.Size.Y - 2)); //生成门的导航区域 - var x = rect.Position.X * GenerateDungeon.TileCellSize; - var y = rect.Position.Y * GenerateDungeon.TileCellSize; + var x = rect.Position.X * GameConfig.TileCellSize; + var y = rect.Position.Y * GameConfig.TileCellSize; - var op1 = new SerializeVector2(x - GenerateDungeon.TileCellSize * 1.5f + (rect.Size.X + 1) * GenerateDungeon.TileCellSize, y + GenerateDungeon.TileCellSize * 1.5f); - var op2 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 0.5f + (rect.Size.X + 1) * GenerateDungeon.TileCellSize, y + GenerateDungeon.TileCellSize * 1.5f); - var op3 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 0.5f + (rect.Size.X + 1) * GenerateDungeon.TileCellSize, y + GenerateDungeon.TileCellSize * 2.5f); - var op4 = new SerializeVector2(x - GenerateDungeon.TileCellSize * 1.5f + (rect.Size.X + 1) * GenerateDungeon.TileCellSize, y + GenerateDungeon.TileCellSize * 2.5f); + var op1 = new SerializeVector2(x - GameConfig.TileCellSize * 1.5f + (rect.Size.X + 1) * GameConfig.TileCellSize, y + GameConfig.TileCellSize * 1.5f); + var op2 = new SerializeVector2(x + GameConfig.TileCellSize * 0.5f + (rect.Size.X + 1) * GameConfig.TileCellSize, y + GameConfig.TileCellSize * 1.5f); + var op3 = new SerializeVector2(x + GameConfig.TileCellSize * 0.5f + (rect.Size.X + 1) * GameConfig.TileCellSize, y + GameConfig.TileCellSize * 2.5f); + var op4 = new SerializeVector2(x - GameConfig.TileCellSize * 1.5f + (rect.Size.X + 1) * GameConfig.TileCellSize, y + GameConfig.TileCellSize * 2.5f); AddDoorNavigation( doorInfo, op1, op2, op3, op4, - new SerializeVector2(op2.X - GenerateDungeon.TileCellSize, op1.Y), + new SerializeVector2(op2.X - GameConfig.TileCellSize, op1.Y), new SerializeVector2(op2), new SerializeVector2(op3), - new SerializeVector2(op2.X - GenerateDungeon.TileCellSize, op4.Y) + new SerializeVector2(op2.X - GameConfig.TileCellSize, op4.Y) ); } } @@ -521,19 +521,19 @@ FillRect(FloorMapLayer, config.Floor, rect.Position + new Vector2(1, -1), new Vector2(rect.Size.X - 2, 1)); //生成门的导航区域 - var x = rect.Position.X * GenerateDungeon.TileCellSize; - var y = rect.Position.Y * GenerateDungeon.TileCellSize; + var x = rect.Position.X * GameConfig.TileCellSize; + var y = rect.Position.Y * GameConfig.TileCellSize; - var op1 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 1.5f, y - GenerateDungeon.TileCellSize * 1.5f); - var op2 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 2.5f, y - GenerateDungeon.TileCellSize * 1.5f); - var op3 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 2.5f, y + GenerateDungeon.TileCellSize * 0.5f); - var op4 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 1.5f, y + GenerateDungeon.TileCellSize * 0.5f); + var op1 = new SerializeVector2(x + GameConfig.TileCellSize * 1.5f, y - GameConfig.TileCellSize * 1.5f); + var op2 = new SerializeVector2(x + GameConfig.TileCellSize * 2.5f, y - GameConfig.TileCellSize * 1.5f); + var op3 = new SerializeVector2(x + GameConfig.TileCellSize * 2.5f, y + GameConfig.TileCellSize * 0.5f); + var op4 = new SerializeVector2(x + GameConfig.TileCellSize * 1.5f, y + GameConfig.TileCellSize * 0.5f); AddDoorNavigation( doorInfo, op1, op2, op3, op4, new SerializeVector2(op1), new SerializeVector2(op2), - new SerializeVector2(op3.X, op1.Y + GenerateDungeon.TileCellSize), - new SerializeVector2(op4.X, op1.Y + GenerateDungeon.TileCellSize) + new SerializeVector2(op3.X, op1.Y + GameConfig.TileCellSize), + new SerializeVector2(op4.X, op1.Y + GameConfig.TileCellSize) ); } } @@ -554,17 +554,17 @@ FillRect(FloorMapLayer, config.Floor, rect.Position + new Vector2(1, rect.Size.Y), new Vector2(rect.Size.X - 2, 1)); //生成门的导航区域 - var x = rect.Position.X * GenerateDungeon.TileCellSize; - var y = rect.Position.Y * GenerateDungeon.TileCellSize; + var x = rect.Position.X * GameConfig.TileCellSize; + var y = rect.Position.Y * GameConfig.TileCellSize; - var op1 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 1.5f, y - GenerateDungeon.TileCellSize * 1.5f + (rect.Size.Y + 1) * GenerateDungeon.TileCellSize); - var op2 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 2.5f, y - GenerateDungeon.TileCellSize * 1.5f + (rect.Size.Y + 1) * GenerateDungeon.TileCellSize); - var op3 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 2.5f, y + GenerateDungeon.TileCellSize * 0.5f + (rect.Size.Y + 1) * GenerateDungeon.TileCellSize); - var op4 = new SerializeVector2(x + GenerateDungeon.TileCellSize * 1.5f, y + GenerateDungeon.TileCellSize * 0.5f + (rect.Size.Y + 1) * GenerateDungeon.TileCellSize); + var op1 = new SerializeVector2(x + GameConfig.TileCellSize * 1.5f, y - GameConfig.TileCellSize * 1.5f + (rect.Size.Y + 1) * GameConfig.TileCellSize); + var op2 = new SerializeVector2(x + GameConfig.TileCellSize * 2.5f, y - GameConfig.TileCellSize * 1.5f + (rect.Size.Y + 1) * GameConfig.TileCellSize); + var op3 = new SerializeVector2(x + GameConfig.TileCellSize * 2.5f, y + GameConfig.TileCellSize * 0.5f + (rect.Size.Y + 1) * GameConfig.TileCellSize); + var op4 = new SerializeVector2(x + GameConfig.TileCellSize * 1.5f, y + GameConfig.TileCellSize * 0.5f + (rect.Size.Y + 1) * GameConfig.TileCellSize); AddDoorNavigation( doorInfo, op1, op2, op3, op4, - new SerializeVector2(op1.X, op3.Y - GenerateDungeon.TileCellSize), - new SerializeVector2(op2.X, op3.Y - GenerateDungeon.TileCellSize), + new SerializeVector2(op1.X, op3.Y - GameConfig.TileCellSize), + new SerializeVector2(op2.X, op3.Y - GameConfig.TileCellSize), new SerializeVector2(op3), new SerializeVector2(op4) ); diff --git a/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs b/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs index 08aea44..b68c277 100644 --- a/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs +++ b/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs @@ -9,21 +9,6 @@ public class GenerateDungeon { /// - /// 过道宽度 - /// - public const int CorridorWidth = 4; - - /// - /// tilemap 网格大小 - /// - public const int TileCellSize = 16; - - /// - /// 房间最小间距 - /// - public const int RoomSpace = 4; - - /// /// 所有生成的房间, 调用过 Generate() 函数才能获取到值 /// public List RoomInfos { get; } = new List(); @@ -223,7 +208,7 @@ } //是否碰到其他房间或者过道 - if (_roomGrid.RectCollision(room.Position - new Vector2(RoomSpace, RoomSpace), room.Size + new Vector2(RoomSpace * 2, RoomSpace * 2))) + if (_roomGrid.RectCollision(room.Position - new Vector2(GameConfig.RoomSpace, GameConfig.RoomSpace), room.Size + new Vector2(GameConfig.RoomSpace * 2, GameConfig.RoomSpace * 2))) { //碰到其他墙壁, 再一次尝试 continue; @@ -579,18 +564,18 @@ if (areaInfo.Direction == DoorDirection.N || areaInfo.Direction == DoorDirection.S) //纵向门 { var num = room1.GetHorizontalStart(); - var p1 = num + areaInfo.Start / TileCellSize; - var p2 = num + areaInfo.End / TileCellSize; + var p1 = num + areaInfo.Start / GameConfig.TileCellSize; + var p2 = num + areaInfo.End / GameConfig.TileCellSize; if (room1.Position.X > room2.Position.X) { var range = CalcOverlapRange(room2.GetHorizontalEnd(), room1.GetHorizontalEnd(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth) + if (range.Y - range.X >= GameConfig.CorridorWidth) { var tempRange = new Vector2I(Mathf.Abs(room1.Position.X - (int)range.X), - Mathf.Abs(room1.Position.X - (int)range.Y) - CorridorWidth); + Mathf.Abs(room1.Position.X - (int)range.Y) - GameConfig.CorridorWidth); if (areaRange == null || tempRange.X < areaRange.Value.X) { areaRange = tempRange; @@ -602,10 +587,10 @@ var range = CalcOverlapRange(room1.GetHorizontalStart(), room2.GetHorizontalStart(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth) + if (range.Y - range.X >= GameConfig.CorridorWidth) { var tempRange = new Vector2I(Mathf.Abs(room1.Position.X - (int)range.X), - Mathf.Abs(room1.Position.X - (int)range.Y) - CorridorWidth); + Mathf.Abs(room1.Position.X - (int)range.Y) - GameConfig.CorridorWidth); if (areaRange == null || tempRange.Y > areaRange.Value.Y) { areaRange = tempRange; @@ -616,18 +601,18 @@ else //横向门 { var num = room1.GetVerticalStart(); - var p1 = num + areaInfo.Start / TileCellSize; - var p2 = num + areaInfo.End / TileCellSize; + var p1 = num + areaInfo.Start / GameConfig.TileCellSize; + var p2 = num + areaInfo.End / GameConfig.TileCellSize; if (room1.Position.Y > room2.Position.Y) { var range = CalcOverlapRange(room2.GetVerticalEnd(), room1.GetVerticalEnd(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth) + if (range.Y - range.X >= GameConfig.CorridorWidth) { var tempRange = new Vector2I(Mathf.Abs(room1.Position.Y - (int)range.X), - Mathf.Abs(room1.Position.Y - (int)range.Y) - CorridorWidth); + Mathf.Abs(room1.Position.Y - (int)range.Y) - GameConfig.CorridorWidth); if (areaRange == null || tempRange.X < areaRange.Value.X) { areaRange = tempRange; @@ -639,10 +624,10 @@ var range = CalcOverlapRange(room1.GetVerticalStart(), room2.GetVerticalStart(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth) + if (range.Y - range.X >= GameConfig.CorridorWidth) { var tempRange = new Vector2I(Mathf.Abs(room1.Position.Y - (int)range.X), - Mathf.Abs(room1.Position.Y - (int)range.Y) - CorridorWidth); + Mathf.Abs(room1.Position.Y - (int)range.Y) - GameConfig.CorridorWidth); if (areaRange == null || tempRange.Y > areaRange.Value.Y) { areaRange = tempRange; @@ -834,21 +819,21 @@ if (direction == DoorDirection.E || direction == DoorDirection.W) //第二个门向← 或者 第二个门向→ { range = CalcOverlapRange( - room.GetVerticalStart() * TileCellSize + doorAreaInfo1.Start, room.GetVerticalStart() * TileCellSize + doorAreaInfo1.End, - nextRoom.GetVerticalStart() * TileCellSize + doorAreaInfo2.Start, nextRoom.GetVerticalStart() * TileCellSize + doorAreaInfo2.End + room.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo1.Start, room.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo1.End, + nextRoom.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo2.Start, nextRoom.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo2.End ); } else //第二个门向↑ 或者 第二个门向↓ { range = CalcOverlapRange( - room.GetHorizontalStart() * TileCellSize + doorAreaInfo1.Start, room.GetHorizontalStart() * TileCellSize + doorAreaInfo1.End, - nextRoom.GetHorizontalStart() * TileCellSize + doorAreaInfo2.Start, nextRoom.GetHorizontalStart() * TileCellSize + doorAreaInfo2.End + room.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo1.Start, room.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo1.End, + nextRoom.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo2.Start, nextRoom.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo2.End ); } //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth * TileCellSize) + if (range.Y - range.X >= GameConfig.CorridorWidth * GameConfig.TileCellSize) { - rangeList.Add(new Vector2I((int)(range.X / 16), (int)(range.Y / 16) - CorridorWidth)); + rangeList.Add(new Vector2I((int)(range.X / 16), (int)(range.Y / 16) - GameConfig.CorridorWidth)); } } } @@ -914,21 +899,21 @@ var point2 = door2.OriginPosition; var pos = new Vector2(Mathf.Min(point1.X, point2.X), Mathf.Min(point1.Y, point2.Y)); var size = new Vector2( - point1.X == point2.X ? CorridorWidth : Mathf.Abs(point1.X - point2.X), - point1.Y == point2.Y ? CorridorWidth : Mathf.Abs(point1.Y - point2.Y) + point1.X == point2.X ? GameConfig.CorridorWidth : Mathf.Abs(point1.X - point2.X), + point1.Y == point2.Y ? GameConfig.CorridorWidth : Mathf.Abs(point1.Y - point2.Y) ); Vector2 collPos; Vector2 collSize; if (point1.X == point2.X) //纵向加宽, 防止贴到其它墙 { - collPos = new Vector2(pos.X - RoomSpace, pos.Y); - collSize = new Vector2(size.X + RoomSpace * 2, size.Y); + collPos = new Vector2(pos.X - GameConfig.RoomSpace, pos.Y); + collSize = new Vector2(size.X + GameConfig.RoomSpace * 2, size.Y); } else //横向加宽, 防止贴到其它墙 { - collPos = new Vector2(pos.X, pos.Y - RoomSpace); - collSize = new Vector2(size.X, size.Y + RoomSpace * 2); + collPos = new Vector2(pos.X, pos.Y - GameConfig.RoomSpace); + collSize = new Vector2(size.X, size.Y + GameConfig.RoomSpace * 2); } if (_roomGrid.RectCollision(collPos, collSize)) @@ -947,26 +932,26 @@ var point2 = door2.OriginPosition; var pos1 = new Vector2(Mathf.Min(point1.X, cross.X), Mathf.Min(point1.Y, cross.Y)); var size1 = new Vector2( - point1.X == cross.X ? CorridorWidth : Mathf.Abs(point1.X - cross.X), - point1.Y == cross.Y ? CorridorWidth : Mathf.Abs(point1.Y - cross.Y) + point1.X == cross.X ? GameConfig.CorridorWidth : Mathf.Abs(point1.X - cross.X), + point1.Y == cross.Y ? GameConfig.CorridorWidth : Mathf.Abs(point1.Y - cross.Y) ); var pos2 = new Vector2(Mathf.Min(point2.X, cross.X), Mathf.Min(point2.Y, cross.Y)); var size2 = new Vector2( - point2.X == cross.X ? CorridorWidth : Mathf.Abs(point2.X - cross.X), - point2.Y == cross.Y ? CorridorWidth : Mathf.Abs(point2.Y - cross.Y) + point2.X == cross.X ? GameConfig.CorridorWidth : Mathf.Abs(point2.X - cross.X), + point2.Y == cross.Y ? GameConfig.CorridorWidth : Mathf.Abs(point2.Y - cross.Y) ); Vector2 collPos1; Vector2 collSize1; if (point1.X == cross.X) //纵向加宽, 防止贴到其它墙 { - collPos1 = new Vector2(pos1.X - RoomSpace, pos1.Y); - collSize1 = new Vector2(size1.X + RoomSpace * 2, size1.Y); + collPos1 = new Vector2(pos1.X - GameConfig.RoomSpace, pos1.Y); + collSize1 = new Vector2(size1.X + GameConfig.RoomSpace * 2, size1.Y); } else //横向加宽, 防止贴到其它墙 { - collPos1 = new Vector2(pos1.X, pos1.Y - RoomSpace); - collSize1 = new Vector2(size1.X, size1.Y + RoomSpace * 2); + collPos1 = new Vector2(pos1.X, pos1.Y - GameConfig.RoomSpace); + collSize1 = new Vector2(size1.X, size1.Y + GameConfig.RoomSpace * 2); } if (_roomGrid.RectCollision(collPos1, collSize1)) @@ -978,13 +963,13 @@ Vector2 collSize2; if (point2.X == cross.X) //纵向加宽, 防止贴到其它墙 { - collPos2 = new Vector2(pos2.X - RoomSpace, pos2.Y); - collSize2 = new Vector2(size2.X + RoomSpace * 2, size2.Y); + collPos2 = new Vector2(pos2.X - GameConfig.RoomSpace, pos2.Y); + collSize2 = new Vector2(size2.X + GameConfig.RoomSpace * 2, size2.Y); } else //横向加宽, 防止贴到其它墙 { - collPos2 = new Vector2(pos2.X, pos2.Y - RoomSpace); - collSize2 = new Vector2(size2.X, size2.Y + RoomSpace * 2); + collPos2 = new Vector2(pos2.X, pos2.Y - GameConfig.RoomSpace); + collSize2 = new Vector2(size2.X, size2.Y + GameConfig.RoomSpace * 2); } if (_roomGrid.RectCollision(collPos2, collSize2)) diff --git a/DungeonShooting_Godot/src/framework/map/RoomInfo.cs b/DungeonShooting_Godot/src/framework/map/RoomInfo.cs index ff2f39c..332de2d 100644 --- a/DungeonShooting_Godot/src/framework/map/RoomInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/RoomInfo.cs @@ -69,8 +69,8 @@ public Vector2 GetWorldPosition() { return new Vector2( - Position.X * GenerateDungeon.TileCellSize, - Position.Y * GenerateDungeon.TileCellSize + Position.X * GameConfig.TileCellSize, + Position.Y * GameConfig.TileCellSize ); } @@ -80,7 +80,7 @@ /// public Vector2 GetOffsetPosition() { - return RoomSplit.RoomInfo.Position.AsVector2() * GenerateDungeon.TileCellSize; + return RoomSplit.RoomInfo.Position.AsVector2() * GameConfig.TileCellSize; } /// diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs index 8dfea92..f47b11d 100644 --- a/DungeonShooting_Godot/src/game/GameApplication.cs +++ b/DungeonShooting_Godot/src/game/GameApplication.cs @@ -133,10 +133,10 @@ var areaInfos = roomSplit.RoomInfo.DoorAreaInfos; if (areaInfos.Count == 0) { - areaInfos.Add(new DoorAreaInfo(DoorDirection.N, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.X - 2) * GenerateDungeon.TileCellSize)); - areaInfos.Add(new DoorAreaInfo(DoorDirection.S, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.X - 2) * GenerateDungeon.TileCellSize)); - areaInfos.Add(new DoorAreaInfo(DoorDirection.W, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.Y - 2) * GenerateDungeon.TileCellSize)); - areaInfos.Add(new DoorAreaInfo(DoorDirection.E, GenerateDungeon.TileCellSize, (roomSplit.RoomInfo.Size.Y - 2) * GenerateDungeon.TileCellSize)); + areaInfos.Add(new DoorAreaInfo(DoorDirection.N, GameConfig.TileCellSize, (roomSplit.RoomInfo.Size.X - 2) * GameConfig.TileCellSize)); + areaInfos.Add(new DoorAreaInfo(DoorDirection.S, GameConfig.TileCellSize, (roomSplit.RoomInfo.Size.X - 2) * GameConfig.TileCellSize)); + areaInfos.Add(new DoorAreaInfo(DoorDirection.W, GameConfig.TileCellSize, (roomSplit.RoomInfo.Size.Y - 2) * GameConfig.TileCellSize)); + areaInfos.Add(new DoorAreaInfo(DoorDirection.E, GameConfig.TileCellSize, (roomSplit.RoomInfo.Size.Y - 2) * GameConfig.TileCellSize)); } } } diff --git a/DungeonShooting_Godot/src/game/GameConfig.cs b/DungeonShooting_Godot/src/game/GameConfig.cs index a303d3a..4437f1e 100644 --- a/DungeonShooting_Godot/src/game/GameConfig.cs +++ b/DungeonShooting_Godot/src/game/GameConfig.cs @@ -6,11 +6,11 @@ /// /// 散射计算的默认距离 /// - public static readonly float ScatteringDistance = 300; + public static float ScatteringDistance = 300; /// /// 重力加速度 /// - public static readonly float G = 250f; + public static float G = 250f; /// /// 像素缩放 /// @@ -21,7 +21,15 @@ public static readonly Vector2 ViewportSize = new Vector2(480, 270); //public static Vector2 ViewportSize => OS.WindowSize / WindowScale; /// + /// 连接房间的过道宽度 + /// + public const int CorridorWidth = 4; + /// /// 游戏地图网格大小 /// - public static readonly Vector2 MapCellSize = new Vector2(16, 16); + public const int TileCellSize = 16; + /// + /// 房间最小间距 + /// + public const int RoomSpace = 4; } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index baf5c5f..6c51704 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -108,8 +108,6 @@ /// /// 获取指定层级根节点 /// - /// - /// public Node2D GetRoomLayer(RoomLayerEnum layerEnum) { switch (layerEnum) @@ -216,7 +214,7 @@ default: offset = new Vector2(); break; } - door.Position = (doorInfo.OriginPosition + offset) * GenerateDungeon.TileCellSize; + door.Position = (doorInfo.OriginPosition + offset) * GameConfig.TileCellSize; door.Init(doorInfo); door.PutDown(RoomLayerEnum.NormalLayer, false); } @@ -228,8 +226,8 @@ var affiliation = new AffiliationArea(); affiliation.Name = "AffiliationArea" + (_affiliationIndex++); affiliation.Init(roomInfo, new Rect2( - roomInfo.GetWorldPosition() + new Vector2(GenerateDungeon.TileCellSize, GenerateDungeon.TileCellSize), - (roomInfo.Size - new Vector2I(2, 2)) * GenerateDungeon.TileCellSize)); + roomInfo.GetWorldPosition() + new Vector2(GameConfig.TileCellSize, GameConfig.TileCellSize), + (roomInfo.Size - new Vector2I(2, 2)) * GameConfig.TileCellSize)); roomInfo.Affiliation = affiliation; TileRoot.AddChild(affiliation);