diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index 0389b0f..e2b99e5 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] [ext_resource path="res://src/role/Player.cs" type="Script" id=2] +[ext_resource path="res://resource/sprite/ui/keyboard/e.png" type="Texture" id=3] [ext_resource path="res://prefab/weapon/Gun.tscn" type="PackedScene" id=4] +[ext_resource path="res://resource/sprite/shell/shellCase.png" type="Texture" id=5] +[ext_resource path="res://resource/font/cn_font_4.tres" type="DynamicFont" id=6] [node name="Player" instance=ExtResource( 1 )] collision_layer = 8 @@ -10,4 +13,36 @@ GunPrefab = ExtResource( 4 ) [node name="AnimatedSprite" parent="." index="0"] -frame = 0 +frame = 3 + +[node name="ColorRect" type="ColorRect" parent="." index="6"] +visible = false +margin_left = -9.0 +margin_top = -24.0 +margin_right = 11.0 +margin_bottom = -18.0 +color = Color( 0.784314, 0.784314, 0.784314, 0.588235 ) + +[node name="ShellCase" type="TextureRect" parent="ColorRect" index="0"] +margin_left = 1.0 +margin_top = 5.0 +margin_right = 5.0 +margin_bottom = 7.0 +rect_rotation = -90.0 +texture = ExtResource( 5 ) + +[node name="Label" type="Label" parent="ColorRect" index="1"] +margin_left = 1.0 +margin_top = -2.0 +margin_right = 21.0 +margin_bottom = 9.0 +custom_colors/font_color = Color( 0, 0, 0, 1 ) +custom_fonts/font = ExtResource( 6 ) +text = "M1911" + +[node name="E" type="TextureRect" parent="ColorRect" index="2"] +margin_left = 5.0 +margin_top = -12.0 +margin_right = 14.0 +margin_bottom = -1.0 +texture = ExtResource( 3 ) diff --git a/DungeonShooting_Godot/prefab/ui/Cursor.tscn b/DungeonShooting_Godot/prefab/ui/Cursor.tscn index dd76fcc..4eae533 100644 --- a/DungeonShooting_Godot/prefab/ui/Cursor.tscn +++ b/DungeonShooting_Godot/prefab/ui/Cursor.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://src/effect/Cursor.cs" type="Script" id=2] [node name="Cursor" type="Node2D"] -z_index = 15 +z_index = 10 script = ExtResource( 2 ) [node name="LT" type="Sprite" parent="."] diff --git a/DungeonShooting_Godot/resource/font/cn_font_4.tres b/DungeonShooting_Godot/resource/font/cn_font_4.tres new file mode 100644 index 0000000..76f4221 --- /dev/null +++ b/DungeonShooting_Godot/resource/font/cn_font_4.tres @@ -0,0 +1,11 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://SourceHanSerifCN-SemiBold.otf" type="DynamicFontData" id=1] + +[resource] +size = 4 +use_mipmaps = true +use_filter = true +extra_spacing_top = -2 +extra_spacing_bottom = -2 +font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/resource/font/cn_font_6.tres b/DungeonShooting_Godot/resource/font/cn_font_6.tres index df04fd6..5c63c44 100644 --- a/DungeonShooting_Godot/resource/font/cn_font_6.tres +++ b/DungeonShooting_Godot/resource/font/cn_font_6.tres @@ -6,5 +6,4 @@ size = 6 use_mipmaps = true use_filter = true -extra_spacing_char = 1 font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/scene/Room.tscn b/DungeonShooting_Godot/scene/Room.tscn index 6a49872..870408c 100644 --- a/DungeonShooting_Godot/scene/Room.tscn +++ b/DungeonShooting_Godot/scene/Room.tscn @@ -10,11 +10,10 @@ [node name="Room" type="Node2D"] script = ExtResource( 3 ) MouseCursor = ExtResource( 4 ) -UIPath = NodePath("") -[node name="CanvasLayer" type="CanvasLayer" parent="."] +[node name="UI" type="CanvasLayer" parent="."] -[node name="RoomUI" parent="CanvasLayer" instance=ExtResource( 6 )] +[node name="RoomUI" parent="UI" instance=ExtResource( 6 )] [node name="MapRoot" type="Node2D" parent="."] z_index = -10 diff --git a/DungeonShooting_Godot/src/role/Player.cs b/DungeonShooting_Godot/src/role/Player.cs index dd1a4c2..4718b69 100644 --- a/DungeonShooting_Godot/src/role/Player.cs +++ b/DungeonShooting_Godot/src/role/Player.cs @@ -134,6 +134,21 @@ RoomUI.Current.SetMaxHp(maxHp); } + protected override void ChangeInteractiveItem() + { + if (InteractiveItem == null) + { + //GD.Print("没有可互动的道具了"); + } + else + { + if (InteractiveItem is Gun gun) + { + //GD.Print("更新可互动的道具: " + gun.Attribute.Name); + } + } + } + protected void OnChangeShield(int shield) { RoomUI.Current.SetShield(shield); diff --git a/DungeonShooting_Godot/src/role/Role.cs b/DungeonShooting_Godot/src/role/Role.cs index 559c1eb..03e1ce6 100644 --- a/DungeonShooting_Godot/src/role/Role.cs +++ b/DungeonShooting_Godot/src/role/Role.cs @@ -90,7 +90,12 @@ private int _maxHp = 0; private Vector2 StartScele; + //所有角色碰撞的道具 private readonly List InteractiveItemList = new List(); + /// + /// 可以互动的道具 + /// + protected IProp InteractiveItem { get; private set; } /// /// 当血量改变时调用 @@ -101,6 +106,12 @@ /// protected abstract void OnChangeMaxHp(int maxHp); + /// + /// 当可互动的物体改变时调用, 从 this.InteractiveItem 取值 + /// + /// + protected abstract void ChangeInteractiveItem(); + public override void _Ready() { StartScele = Scale; @@ -116,6 +127,42 @@ Face = FaceDirection.Right; } + public override void _Process(float delta) + { + //检查可互动的道具 + bool findFlag = false; + for (int i = 0; i < InteractiveItemList.Count; i++) + { + var item = InteractiveItemList[i]; + if (item == null) + { + InteractiveItemList.RemoveAt(i--); + } + else + { + //找到可互动的道具了 + if (!findFlag && item.CanTnteractive(this)) + { + findFlag = true; + if (InteractiveItem != item) + { + InteractiveItem = item; + GD.Print("--------change"); + ChangeInteractiveItem(); + } + } + } + } + //没有可互动的道具 + if (!findFlag && InteractiveItem != null) + { + InteractiveItem = null; + GD.Print("--------remove1"); + ChangeInteractiveItem(); + } + } + + /// /// 拾起一个武器, 并且切换到这个武器 /// @@ -159,7 +206,7 @@ /// public bool HasTnteractive() { - return InteractiveItemList.Count > 0; + return InteractiveItem != null; } /// @@ -169,8 +216,7 @@ { if (HasTnteractive()) { - var item = InteractiveItemList[InteractiveItemList.Count - 1]; - item.Tnteractive(this); + InteractiveItem.Tnteractive(this); } } @@ -236,31 +282,38 @@ /// /// 连接信号: InteractiveArea.area_entered - /// 与道具碰撞 + /// 与物体碰撞 /// private void _OnPropsEnter(Area2D other) { - if (other is IProp prop) + if (other is IProp prop) //道具类型 { if (!InteractiveItemList.Contains(prop)) { InteractiveItemList.Add(prop); + GD.Print("--------add"); } } } /// /// 连接信号: InteractiveArea.area_exited - /// 道具离开碰撞区域 + /// 物体离开碰撞区域 /// private void _OnPropsExit(Area2D other) { - if (other is IProp prop) + if (other is IProp prop) //道具类型 { if (InteractiveItemList.Contains(prop)) { InteractiveItemList.Remove(prop); } + if (InteractiveItem == prop) + { + InteractiveItem = null; + GD.Print("--------remove2"); + ChangeInteractiveItem(); + } } } diff --git a/DungeonShooting_Godot/src/room/RoomManager.cs b/DungeonShooting_Godot/src/room/RoomManager.cs index 7567ae7..2697778 100644 --- a/DungeonShooting_Godot/src/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/room/RoomManager.cs @@ -11,8 +11,6 @@ /// [Export] public PackedScene MouseCursor; - [Export] public NodePath UIPath; - public static RoomManager Current { get; private set; } public CanvasLayer UI; @@ -25,6 +23,9 @@ { Current = this; Input.MouseMode = Input.MouseModeEnum.Hidden; + + UI = GetNode("UI"); + // 初始化鼠标 Cursor = MouseCursor.Instance(); AddChild(Cursor); @@ -61,9 +62,6 @@ public override void _Process(float delta) { - if (Input.IsActionJustPressed("fire")) - { - //CommonNodeManager.CreateThrowNode(); - } + } } \ No newline at end of file