diff --git a/DungeonShooting_Godot/export_presets.cfg b/DungeonShooting_Godot/export_presets.cfg
new file mode 100644
index 0000000..540aecb
--- /dev/null
+++ b/DungeonShooting_Godot/export_presets.cfg
@@ -0,0 +1,66 @@
+[preset.0]
+
+name="UWP"
+platform="UWP"
+runnable=true
+custom_features=""
+export_filter="all_resources"
+include_filter=""
+exclude_filter=""
+export_path=""
+script_export_mode=1
+script_encryption_key=""
+
+[preset.0.options]
+
+custom_template/debug=""
+custom_template/release=""
+architecture/target=1
+command_line/extra_args=""
+package/display_name=""
+package/short_name=""
+package/unique_name=""
+package/description=""
+package/publisher=""
+package/publisher_display_name=""
+identity/product_guid=""
+identity/publisher_guid=""
+signing/certificate=""
+signing/password=""
+signing/algorithm=2
+version/major=1
+version/minor=0
+version/build=0
+version/revision=0
+orientation/landscape=true
+orientation/portrait=true
+orientation/landscape_flipped=true
+orientation/portrait_flipped=true
+images/background_color="transparent"
+tiles/show_name_on_square150x150=false
+tiles/show_name_on_wide310x150=false
+tiles/show_name_on_square310x310=false
+capabilities/allJoyn=false
+capabilities/codeGeneration=false
+capabilities/internetClient=false
+capabilities/internetClientServer=false
+capabilities/privateNetworkClientServer=false
+capabilities/appointments=false
+capabilities/blockedChatMessages=false
+capabilities/chat=false
+capabilities/contacts=false
+capabilities/enterpriseAuthentication=false
+capabilities/musicLibrary=false
+capabilities/objects3D=false
+capabilities/picturesLibrary=false
+capabilities/phoneCall=false
+capabilities/removableStorage=false
+capabilities/sharedUserCertificates=false
+capabilities/userAccountInformation=false
+capabilities/videosLibrary=false
+capabilities/voipCall=false
+capabilities/bluetooth=false
+capabilities/location=false
+capabilities/microphone=false
+capabilities/proximity=false
+capabilities/webcam=false
diff --git a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn
index 682de6a..778ffae 100644
--- a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn
+++ b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn
@@ -36,7 +36,7 @@
[node name="HpSlot" type="NinePatchRect" parent="Control/HealthBar"]
margin_left = 13.0
margin_top = 1.0
-margin_right = 81.0
+margin_right = 66.0
margin_bottom = 9.0
texture = ExtResource( 8 )
patch_margin_left = 1
@@ -47,7 +47,7 @@
[node name="HpBar" type="TextureRect" parent="Control/HealthBar/HpSlot"]
margin_left = 1.0
margin_top = 2.0
-margin_right = 66.0
+margin_right = 51.0
margin_bottom = 6.0
texture = ExtResource( 6 )
expand = true
@@ -55,7 +55,7 @@
[node name="ShieldSlot" type="NinePatchRect" parent="Control/HealthBar"]
margin_left = 13.0
margin_top = 8.0
-margin_right = 87.0
+margin_right = 65.0
margin_bottom = 13.0
texture = ExtResource( 9 )
patch_margin_left = 1
@@ -66,7 +66,7 @@
[node name="ShieldBar" type="TextureRect" parent="Control/HealthBar/ShieldSlot"]
margin_left = 1.0
margin_top = 1.0
-margin_right = 73.0
+margin_right = 51.0
margin_bottom = 4.0
texture = ExtResource( 7 )
expand = true
@@ -78,13 +78,13 @@
margin_bottom = 44.0
texture = ExtResource( 2 )
-[node name="Control" type="Control" parent="Control"]
+[node name="GunBar" type="Control" parent="Control"]
anchor_top = 1.0
anchor_bottom = 1.0
margin_top = -43.0
margin_right = 40.0
-[node name="GunBar" type="TextureRect" parent="Control/Control"]
+[node name="GunSprite" type="TextureRect" parent="Control/GunBar"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
@@ -95,7 +95,7 @@
margin_bottom = 33.0
texture = ExtResource( 5 )
-[node name="BulletBar" type="Label" parent="Control/Control"]
+[node name="BulletText" type="Label" parent="Control/GunBar"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -28.0
diff --git a/DungeonShooting_Godot/scene/Room.tscn b/DungeonShooting_Godot/scene/Room.tscn
index 439a225..6a49872 100644
--- a/DungeonShooting_Godot/scene/Room.tscn
+++ b/DungeonShooting_Godot/scene/Room.tscn
@@ -12,6 +12,10 @@
MouseCursor = ExtResource( 4 )
UIPath = NodePath("")
+[node name="CanvasLayer" type="CanvasLayer" parent="."]
+
+[node name="RoomUI" parent="CanvasLayer" instance=ExtResource( 6 )]
+
[node name="MapRoot" type="Node2D" parent="."]
z_index = -10
@@ -34,7 +38,3 @@
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="ItemRoot/Player"]
remote_path = NodePath("../../../Camera2D")
-
-[node name="CanvasLayer" type="CanvasLayer" parent="."]
-
-[node name="RoomUI" parent="CanvasLayer" instance=ExtResource( 6 )]
diff --git a/DungeonShooting_Godot/src/manager/GameManager.cs b/DungeonShooting_Godot/src/manager/GameManager.cs
index 29d3962..5631110 100644
--- a/DungeonShooting_Godot/src/manager/GameManager.cs
+++ b/DungeonShooting_Godot/src/manager/GameManager.cs
@@ -5,9 +5,12 @@
///
public class GameManager : Node2D
{
+
public static GameManager Instance { get; private set; }
+
public GameManager()
{
GameManager.Instance = this;
}
+
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/role/Player.cs b/DungeonShooting_Godot/src/role/Player.cs
index d6ed468..dd1a4c2 100644
--- a/DungeonShooting_Godot/src/role/Player.cs
+++ b/DungeonShooting_Godot/src/role/Player.cs
@@ -16,6 +16,37 @@
///
public Vector2 Velocity = Vector2.Zero;
+ ///
+ /// 当前护盾值
+ ///
+ public int Shield
+ {
+ get => _shield;
+ protected set
+ {
+ int temp = _shield;
+ _shield = value;
+ if (temp != _shield) OnChangeShield(_shield);
+ }
+ }
+ private int _shield = 0;
+
+ ///
+ /// 最大护盾值
+ ///
+ public int MaxShield
+ {
+ get => _maxShield;
+ protected set
+ {
+ int temp = _maxShield;
+ _maxShield = value;
+ if (temp != _maxShield) OnChangeMaxShield(_maxShield);
+ }
+ }
+ private int _maxShield = 0;
+
+
[Export] public PackedScene GunPrefab;
public override void _EnterTree()
@@ -33,6 +64,12 @@
PickUpGun(GunManager.GetGun2()); //1
PickUpGun(GunManager.GetGun3()); //2
PickUpGun(GunManager.GetGun4()); //3
+ RefreshGunTexture();
+
+ MaxHp = 50;
+ Hp = 40;
+ MaxShield = 30;
+ Shield = 10;
}
public override void _Process(float delta)
@@ -55,14 +92,17 @@
if (Input.IsActionJustPressed("exchange")) //切换武器
{
TriggerExchangeNext();
+ RefreshGunTexture();
}
else if (Input.IsActionJustPressed("throw")) //扔掉武器
{
TriggerThrowGun();
+ RefreshGunTexture();
}
else if (Input.IsActionJustPressed("interactive")) //互动物体
{
TriggerTnteractive();
+ RefreshGunTexture();
}
else if (Input.IsActionJustPressed("reload")) //换弹
{
@@ -72,6 +112,8 @@
{
TriggerAttack();
}
+ //刷新显示的弹药剩余量
+ RefreshGunAmmunition();
}
public override void _PhysicsProcess(float delta)
@@ -82,6 +124,54 @@
PlayAnim();
}
+ protected override void OnChangeHp(int hp)
+ {
+ RoomUI.Current.SetHp(hp);
+ }
+
+ protected override void OnChangeMaxHp(int maxHp)
+ {
+ RoomUI.Current.SetMaxHp(maxHp);
+ }
+
+ protected void OnChangeShield(int shield)
+ {
+ RoomUI.Current.SetShield(shield);
+ }
+
+ protected void OnChangeMaxShield(int maxShield)
+ {
+ RoomUI.Current.SetMaxShield(maxShield);
+ }
+
+ ///
+ /// 刷新 ui 上手持的物体
+ ///
+ private void RefreshGunTexture()
+ {
+ var gun = Holster.ActiveGun;
+ if (gun != null)
+ {
+ RoomUI.Current.SetGunTexture(gun.Attribute.Sprite);
+ }
+ else
+ {
+ RoomUI.Current.SetGunTexture(null);
+ }
+ }
+
+ ///
+ /// 刷新 ui 上显示的弹药量
+ ///
+ private void RefreshGunAmmunition()
+ {
+ var gun = Holster.ActiveGun;
+ if (gun != null)
+ {
+ RoomUI.Current.SetAmmunition(gun.CurrAmmo, gun.ResidueAmmo);
+ }
+ }
+
private void Move(float delta)
{
//角色移动
diff --git a/DungeonShooting_Godot/src/role/Role.cs b/DungeonShooting_Godot/src/role/Role.cs
index 335ba00..d132261 100644
--- a/DungeonShooting_Godot/src/role/Role.cs
+++ b/DungeonShooting_Godot/src/role/Role.cs
@@ -13,7 +13,7 @@
///
/// 角色基类
///
-public class Role : KinematicBody2D
+public abstract class Role : KinematicBody2D
{
///
/// 重写的纹理
@@ -59,9 +59,48 @@
public FaceDirection Face { get => _face; set => SetFace(value); }
private FaceDirection _face;
+ ///
+ /// 血量
+ ///
+ public int Hp
+ {
+ get => _hp;
+ protected set
+ {
+ int temp = _hp;
+ _hp = value;
+ if (temp != _hp) OnChangeHp(_hp);
+ }
+ }
+ private int _hp = 0;
+
+ ///
+ /// 最大血量
+ ///
+ public int MaxHp
+ {
+ get => _maxHp;
+ protected set
+ {
+ int temp = _maxHp;
+ _maxHp = value;
+ if (temp != _maxHp) OnChangeMaxHp(_maxHp);
+ }
+ }
+ private int _maxHp = 0;
+
private Vector2 StartScele;
private readonly List InteractiveItemList = new List();
+ ///
+ /// 当血量改变时调用
+ ///
+ protected abstract void OnChangeHp(int hp);
+ ///
+ /// 当最大血量改变时调用
+ ///
+ protected abstract void OnChangeMaxHp(int maxHp);
+
public override void _Ready()
{
StartScele = Scale;
@@ -211,28 +250,30 @@
///
/// 连接信号: InteractiveArea.area_entered
+ /// 与道具碰撞
///
private void _OnPropsEnter(Area2D other)
{
- if (other is Gun gun)
+ if (other is IProp prop)
{
- if (!InteractiveItemList.Contains(gun))
+ if (!InteractiveItemList.Contains(prop))
{
- InteractiveItemList.Add(gun);
+ InteractiveItemList.Add(prop);
}
}
}
///
/// 连接信号: InteractiveArea.area_exited
+ /// 道具离开碰撞区域
///
private void _OnPropsExit(Area2D other)
{
- if (other is Gun gun)
+ if (other is IProp prop)
{
- if (InteractiveItemList.Contains(gun))
+ if (InteractiveItemList.Contains(prop))
{
- InteractiveItemList.Remove(gun);
+ InteractiveItemList.Remove(prop);
}
}
}
diff --git a/DungeonShooting_Godot/src/ui/RoomUI.cs b/DungeonShooting_Godot/src/ui/RoomUI.cs
index 2b5a2bf..bab552b 100644
--- a/DungeonShooting_Godot/src/ui/RoomUI.cs
+++ b/DungeonShooting_Godot/src/ui/RoomUI.cs
@@ -1,9 +1,133 @@
+using System;
using Godot;
+///
+/// 房间中的ui
+///
public class RoomUI : Control
{
+
+ public static RoomUI Current { get; private set; }
+
+ ///
+ /// 当前血量
+ ///
+ public int Hp { get; private set; }
+ ///
+ /// 最大血量
+ ///
+ public int MaxHp { get; private set; }
+ ///
+ /// 当前护盾值
+ ///
+ public int Shield { get; private set; }
+ ///
+ /// 最大护盾值
+ ///
+ public int MaxShield { get; private set; }
+
+
+ private NinePatchRect hpSlot;
+ private NinePatchRect shieldSlot;
+ private TextureRect hpBar;
+ private TextureRect shieldBar;
+ private Label bulletText;
+ private TextureRect gunSprite;
+
+ public override void _EnterTree()
+ {
+ Current = this;
+ }
+
public override void _Ready()
{
-
+ hpSlot = GetNode("Control/HealthBar/HpSlot");
+ shieldSlot = GetNode("Control/HealthBar/ShieldSlot");
+ hpBar = GetNode("Control/HealthBar/HpSlot/HpBar");
+ shieldBar = GetNode("Control/HealthBar/ShieldSlot/ShieldBar");
+
+ bulletText = GetNode