diff --git a/DungeonShooting_Godot/DungeonShooting.csproj b/DungeonShooting_Godot/DungeonShooting.csproj index 48063c3..3b5ab85 100644 --- a/DungeonShooting_Godot/DungeonShooting.csproj +++ b/DungeonShooting_Godot/DungeonShooting.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/DungeonShooting_Godot/DungeonShooting.csproj.old.3 b/DungeonShooting_Godot/DungeonShooting.csproj.old.3 new file mode 100644 index 0000000..48063c3 --- /dev/null +++ b/DungeonShooting_Godot/DungeonShooting.csproj.old.3 @@ -0,0 +1,11 @@ + + + net6.0 + true + + + + + + + \ No newline at end of file diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index aa774e3..0713541 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -188,9 +188,9 @@ [rendering] +textures/canvas_textures/default_texture_filter=0 renderer/rendering_method="gl_compatibility" environment/defaults/default_clear_color=Color(0.109804, 0.0666667, 0.0901961, 1) -textures/canvas_textures/default_texture_filter=0 2d/snapping/use_gpu_pixel_snap=true environment/default_environment="res://default_env.tres" diff --git a/DungeonShooting_Godot/src/framework/IDestroy.cs b/DungeonShooting_Godot/src/framework/IDestroy.cs index 3591caa..73e8a1e 100644 --- a/DungeonShooting_Godot/src/framework/IDestroy.cs +++ b/DungeonShooting_Godot/src/framework/IDestroy.cs @@ -10,7 +10,7 @@ bool IsDestroyed { get; } /// - /// 销毁物体接口 + /// 销毁物体 /// void Destroy(); } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index 6434c9d..bf322d7 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -10,7 +10,7 @@ /// ActivityObject 子类实例化请不要直接使用 new, 而用该在类上标上 [RegisterActivity(id, prefabPath)], /// ActivityObject 类会自动扫描并注册物体, 然后使用而是使用 ActivityObject.Create(id) 来创建实例 /// -public abstract partial class ActivityObject : CharacterBody2D +public abstract partial class ActivityObject : CharacterBody2D, IDestroy { /// /// 是否是调试模式 diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs index 0967eca..f5d7616 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs @@ -62,6 +62,7 @@ //房间组名称 private string _groupName; + private DungeonRoomGroup _roomGroup; private enum GenerateRoomErrorCode { @@ -81,6 +82,21 @@ public DungeonGenerator(string groupName) { _groupName = groupName; + _roomGroup = GameApplication.Instance.RoomConfig[_groupName]; + + //验证该组是否满足生成地牢的条件 + if (_roomGroup.InletList.Count == 0) + { + throw new Exception("当前组'" + groupName + "'中没有起始房间, 不能生成地牢!"); + } + // else if (_roomGroup.OutletList.Count == 0) + // { + // throw new Exception("当前组'" + groupName + "'中没有结束房间, 不能生成地牢!"); + // } + // else if (_roomGroup.BattleList.Count == 0) + // { + // throw new Exception("当前组'" + groupName + "'中没有战斗房间, 不能生成地牢!"); + // } } /// @@ -113,14 +129,14 @@ if (StartRoom != null) return; //第一个房间 - GenerateRoom(null, 0, DungeonRoomType.Inlet, out var startRoom); + GenerateRoom(null, 0, GetNextRoomType(), out var startRoom); StartRoom = startRoom; //如果房间数量不够, 就一直生成 while (_count < _maxCount) { var room = Utils.RandomChoose(RoomInfos); - var errorCode = GenerateRoom(room, Utils.RandomRangeInt(0, 3), DungeonRoomType.Battle, out var nextRoom); + var errorCode = GenerateRoom(room, Utils.RandomRangeInt(0, 3), GetNextRoomType(), out var nextRoom); if (errorCode == GenerateRoomErrorCode.NoError) { _failCount = 0; @@ -155,8 +171,12 @@ } //随机选择一个房间 - var roomSplit = Utils.RandomChoose(GameApplication.Instance.RoomConfig[_groupName].GetRoomList(roomType)); - //var roomSplit = GameApplication.Instance.RoomConfig[1]; + var list = _roomGroup.GetRoomList(roomType); + if (list.Count == 0) //如果没有指定类型的房间, 就生成战斗房间 + { + list = _roomGroup.BattleList; + } + var roomSplit = Utils.RandomChoose(list); var room = new RoomInfo(_count, roomSplit); //房间大小 @@ -267,7 +287,7 @@ while (dirList.Count > 0) { var randDir = Utils.RandomChoose(dirList); - GenerateRoom(room, randDir, DungeonRoomType.Battle, out var nextRoom); + GenerateRoom(room, randDir, GetNextRoomType(), out var nextRoom); if (nextRoom == null) { break; @@ -284,6 +304,22 @@ return GenerateRoomErrorCode.NoError; } + private DungeonRoomType GetNextRoomType() + { + if (_count == 0) //生成第一个房间 + { + return DungeonRoomType.Inlet; + } + else if (_count == _maxCount - 1) //生成最后一个房间 + { + return DungeonRoomType.Outlet; + } + else + { + return DungeonRoomType.Battle; + } + } + /// /// 找两个房间的门 /// diff --git a/DungeonShooting_Godot/src/framework/map/RoomInfo.cs b/DungeonShooting_Godot/src/framework/map/RoomInfo.cs index 6207edd..02d1b4e 100644 --- a/DungeonShooting_Godot/src/framework/map/RoomInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/RoomInfo.cs @@ -5,7 +5,7 @@ /// /// 房间的数据描述 /// -public class RoomInfo +public class RoomInfo : IDestroy { public RoomInfo(int id, DungeonRoomSplit roomSplit) { @@ -62,7 +62,9 @@ /// 是否处于闭关状态, 也就是房间门没有主动打开 /// public bool IsSeclusion { get; private set; } = false; - + + public bool IsDestroyed { get; private set; } + private bool _beReady = false; private bool _waveStart = false; private int _currWaveIndex = 0; @@ -120,7 +122,27 @@ { return Position.Y; } + + public void Destroy() + { + if (IsDestroyed) + { + return; + } + IsDestroyed = true; + foreach (var nextRoom in Next) + { + nextRoom.Destroy(); + } + Next.Clear(); + foreach (var activityMark in ActivityMarks) + { + activityMark.QueueFree(); + } + ActivityMarks.Clear(); + } + /// /// 房间准备好了, 准备刷敌人, 并且关闭所有门, /// 当清完每一波刷新的敌人后即可开门 @@ -147,10 +169,14 @@ }); } - //关门 - foreach (var doorInfo in Doors) + //不是初始房间才能关门 + if (RoomSplit.RoomInfo.RoomType != DungeonRoomType.Inlet) { - doorInfo.Door.CloseDoor(); + //关门 + foreach (var doorInfo in Doors) + { + doorInfo.Door.CloseDoor(); + } } //执行第一波生成 @@ -167,9 +193,12 @@ IsSeclusion = false; _currActivityMarks.Clear(); //开门 - foreach (var doorInfo in Doors) + if (RoomSplit.RoomInfo.RoomType != DungeonRoomType.Inlet) { - doorInfo.Door.OpenDoor(); + foreach (var doorInfo in Doors) + { + doorInfo.Door.OpenDoor(); + } } } else //执行下一波 diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index a081f4a..93a5d5a 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Godot; /// @@ -91,9 +92,14 @@ //播放bgm //SoundManager.PlayMusic(ResourcePath.resource_sound_bgm_Intro_ogg, -17f); + //初始房间创建玩家标记 + var playerBirthMark = StartRoom.ActivityMarks.FirstOrDefault(mark => mark is PlayerBirthMark); //创建玩家 Player = ActivityObject.Create(ActivityIdPrefix.Role + "0001"); - Player.Position = new Vector2(30, 30); + if (playerBirthMark != null) + { + Player.Position = playerBirthMark.Position; + } Player.Name = "Player"; Player.PutDown(RoomLayerEnum.YSortLayer); Player.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0001")); @@ -179,7 +185,7 @@ //创建房间归属区域 CreateRoomAisleAffiliation(roomInfo); } - + //挂载房间导航区域 private void MountNavFromRoomInfo(RoomInfo roomInfo) { diff --git a/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs index c307cf0..3c92f03 100644 --- a/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs @@ -336,7 +336,7 @@ if (result) { //检查名称是否合规 - if (!Regex.IsMatch(roomName, "^\\w*$")) + if (!Regex.IsMatch(roomName, "^\\w+$")) { ShowTips("错误", "房间名称'" + roomName + "'不符合名称约束, 房间名称只允许包含大写字母和数字!"); return;