diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs
index e99890a..84b1505 100644
--- a/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs
+++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs
@@ -41,8 +41,6 @@
///
/// 扫描指定程序集, 自动注册带有 RegisterActivity 特性的类
///
- ///
- ///
public static void ScannerFromAssembly(Assembly assembly)
{
var types = assembly.GetTypes();
diff --git a/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs b/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs
index f5f1a03..d3247b1 100644
--- a/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs
+++ b/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs
@@ -10,7 +10,7 @@
///
/// 注册物体唯一ID, 该ID不能有重复
///
- public string Id { get; }
+ public string Id { get; protected set; }
///
/// 模板 Prefab 的路径
diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs
index dcbfc30..8dfea92 100644
--- a/DungeonShooting_Godot/src/game/GameApplication.cs
+++ b/DungeonShooting_Godot/src/game/GameApplication.cs
@@ -113,8 +113,9 @@
///
public Vector2 ViewToGlobalPosition(Vector2 viewPos)
{
- //return viewPos;
- return (viewPos - GameCamera.Main.GlobalPosition + (GameConfig.ViewportSize / 2)) * GameConfig.WindowScale - GameCamera.Main.SubPixelPosition;
+ // 3.5写法
+ //return (viewPos - GameCamera.Main.GlobalPosition + (GameConfig.ViewportSize / 2)) * GameConfig.WindowScale - GameCamera.Main.SubPixelPosition;
+ return (viewPos - GameCamera.Main.GlobalPosition + (GameConfig.ViewportSize / 2)) * GameConfig.WindowScale;
}
//初始化房间配置
diff --git a/DungeonShooting_Godot/src/game/camera/GameCamera.cs b/DungeonShooting_Godot/src/game/camera/GameCamera.cs
index 8850463..2dc34fe 100644
--- a/DungeonShooting_Godot/src/game/camera/GameCamera.cs
+++ b/DungeonShooting_Godot/src/game/camera/GameCamera.cs
@@ -16,16 +16,24 @@
///
[Export]
public float RecoveryCoefficient = 100f;
+
///
/// 抖动开关
///
- public bool Enable { get; set; } = true;
+ public bool EnableShake { get; set; } = true;
+
+ ///
+ /// 相机跟随目标
+ ///
+ private Role _followTarget;
- public Vector2 SubPixelPosition { get; private set; }
+ // 3.5
+ //public Vector2 SubPixelPosition { get; private set; }
private long _index = 0;
private Vector2 _processDistance = Vector2.Zero;
private Vector2 _processDirection = Vector2.Zero;
+ //抖动数据
private readonly Dictionary _shakeMap = new Dictionary();
private Vector2 _camPos;
@@ -50,22 +58,40 @@
// SubPixelPosition = _camPos.Round() - _camPos;
// (viewportContainer.Material as ShaderMaterial)?.SetShaderParameter("offset", SubPixelPosition);
// GlobalPosition = _camPos.Round();
-
- var player = GameApplication.Instance.RoomManager.Player;
- var mousePosition = InputManager.GetViewportMousePosition();
- var playerPosition = player.GlobalPosition;
- Vector2 targetPos;
- if (playerPosition.DistanceSquaredTo(mousePosition) >= (60 / 0.3f) * (60 / 0.3f))
+
+ if (_followTarget != null)
{
- targetPos = playerPosition.MoveToward(mousePosition, 60);
+ var mousePosition = InputManager.GetViewportMousePosition();
+ var targetPosition = _followTarget.GlobalPosition;
+ Vector2 targetPos;
+ if (targetPosition.DistanceSquaredTo(mousePosition) >= (60 / 0.3f) * (60 / 0.3f))
+ {
+ targetPos = targetPosition.MoveToward(mousePosition, 60);
+ }
+ else
+ {
+ targetPos = targetPosition.Lerp(mousePosition, 0.3f);
+ }
+ _camPos = _camPos.Lerp(targetPos, Mathf.Min(6 * newDelta, 1)) + _shakeOffset;
+ GlobalPosition = _camPos.Round();
}
- else
- {
- targetPos = playerPosition.Lerp(mousePosition, 0.3f);
- }
- _camPos = _camPos.Lerp(targetPos, Mathf.Min(6 * newDelta, 1)) + _shakeOffset;
- SubPixelPosition = _camPos.Round() - _camPos;
- GlobalPosition = _camPos.Round();
+ }
+
+ ///
+ /// 设置相机跟随目标
+ ///
+ public void SetFollowTarget(Role target)
+ {
+ _followTarget = target;
+ GlobalPosition = target.GlobalPosition;
+ }
+
+ ///
+ /// 获取相机跟随目标
+ ///
+ public Role GetFollowTarget()
+ {
+ return _followTarget;
}
///
@@ -105,7 +131,7 @@
//抖动调用
private void _Shake(float delta)
{
- if (Enable)
+ if (EnableShake)
{
var distance = _CalculateDistance();
_shakeOffset += _processDirection + new Vector2(
diff --git a/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs b/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs
index 6ee6ea3..0ee6aad 100644
--- a/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs
+++ b/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs
@@ -6,19 +6,22 @@
///
public class RegisterWeapon : RegisterActivity
{
- public WeaponAttribute WeaponAttribute { get; }
+ ///
+ /// 武器属性
+ ///
+ private readonly WeaponAttribute _weaponAttribute;
public RegisterWeapon(string id, Type attribute) : base(id, null)
{
- WeaponAttribute = (WeaponAttribute)Activator.CreateInstance(attribute);
- if (WeaponAttribute != null) PrefabPath = WeaponAttribute.WeaponPrefab;
+ _weaponAttribute = (WeaponAttribute)Activator.CreateInstance(attribute);
+ if (_weaponAttribute != null) PrefabPath = _weaponAttribute.WeaponPrefab;
}
public override void CustomHandler(ActivityObject instance)
{
if (instance is Weapon weapon)
{
- weapon.InitWeapon(WeaponAttribute.Clone());
+ weapon.InitWeapon(_weaponAttribute.Clone());
}
}
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs
index 19e8dd0..47f35be 100644
--- a/DungeonShooting_Godot/src/game/room/RoomManager.cs
+++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs
@@ -37,16 +37,7 @@
//房间内所有静态导航网格数据
private static List _roomStaticNavigationList = new List();
-
- public override void _EnterTree()
- {
- //创建玩家
- Player = ActivityObject.Create(ActivityIdPrefix.Role + "0001");
- Player.Position = new Vector2(30, 30);
- Player.Name = "Player";
- Player.PutDown(RoomLayerEnum.YSortLayer);
- }
-
+
public override void _Ready()
{
TileRoot.YSortEnabled = false;
@@ -83,14 +74,24 @@
//播放bgm
SoundManager.PlayMusic(ResourcePath.resource_sound_bgm_Intro_ogg, -17f);
+ //创建玩家
+ Player = ActivityObject.Create(ActivityIdPrefix.Role + "0001");
+ Player.Position = new Vector2(30, 30);
+ Player.Name = "Player";
+ Player.PutDown(RoomLayerEnum.YSortLayer);
+
Player.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0001"));
Player.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0002"));
// Player.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0004"));
Player.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0003"));
+
+ //相机跟随玩家
+ GameCamera.Main.SetFollowTarget(Player);
- // var enemy1 = ActivityObject.Create(ActivityIdPrefix.Enemy + "0001");
- // enemy1.PutDown(new Vector2(160, 160), RoomLayerEnum.YSortLayer);
- // enemy1.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0001"));
+ //修改鼠标指针
+ var cursor = GameApplication.Instance.Cursor;
+ cursor.SetGuiMode(false);
+ cursor.SetMountRole(Player);
}
///
diff --git a/DungeonShooting_Godot/src/game/ui/Cursor.cs b/DungeonShooting_Godot/src/game/ui/Cursor.cs
index a7cc1a4..7bc0a69 100644
--- a/DungeonShooting_Godot/src/game/ui/Cursor.cs
+++ b/DungeonShooting_Godot/src/game/ui/Cursor.cs
@@ -5,11 +5,21 @@
///
public partial class Cursor : Node2D
{
+ ///
+ /// 是否是GUI模式
+ ///
+ private bool _isGuiMode = true;
+
+ ///
+ /// 非GUI模式下鼠标指针所挂载的角色
+ ///
+ private Role _mountRole;
+
private Sprite2D lt;
private Sprite2D lb;
private Sprite2D rt;
private Sprite2D rb;
-
+
public override void _Ready()
{
lt = GetNode("LT");
@@ -20,21 +30,56 @@
public override void _Process(double delta)
{
- var targetGun = GameApplication.Instance.RoomManager.Player?.Holster.ActiveWeapon;
- if (targetGun != null)
+ if (_isGuiMode)
{
- SetScope(targetGun.CurrScatteringRange, targetGun);
+ SetScope(0, null);
}
else
{
- SetScope(0, targetGun);
+ var targetGun = _mountRole?.Holster.ActiveWeapon;
+ if (targetGun != null)
+ {
+ SetScope(targetGun.CurrScatteringRange, targetGun);
+ }
+ else
+ {
+ SetScope(0, null);
+ }
}
+
SetCursorPos();
}
- public Vector2 GetPos()
+ ///
+ /// 设置是否是Gui模式
+ ///
+ public void SetGuiMode(bool flag)
{
- return Vector2.Zero;
+ _isGuiMode = flag;
+ }
+
+ ///
+ /// 获取是否是Gui模式
+ ///
+ public bool GetGuiMode()
+ {
+ return _isGuiMode;
+ }
+
+ ///
+ /// 设置非GUI模式下鼠标指针所挂载的角色
+ ///
+ public void SetMountRole(Role role)
+ {
+ _mountRole = role;
+ }
+
+ ///
+ /// 获取非GUI模式下鼠标指针所挂载的角色
+ ///
+ public Role GetMountRole()
+ {
+ return _mountRole;
}
///