diff --git a/src/camera/MainCamera.cs b/src/camera/MainCamera.cs index a1fa3cd..8f97587 100644 --- a/src/camera/MainCamera.cs +++ b/src/camera/MainCamera.cs @@ -3,29 +3,69 @@ public class MainCamera : Camera2D { - //当前场景的相机对象 - public static MainCamera CurrentCamera { get; private set; } + /// + /// 当前场景的相机对象 + /// + public static MainCamera Main { get; private set; } - //抖动力度(px) - [Export] public Vector2 ShakeDistance = Vector2.Zero; - //恢复系数 - [Export] public float RecoveryCoefficient = 100f; - //抖动开关 - public bool Enable = true; + /// + /// 恢复系数 + /// + [Export] + public float RecoveryCoefficient = 100f; + /// + /// 抖动开关 + /// + public bool Enable { get; set; } = true; private long _index = 0; private Vector2 _prossesDistance = Vector2.Zero; + private Vector2 _prossesDirectiona = Vector2.Zero; private readonly Dictionary _shakeMap = new Dictionary(); public override void _Ready() { - CurrentCamera = this; + Main = this; } public override void _PhysicsProcess(float delta) { _Shake(delta); } + /// + /// 设置帧抖动, 结束后自动清零, 需要每一帧调用 + /// + /// 抖动的力度 + public void ProssesShake(Vector2 value) + { + if (value.Length() > _prossesDistance.Length()) + { + _prossesDistance = value; + } + } + + public void ProssesDirectionalShake(Vector2 value) + { + _prossesDirectiona += value; + } + + /// + /// 创建一个抖动, 并设置抖动时间 + /// + /// 抖动力度 + /// 抖动生效时间 + public async void CreateShake(Vector2 value, float time) + { + if (time > 0) + { + long tempIndex = _index++; + SceneTreeTimer sceneTreeTimer = GetTree().CreateTimer(time); + _shakeMap[tempIndex] = value; + await ToSignal(sceneTreeTimer, "timeout"); + _shakeMap.Remove(tempIndex); + } + } + //抖动调用 private void _Shake(float delta) { @@ -36,7 +76,9 @@ (float)GD.RandRange(-_distance.x, _distance.x) - Offset.x, (float)GD.RandRange(-_distance.y, _distance.y) - Offset.y ); + Offset += _prossesDirectiona; _prossesDistance = Vector2.Zero; + _prossesDirectiona = Vector2.Zero; } else { @@ -62,26 +104,4 @@ return _prossesDistance.Length() > length ? _prossesDistance : temp; } - //设置帧抖动, 结束后自动清零, 需要每一帧调用 - public void ProssesShakeDistance(Vector2 value) - { - if (value.Length() > _prossesDistance.Length()) - { - _prossesDistance = value; - } - } - - //创建一个抖动, 并设置抖动时间 - public async void CreateShake(Vector2 value, float time) - { - if (time > 0) - { - long tempIndex = _index++; - SceneTreeTimer sceneTreeTimer = GetTree().CreateTimer(time); - _shakeMap[tempIndex] = value; - await ToSignal(sceneTreeTimer, "timeout"); - _shakeMap.Remove(tempIndex); - } - } - } diff --git a/src/weapon/gun/OrdinaryGun.cs b/src/weapon/gun/OrdinaryGun.cs index ff11b4c..31f869c 100644 --- a/src/weapon/gun/OrdinaryGun.cs +++ b/src/weapon/gun/OrdinaryGun.cs @@ -25,6 +25,8 @@ var sprite = Attribute.ShellPack.Instance(); temp.InitThrow(new Vector2(5, 10), startPos, startHeight, direction, xf, yf, rotate, sprite, sprite); RoomManager.Current.SortRoot.AddChild(temp); + //创建抖动 + MainCamera.Main.ProssesDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 1.5f); } protected override void OnShootBullet()