From 92659d23b00c499bc3cdb1e94e9dbb1e5f5eaeb3 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Fri, 10 May 2024 22:56:27 +0800 Subject: [PATCH] =?UTF-8?q?Prepare=20to=20add=20forks=20to=20the=20map.=20?= =?UTF-8?q?=E5=87=86=E5=A4=87=E4=B8=BA=E5=9C=B0=E5=9B=BE=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E5=8F=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ColdMint.Traveler.csproj | 3 + prefab/entitys/Character.tscn | 1 + prefab/entitys/DelivererOfDarkMagic.tscn | 2 +- .../dungeon/horizontalCorridorWithSewer.tscn | 11 +--- scenes/game.tscn | 14 ++++- scripts/FpsLabel.cs | 56 +++++++++++++++++++ scripts/debug/LogCat.cs | 9 ++- scripts/loader/sceneLoader/GameSceneLoader.cs | 2 +- scripts/map/MapGenerator.cs | 3 +- scripts/map/MapGeneratorConfig.cs | 18 ++++-- scripts/map/interfaces/IBranch.cs | 18 ++++++ scripts/map/interfaces/IMapGeneratorConfig.cs | 6 ++ scripts/map/interfaces/IRoomHolder.cs | 8 +++ scripts/map/interfaces/IRoomProvider.cs | 8 +++ 14 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 scripts/FpsLabel.cs create mode 100644 scripts/map/interfaces/IBranch.cs diff --git a/ColdMint.Traveler.csproj b/ColdMint.Traveler.csproj index 81e4509..8fddecf 100644 --- a/ColdMint.Traveler.csproj +++ b/ColdMint.Traveler.csproj @@ -7,4 +7,7 @@ ColdMint enable + + + \ No newline at end of file diff --git a/prefab/entitys/Character.tscn b/prefab/entitys/Character.tscn index e1e4d59..84a2e99 100644 --- a/prefab/entitys/Character.tscn +++ b/prefab/entitys/Character.tscn @@ -34,6 +34,7 @@ shape = SubResource("CapsuleShape2D_bb8wt") debug_color = Color(0.886275, 0, 0.803922, 0.419608) [node name="Camera2D" type="Camera2D" parent="."] +position_smoothing_enabled = true [node name="Area2DPickingArea" type="Area2D" parent="."] collision_layer = 0 diff --git a/prefab/entitys/DelivererOfDarkMagic.tscn b/prefab/entitys/DelivererOfDarkMagic.tscn index 6c6d248..1588392 100644 --- a/prefab/entitys/DelivererOfDarkMagic.tscn +++ b/prefab/entitys/DelivererOfDarkMagic.tscn @@ -32,7 +32,7 @@ collision_layer = 64 collision_mask = 38 script = ExtResource("1_ubaid") metadata/CampId = "Mazoku" -metadata/MaxHp = 99999 +metadata/MaxHp = 50 metadata/Name = "死灵法师" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/prefab/roomTemplates/dungeon/horizontalCorridorWithSewer.tscn b/prefab/roomTemplates/dungeon/horizontalCorridorWithSewer.tscn index b57c429..dcc0c6b 100644 --- a/prefab/roomTemplates/dungeon/horizontalCorridorWithSewer.tscn +++ b/prefab/roomTemplates/dungeon/horizontalCorridorWithSewer.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=3 uid="uid://dslr5tdbp4noq"] +[gd_scene load_steps=5 format=3 uid="uid://dslr5tdbp4noq"] [ext_resource type="TileSet" uid="uid://c4wpp12rr44hi" path="res://tileSets/dungeon.tres" id="1_rn2om"] @@ -8,9 +8,6 @@ size = Vector2(508.75, 191) [sub_resource type="RectangleShape2D" id="RectangleShape2D_o85u0"] size = Vector2(20, 48) -[sub_resource type="RectangleShape2D" id="RectangleShape2D_30r3c"] -size = Vector2(20, 46) - [sub_resource type="RectangleShape2D" id="RectangleShape2D_x4kt2"] size = Vector2(46, 20) @@ -42,12 +39,6 @@ shape = SubResource("RectangleShape2D_kiih8") position = Vector2(17, 129) shape = SubResource("RectangleShape2D_o85u0") -[node name="Area2D2" type="Area2D" parent="RoomSlotList"] - -[node name="CollisionShape2D" type="CollisionShape2D" parent="RoomSlotList/Area2D2"] -position = Vector2(498, 128) -shape = SubResource("RectangleShape2D_30r3c") - [node name="Area2D3" type="Area2D" parent="RoomSlotList"] [node name="CollisionShape2D" type="CollisionShape2D" parent="RoomSlotList/Area2D3"] diff --git a/scenes/game.tscn b/scenes/game.tscn index 3c2e326..5a000bd 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://bnftvkj2cido7"] +[gd_scene load_steps=6 format=3 uid="uid://bnftvkj2cido7"] [ext_resource type="Script" path="res://scripts/loader/sceneLoader/GameSceneLoader.cs" id="1_mqdgt"] [ext_resource type="Texture2D" uid="uid://cs6e0af876ss5" path="res://sprites/ui/HeartEmpty.png" id="2_n1yht"] [ext_resource type="Script" path="res://scripts/inventory/HotBar.cs" id="2_owrhq"] [ext_resource type="Script" path="res://scripts/HealthBarUi.cs" id="2_xrm3v"] +[ext_resource type="Script" path="res://scripts/FpsLabel.cs" id="5_dis4v"] [node name="Game" type="Node2D"] script = ExtResource("1_mqdgt") @@ -55,6 +56,17 @@ bbcode_enabled = true text = "OperationTip" fit_content = true +[node name="FPSLabel" type="Label" parent="CanvasLayer/Control"] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -40.0 +offset_bottom = 25.0 +grow_horizontal = 0 +horizontal_alignment = 2 +script = ExtResource("5_dis4v") + [node name="ProjectileContainer" type="Node2D" parent="."] [node name="DamageNumberContainer" type="Node2D" parent="."] diff --git a/scripts/FpsLabel.cs b/scripts/FpsLabel.cs new file mode 100644 index 0000000..415aed1 --- /dev/null +++ b/scripts/FpsLabel.cs @@ -0,0 +1,56 @@ +using Godot; + +namespace ColdMint.scripts; + +/// +/// FPSLabel +/// FPS标签 +/// +public partial class FpsLabel : Label +{ + bool _enable; + private LabelSettings? _labelSettings; + + public override void _Ready() + { + Text = null; + if (Config.IsDebug()) + { + _labelSettings = new LabelSettings(); + LabelSettings = _labelSettings; + _enable = true; + } + } + + public override void _Process(double delta) + { + if (!_enable) + { + return; + } + + var fps = Engine.GetFramesPerSecond(); + Text = "FPS:" + fps; + if (_labelSettings != null) + { + //Green above 54 frames (smooth) + //在54帧以上为绿色(流畅) + if (fps > 54) + { + _labelSettings.FontColor = Colors.Green; + } + else if (fps > 48) + { + //Yellow between 48 and 54 frames (Karting) + //在48到54帧之间为黄色(卡顿) + _labelSettings.FontColor = Colors.Yellow; + } + else + { + //Red below 48 frames (lag) + //在48帧以下为红色(卡) + _labelSettings.FontColor = Colors.Red; + } + } + } +} \ No newline at end of file diff --git a/scripts/debug/LogCat.cs b/scripts/debug/LogCat.cs index 37cac34..37a572e 100644 --- a/scripts/debug/LogCat.cs +++ b/scripts/debug/LogCat.cs @@ -58,8 +58,15 @@ public static class LogCat GD.Print(string.Format(HandleMessage(message).ToString(), args)); } - public static void LogError(Exception e) + /// + /// This method is called when an exception is caught + /// 当捕获异常后调用此方法 + /// + /// + public static void WhenCaughtException(Exception e) { + //Log an exception here or send it to the server. + //请在这里记录异常或将异常发送至服务器。 GD.PrintErr(HandleMessage(e.Message).Append('\n').Append(e.StackTrace)); } } \ No newline at end of file diff --git a/scripts/loader/sceneLoader/GameSceneLoader.cs b/scripts/loader/sceneLoader/GameSceneLoader.cs index d8745f7..d48f4f3 100644 --- a/scripts/loader/sceneLoader/GameSceneLoader.cs +++ b/scripts/loader/sceneLoader/GameSceneLoader.cs @@ -46,8 +46,8 @@ public partial class GameSceneLoader : SceneLoaderTemplate new RoomTemplate("res://prefab/roomTemplates/dungeon/horizontalCorridorWithSewer.tscn"); var horizontalCorridor = new RoomTemplate("res://prefab/roomTemplates/dungeon/horizontalCorridor.tscn"); roomProvider.AddRoom(initialRoom); - roomProvider.AddRoom(horizontalCorridor); roomProvider.AddRoom(horizontalCorridorWithSewer); + roomProvider.AddRoom(horizontalCorridor); roomProvider.AddRoom(utilityRoom); _mapGenerator.RoomProvider = roomProvider; diff --git a/scripts/map/MapGenerator.cs b/scripts/map/MapGenerator.cs index 5e611bd..5994ee6 100644 --- a/scripts/map/MapGenerator.cs +++ b/scripts/map/MapGenerator.cs @@ -70,8 +70,7 @@ public class MapGenerator : IMapGenerator } catch (Exception e) { - LogCat.LogError(e); - throw; + LogCat.WhenCaughtException(e); } } diff --git a/scripts/map/MapGeneratorConfig.cs b/scripts/map/MapGeneratorConfig.cs index f83bbec..e81be61 100644 --- a/scripts/map/MapGeneratorConfig.cs +++ b/scripts/map/MapGeneratorConfig.cs @@ -1,4 +1,5 @@ -using ColdMint.scripts.map.interfaces; +using ColdMint.scripts.debug; +using ColdMint.scripts.map.interfaces; using Godot; namespace ColdMint.scripts.map; @@ -9,15 +10,21 @@ public class MapGeneratorConfig : IMapGeneratorConfig /// At least how many rooms are generated /// 至少生成多少个房间 /// - public const int MinCount = 15; + public const int MinRoomCount = 15; /// /// Maximum number of rooms generated /// 最多生成多少个房间 /// - public const int MaxCount = 30; + public const int MaxRoomCount = 30; + + + public const int MinBranchCount = 3; + + public const int MaxBranchCount = 5; private int _roomCount; + private int _branchCount; public MapGeneratorConfig(Node2D mapRoot, ulong seed) { @@ -25,11 +32,14 @@ public class MapGeneratorConfig : IMapGeneratorConfig Seed = seed; RandomNumberGenerator = new RandomNumberGenerator(); RandomNumberGenerator.Seed = seed; - _roomCount = RandomNumberGenerator.RandiRange(MinCount, MaxCount); + _roomCount = RandomNumberGenerator.RandiRange(MinRoomCount, MaxRoomCount); + _branchCount = RandomNumberGenerator.RandiRange(MinBranchCount, MaxBranchCount); + LogCat.Log("Seed:" + seed + " RoomCount:" + _roomCount); } public Node2D MapRoot { get; } public int RoomCount => _roomCount; + public int BranchCount => _branchCount; public ulong Seed { get; } public RandomNumberGenerator RandomNumberGenerator { get; } diff --git a/scripts/map/interfaces/IBranch.cs b/scripts/map/interfaces/IBranch.cs new file mode 100644 index 0000000..715ed9a --- /dev/null +++ b/scripts/map/interfaces/IBranch.cs @@ -0,0 +1,18 @@ +namespace ColdMint.scripts.map.interfaces; + +/// +/// Represents a branch on the map. +/// 表示地图上的一个分支。 +/// +public interface IBranch +{ + /// + /// Master branch or not + /// 是否为主分支 + /// + bool IsMasterBranch + { + get; + set; + } +} \ No newline at end of file diff --git a/scripts/map/interfaces/IMapGeneratorConfig.cs b/scripts/map/interfaces/IMapGeneratorConfig.cs index 548d448..6444f97 100644 --- a/scripts/map/interfaces/IMapGeneratorConfig.cs +++ b/scripts/map/interfaces/IMapGeneratorConfig.cs @@ -16,6 +16,12 @@ public interface IMapGeneratorConfig /// int RoomCount { get; } + /// + /// The number of forks in this map + /// 这个地图的分叉数量 + /// + int BranchCount { get; } + /// /// seed /// 种子 diff --git a/scripts/map/interfaces/IRoomHolder.cs b/scripts/map/interfaces/IRoomHolder.cs index 01e749c..1185876 100644 --- a/scripts/map/interfaces/IRoomHolder.cs +++ b/scripts/map/interfaces/IRoomHolder.cs @@ -1,5 +1,13 @@ namespace ColdMint.scripts.map.interfaces; +/// +/// Room holder +/// 房间持有者 +/// +/// +///This class holds all generated and placed rooms. +///该类保存所有已生成且已放置的房间。 +/// public interface IRoomHolder { bool AddRoom(IRoom room); diff --git a/scripts/map/interfaces/IRoomProvider.cs b/scripts/map/interfaces/IRoomProvider.cs index e80a606..ec2b8f9 100644 --- a/scripts/map/interfaces/IRoomProvider.cs +++ b/scripts/map/interfaces/IRoomProvider.cs @@ -1,5 +1,13 @@ namespace ColdMint.scripts.map.interfaces; +/// +/// Room provider +/// 房间提供者 +/// +/// +///Responsible for providing room templates for map generator. +///负责为地图生成器提供房间模板。 +/// public interface IRoomProvider { ///