diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup2/inlet/Start1/RoomInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup2/inlet/Start1/RoomInfo.json index d224396..c1f72ee 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup2/inlet/Start1/RoomInfo.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup2/inlet/Start1/RoomInfo.json @@ -1 +1 @@ -{"Position":{"X":-3,"Y":-6},"Size":{"X":14,"Y":13},"DoorAreaInfos":[{"Direction":0,"Start":16,"End":128},{"Direction":1,"Start":32,"End":128},{"Direction":3,"Start":0,"End":128},{"Direction":2,"Start":16,"End":144}],"GroupName":"TestGroup2","RoomType":1,"RoomName":"Start1","Weight":100,"Remark":""} \ No newline at end of file +{"Position":{"X":-3,"Y":-6},"Size":{"X":14,"Y":13},"DoorAreaInfos":[{"Direction":3,"Start":0,"End":64},{"Direction":1,"Start":0,"End":64},{"Direction":0,"Start":64,"End":128},{"Direction":2,"Start":96,"End":160}],"GroupName":"TestGroup2","RoomType":1,"RoomName":"Start1","Weight":100,"Remark":""} \ 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 6d725a8..4afdb8a 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs @@ -155,9 +155,9 @@ /// /// 生成房间 /// - public void Generate() + public bool Generate() { - if (StartRoomInfo != null) return; + if (StartRoomInfo != null) return false; CalcNextRoomType(null); //用于排除上一级房间 @@ -167,6 +167,12 @@ var chainTryCount = 0; var chainMaxTryCount = 3; + + //最大尝试次数 + var maxTryCount = 500; + + //当前尝试次数 + var currTryCount = 0; //如果房间数量不够, 就一直生成 while (_count < _config.RoomCount || EndRoomInfo == null) @@ -280,11 +286,18 @@ Debug.Log("生成房间失败次数过多, 增大区域"); } } + currTryCount++; + if (currTryCount >= maxTryCount) + { + return false; + } } } _roomGrid.Clear(); Debug.Log("房间总数: " + RoomInfos.Count); + + return true; } //生成房间 @@ -397,7 +410,7 @@ continue; //return GenerateRoomErrorCode.HasCollision; } - + _roomGrid.SetRect(room.Position, room.Size, true); //找门, 与上一个房间是否能连通 @@ -850,8 +863,8 @@ if (areaInfo.Direction == DoorDirection.N || areaInfo.Direction == DoorDirection.S) //纵向门 { var num = room1.GetHorizontalStart(); - var p1 = num + areaInfo.Start / GameConfig.TileCellSize; - var p2 = num + areaInfo.End / GameConfig.TileCellSize; + var p1 = num + GetDoorAreaInfoStart(areaInfo) / GameConfig.TileCellSize; + var p2 = num + GetDoorAreaInfoEnd(areaInfo) / GameConfig.TileCellSize; if (room1.Position.X > room2.Position.X) { @@ -893,8 +906,8 @@ else //横向门 { var num = room1.GetVerticalStart(); - var p1 = num + areaInfo.Start / GameConfig.TileCellSize; - var p2 = num + areaInfo.End / GameConfig.TileCellSize; + var p1 = num + GetDoorAreaInfoStart(areaInfo) / GameConfig.TileCellSize; + var p2 = num + GetDoorAreaInfoEnd(areaInfo) / GameConfig.TileCellSize; if (room1.Position.Y > room2.Position.Y) { @@ -1117,15 +1130,15 @@ if (direction == DoorDirection.E || direction == DoorDirection.W) //第二个门向← 或者 第二个门向→ { range = CalcOverlapRange( - roomInfo.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo1.Start, roomInfo.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo1.End, - nextRoomInfo.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo2.Start, nextRoomInfo.GetVerticalStart() * GameConfig.TileCellSize + doorAreaInfo2.End + roomInfo.GetVerticalStart() * GameConfig.TileCellSize + GetDoorAreaInfoStart(doorAreaInfo1), roomInfo.GetVerticalStart() * GameConfig.TileCellSize + GetDoorAreaInfoEnd(doorAreaInfo1), + nextRoomInfo.GetVerticalStart() * GameConfig.TileCellSize + GetDoorAreaInfoStart(doorAreaInfo2), nextRoomInfo.GetVerticalStart() * GameConfig.TileCellSize + GetDoorAreaInfoEnd(doorAreaInfo2) ); } else //第二个门向↑ 或者 第二个门向↓ { range = CalcOverlapRange( - roomInfo.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo1.Start, roomInfo.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo1.End, - nextRoomInfo.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo2.Start, nextRoomInfo.GetHorizontalStart() * GameConfig.TileCellSize + doorAreaInfo2.End + roomInfo.GetHorizontalStart() * GameConfig.TileCellSize + GetDoorAreaInfoStart(doorAreaInfo1), roomInfo.GetHorizontalStart() * GameConfig.TileCellSize + GetDoorAreaInfoEnd(doorAreaInfo1), + nextRoomInfo.GetHorizontalStart() * GameConfig.TileCellSize + GetDoorAreaInfoStart(doorAreaInfo2), nextRoomInfo.GetHorizontalStart() * GameConfig.TileCellSize + GetDoorAreaInfoEnd(doorAreaInfo2) ); } //交集范围够生成门 @@ -1322,4 +1335,14 @@ _roomGrid.SetRect(pos2, size2, true); return true; } + + private int GetDoorAreaInfoStart(DoorAreaInfo areaInfo) + { + return areaInfo.Start; + } + + private int GetDoorAreaInfoEnd(DoorAreaInfo areaInfo) + { + return areaInfo.End; + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs b/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs index 738c53b..5d6c1d1 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs @@ -182,6 +182,7 @@ roomPreinstall.Pretreatment(random); } + // yield break; //铺过道 foreach (var doorInfo in roomInfo.Doors) { diff --git a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs index fd98545..cbec0bd 100644 --- a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs +++ b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs @@ -61,20 +61,20 @@ ActivePropsPack.SetCapacity(1); // debug用 - // RoleState.Acceleration = 3000; - // RoleState.Friction = 3000; - // RoleState.MoveSpeed = 500; - // CollisionLayer = 0; - // CollisionMask = 0; + RoleState.Acceleration = 3000; + RoleState.Friction = 3000; + RoleState.MoveSpeed = 500; + CollisionLayer = 0; + CollisionMask = 0; //GameCamera.Main.Zoom = new Vector2(0.5f, 0.5f); //GameCamera.Main.Zoom = new Vector2(0.2f, 0.2f); - this.CallDelay(0.5f, () => - { - PickUpWeapon(Create(Ids.Id_weapon0009)); - PickUpWeapon(Create(Ids.Id_weapon0008)); - PickUpWeapon(Create(Ids.Id_weapon0007)); - PickUpWeapon(Create(Ids.Id_weapon0006)); - }); + // this.CallDelay(0.5f, () => + // { + // PickUpWeapon(Create(Ids.Id_weapon0009)); + // PickUpWeapon(Create(Ids.Id_weapon0008)); + // PickUpWeapon(Create(Ids.Id_weapon0007)); + // PickUpWeapon(Create(Ids.Id_weapon0006)); + // }); //注册状态机 StateController.Register(new PlayerIdleState()); diff --git a/DungeonShooting_Godot/src/game/manager/EditorPlayManager.cs b/DungeonShooting_Godot/src/game/manager/EditorPlayManager.cs index e9d9088..66c1ab2 100644 --- a/DungeonShooting_Godot/src/game/manager/EditorPlayManager.cs +++ b/DungeonShooting_Godot/src/game/manager/EditorPlayManager.cs @@ -6,7 +6,7 @@ /// /// 是否正在播放 /// - public static bool IsPlay { get; private set; } + public static bool IsPlay { get; set; } private static DungeonConfig _config; diff --git a/DungeonShooting_Godot/src/game/room/DungeonManager.cs b/DungeonShooting_Godot/src/game/room/DungeonManager.cs index 513687a..65959e0 100644 --- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs +++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs @@ -195,13 +195,35 @@ //打开 loading UI UiManager.Open_Loading(); yield return 0; - //创建世界场景 - World = GameApplication.Instance.CreateNewWorld(); - yield return 0; //生成地牢房间 var random = new SeedRandom(1); _dungeonGenerator = new DungeonGenerator(CurrConfig, random); - _dungeonGenerator.Generate(); + if (!_dungeonGenerator.Generate()) //生成房间失败 + { + _dungeonGenerator.EachRoom(DisposeRoomInfo); + _dungeonGenerator = null; + UiManager.Hide_Loading(); + + if (IsEditorMode) //在编辑器模式下打开的Ui + { + EditorPlayManager.IsPlay = false; + IsEditorMode = false; + //显示上一个Ui + if (_prevUi != null) + { + _prevUi.ShowUi(); + } + } + else //正常关闭Ui + { + UiManager.Open_Main(); + } + EditorWindowManager.ShowTips("错误", "生成房间尝试次数过多,生成地牢房间失败,请加大房间门连接区域!"); + yield break; + } + yield return 0; + //创建世界场景 + World = GameApplication.Instance.CreateNewWorld(); yield return 0; //填充地牢 diff --git a/DungeonShooting_Godot/src/game/room/World.cs b/DungeonShooting_Godot/src/game/room/World.cs index d6db819..29c4175 100644 --- a/DungeonShooting_Godot/src/game/room/World.cs +++ b/DungeonShooting_Godot/src/game/room/World.cs @@ -70,7 +70,7 @@ public override void _Ready() { - Color = Colors.Black; + //Color = Colors.Black; //临时处理, 加载TileSet var tileSet = ResourceManager.Load(ResourcePath.resource_tileSet_map2_TileSet2_tres);