diff --git a/DungeonShooting_Godot/scene/Main.tscn b/DungeonShooting_Godot/scene/Main.tscn
index aff7b6d..646feca 100644
--- a/DungeonShooting_Godot/scene/Main.tscn
+++ b/DungeonShooting_Godot/scene/Main.tscn
@@ -1,9 +1,10 @@
-[gd_scene load_steps=7 format=2]
+[gd_scene load_steps=8 format=2]
[ext_resource path="res://scene/Room.tscn" type="PackedScene" id=1]
[ext_resource path="res://prefab/ui/RoomUI.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/game/GameApplication.cs" type="Script" id=3]
[ext_resource path="res://prefab/ui/Cursor.tscn" type="PackedScene" id=4]
+[ext_resource path="res://resource/font/cn_font_18.tres" type="DynamicFont" id=5]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
@@ -30,6 +31,7 @@
ViewportContainerPath = NodePath("ViewCanvas/ViewportContainer")
UiPath = NodePath("UiCanvas/RoomUI")
GlobalNodeRootPath = NodePath("GlobalNodeRoot")
+Font = ExtResource( 5 )
[node name="ViewCanvas" type="CanvasLayer" parent="."]
layer = -1
diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs
index c6e5b35..517f5ef 100644
--- a/DungeonShooting_Godot/src/game/GameApplication.cs
+++ b/DungeonShooting_Godot/src/game/GameApplication.cs
@@ -17,6 +17,8 @@
[Export] public NodePath GlobalNodeRootPath;
+ [Export] public Font Font;
+
///
/// 鼠标指针
///
@@ -70,6 +72,6 @@
public Vector2 ViewToGlobalPosition(Vector2 viewPos)
{
- return (viewPos - GameCamera.Main.GlobalPosition + (GameConfig.ViewportSize / 2)) * GameConfig.WindowScale;
+ return (viewPos - GameCamera.Main.GlobalPosition + (GameConfig.ViewportSize / 2)) * GameConfig.WindowScale - GameCamera.Main.SubPixelPosition;
}
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/camera/GameCamera.cs b/DungeonShooting_Godot/src/game/camera/GameCamera.cs
index 70ca0e0..4b827de 100644
--- a/DungeonShooting_Godot/src/game/camera/GameCamera.cs
+++ b/DungeonShooting_Godot/src/game/camera/GameCamera.cs
@@ -20,6 +20,8 @@
/// 抖动开关
///
public bool Enable { get; set; } = true;
+
+ public Vector2 SubPixelPosition { get; private set; }
private long _index = 0;
private Vector2 _processDistance = Vector2.Zero;
@@ -48,8 +50,8 @@
//var camPos = player.GlobalPosition.LinearInterpolate(mousePos, 0);
//_camPos = camPos + _shakeOffset;
_camPos = _camPos.LinearInterpolate(camPos, Mathf.Min(5 * delta, 1)) + _shakeOffset;
- var camSubpixelPos = _camPos.Round() - _camPos;
- (viewportContainer.Material as ShaderMaterial)?.SetShaderParam("offset", camSubpixelPos);
+ SubPixelPosition = _camPos.Round() - _camPos;
+ (viewportContainer.Material as ShaderMaterial)?.SetShaderParam("offset", SubPixelPosition);
//GlobalPosition = _camPos.Round();
GlobalPosition = _camPos.Round();
}
diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs
index c2dd69f..4c629f2 100644
--- a/DungeonShooting_Godot/src/game/role/Player.cs
+++ b/DungeonShooting_Godot/src/game/role/Player.cs
@@ -45,9 +45,6 @@
}
}
private int _maxShield = 0;
-
- private Vector2 _v1;
- private Vector2 _v2;
[Export] public PackedScene GunPrefab;
@@ -59,8 +56,6 @@
{
base._Ready();
- _v1 = _v2 = Position;
-
//让相机跟随玩家
// var remoteTransform = new RemoteTransform2D();
// AddChild(remoteTransform);
@@ -95,10 +90,6 @@
{
Face = FaceDirection.Left;
}
-
- //var f = Mathf.Clamp(Engine.GetPhysicsInterpolationFraction(), 0, 1);
- //Position = _v1.LinearInterpolate(_v2, f).Round();
- // GD.Print($"Position: {_realPos}, f: {f}");
if (Input.IsActionJustPressed("exchange")) //切换武器
{
@@ -129,13 +120,18 @@
//刷新显示的弹药剩余量
RefreshGunAmmunition();
+ var reloadBar = GameApplication.Instance.Ui.ReloadBar;
if (Holster.ActiveWeapon != null && Holster.ActiveWeapon.Reloading)
{
- GameApplication.Instance.Ui.ReloadBar.ShowBar(gPos, 1 - Holster.ActiveWeapon.ReloadProgress);
+ if (!reloadBar.Visible)
+ {
+ reloadBar.ShowBar(gPos);
+ }
+ reloadBar.UpdateProcess(1 - Holster.ActiveWeapon.ReloadProgress);
}
else
{
- GameApplication.Instance.Ui.ReloadBar.HideBar();
+ reloadBar.HideBar();
}
}
@@ -171,7 +167,7 @@
if (InteractiveItem is Weapon gun)
{
//显示互动提示
- GameApplication.Instance.Ui.InteractiveTipBar.ShowBar(result.Target.GlobalPosition, result.ShowIcon, result.Message);
+ GameApplication.Instance.Ui.InteractiveTipBar.ShowBar(result.Target, result.ShowIcon, result.Message);
}
}
}
@@ -227,10 +223,7 @@
if (Mathf.IsZeroApprox(dir.y)) Velocity.y = Mathf.MoveToward(Velocity.y, 0, Friction * delta);
else Velocity.y = Mathf.MoveToward(Velocity.y, dir.y * MoveSpeed, Acceleration * delta);
- //_v1 = Position = _v2;
Velocity = MoveAndSlide(Velocity);
- //_v2 = Position;
- //Position = _v1.Round();
}
// 播放动画
diff --git a/DungeonShooting_Godot/src/game/ui/InteractiveTipBar.cs b/DungeonShooting_Godot/src/game/ui/InteractiveTipBar.cs
index b582128..5bf48c4 100644
--- a/DungeonShooting_Godot/src/game/ui/InteractiveTipBar.cs
+++ b/DungeonShooting_Godot/src/game/ui/InteractiveTipBar.cs
@@ -6,6 +6,8 @@
public class InteractiveTipBar : Node2D
{
+ private ActivityObject Target;
+
private Label Message;
private Sprite Icon;
private Sprite Bg;
@@ -30,12 +32,13 @@
///
/// 显示互动提示ui
///
- /// 所在坐标
+ /// 所在坐标
/// 显示图标
/// 显示文本
- public void ShowBar(Vector2 pos, string icon, string message)
+ public void ShowBar(ActivityObject target, string icon, string message)
{
- GlobalPosition = GameApplication.Instance.ViewToGlobalPosition(pos);
+ Target = target;
+ GlobalPosition = GameApplication.Instance.ViewToGlobalPosition(target.GlobalPosition);
Message.Text = message;
if (currImage != icon)
{
@@ -44,4 +47,20 @@
}
Visible = true;
}
+
+ public override void _Process(float delta)
+ {
+ if (Visible)
+ {
+ var pos = GameApplication.Instance.ViewToGlobalPosition(Target.GlobalPosition);
+ GlobalPosition = pos.Round();
+
+ }
+ }
+
+ public override void _Draw()
+ {
+ DrawString(GameApplication.Instance.Font, new Vector2(0, 20), GlobalPosition.ToString(), Colors.Red);
+ GD.Print("draw...");
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/ReloadBar.cs b/DungeonShooting_Godot/src/game/ui/ReloadBar.cs
index 520a332..6e417c5 100644
--- a/DungeonShooting_Godot/src/game/ui/ReloadBar.cs
+++ b/DungeonShooting_Godot/src/game/ui/ReloadBar.cs
@@ -31,13 +31,21 @@
/// 显示换弹进度组件
///
/// 坐标
- /// 进度, 0 - 1
- public void ShowBar(Vector2 position, float progress)
+ public void ShowBar(Vector2 position)
{
Visible = true;
GlobalPosition = GameApplication.Instance.ViewToGlobalPosition(position);
+
+ }
+
+ ///
+ /// 更新进度
+ ///
+ /// 进度, 0 - 1
+ public void UpdateProcess(float progress)
+ {
progress = Mathf.Clamp(progress, 0, 1);
block.Position = new Vector2(startX + (width - 3) * progress, 0);
}
-
+
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/RoomUI.cs b/DungeonShooting_Godot/src/game/ui/RoomUI.cs
index b2427a9..8d51213 100644
--- a/DungeonShooting_Godot/src/game/ui/RoomUI.cs
+++ b/DungeonShooting_Godot/src/game/ui/RoomUI.cs
@@ -71,6 +71,19 @@
tempNode.CallDeferred("queue_free");
}
+ public override void _Process(float delta)
+ {
+
+ }
+
+ public override void _PhysicsProcess(float delta)
+ {
+ // var colorRect = GetNode("ColorRect");
+ // var pos = GameApplication.Instance.ViewToGlobalPosition(GameApplication.Instance.Room.Player.GlobalPosition);
+ // colorRect.SetGlobalPosition(pos);
+ //GD.Print("pos: " + pos + ", " + colorRect.RectGlobalPosition);
+ }
+
///
/// 设置最大血量
///