Compare commits
4 Commits
1f008f0405
...
86c3e8d7fb
Author | SHA1 | Date | |
---|---|---|---|
|
86c3e8d7fb | ||
|
1601af60a6 | ||
|
6b6b01e977 | ||
|
b23d3be76b |
Before Width: | Height: | Size: 722 B After Width: | Height: | Size: 988 B |
Before Width: | Height: | Size: 643 B After Width: | Height: | Size: 707 B |
Before Width: | Height: | Size: 502 B After Width: | Height: | Size: 372 B |
Before Width: | Height: | Size: 230 B After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 402 B After Width: | Height: | Size: 305 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 470 B |
Before Width: | Height: | Size: 158 B After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 536 B After Width: | Height: | Size: 424 B |
Before Width: | Height: | Size: 486 B After Width: | Height: | Size: 528 B |
Before Width: | Height: | Size: 386 B After Width: | Height: | Size: 317 B |
|
@ -1,4 +1,4 @@
|
|||
using Godot;
|
||||
using Godot;
|
||||
|
||||
/// <summary>
|
||||
/// 宝箱
|
||||
|
@ -6,37 +6,37 @@
|
|||
[Tool]
|
||||
public partial class TreasureBox : ObstacleObject
|
||||
{
|
||||
public bool IsOpen { get; private set; }
|
||||
public bool IsOpen { get; private set; }
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
AnimatedSprite.AnimationFinished += OnAnimationFinished;
|
||||
}
|
||||
public override void OnInit()
|
||||
{
|
||||
AnimatedSprite.AnimationFinished += OnAnimationFinished;
|
||||
}
|
||||
|
||||
public override CheckInteractiveResult CheckInteractive(ActivityObject master)
|
||||
{
|
||||
return new CheckInteractiveResult(this, !IsOpen, CheckInteractiveResult.InteractiveType.OpenTreasureBox);
|
||||
}
|
||||
public override CheckInteractiveResult CheckInteractive(ActivityObject master)
|
||||
{
|
||||
return new CheckInteractiveResult(this, !IsOpen, CheckInteractiveResult.InteractiveType.OpenTreasureBox);
|
||||
}
|
||||
|
||||
public override void Interactive(ActivityObject master)
|
||||
{
|
||||
if (IsOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public override void Interactive(ActivityObject master)
|
||||
{
|
||||
if (IsOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsOpen = true;
|
||||
AnimatedSprite.Play(AnimatorNames.Open);
|
||||
}
|
||||
IsOpen = true;
|
||||
AnimatedSprite.Play(AnimatorNames.Open);
|
||||
}
|
||||
|
||||
private void OnAnimationFinished()
|
||||
{
|
||||
var weapon = Create(World.RandomPool.GetRandomProp());
|
||||
weapon.Throw(Position, 2, 95, new Vector2(0, 11), 0);
|
||||
}
|
||||
private void OnAnimationFinished()
|
||||
{
|
||||
var weapon = Create(World.RandomPool.GetRandomProp());
|
||||
weapon.Throw(Position, 2, 95, new Vector2(0, 11), 0);
|
||||
}
|
||||
|
||||
public override void Hurt(ActivityObject target, int damage, float angle)
|
||||
{
|
||||
PlayHitAnimation();
|
||||
}
|
||||
}
|
||||
public override void Hurt(ActivityObject target, int damage, float angle)
|
||||
{
|
||||
PlayHitAnimation();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
|
||||
using Godot;
|
||||
|
||||
/// <summary>
|
||||
|
@ -7,67 +7,67 @@ using Godot;
|
|||
[Tool]
|
||||
public partial class Gold : ActivityObject, IPoolItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 金币数量
|
||||
/// </summary>
|
||||
[Export]
|
||||
public int GoldCount { get; set; } = 1;
|
||||
|
||||
public bool IsRecycled { get; set; }
|
||||
public string Logotype { get; set; }
|
||||
|
||||
private float _maxSpeed = 250;
|
||||
private float _speed = 0;
|
||||
private Role _moveTarget;
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
DefaultLayer = RoomLayerEnum.YSortLayer;
|
||||
}
|
||||
/// <summary>
|
||||
/// 金币数量
|
||||
/// </summary>
|
||||
[Export]
|
||||
public int GoldCount { get; set; } = 1;
|
||||
|
||||
public bool IsRecycled { get; set; }
|
||||
public string Logotype { get; set; }
|
||||
|
||||
private float _maxSpeed = 250;
|
||||
private float _speed = 0;
|
||||
private Role _moveTarget;
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
DefaultLayer = RoomLayerEnum.YSortLayer;
|
||||
}
|
||||
|
||||
protected override void OnThrowOver()
|
||||
{
|
||||
var current = Player.Current;
|
||||
if (current != null)
|
||||
{
|
||||
this.CallDelay(0.3f, () =>
|
||||
{
|
||||
_moveTarget = current;
|
||||
MoveController.Enable = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
protected override void OnThrowOver()
|
||||
{
|
||||
var current = Player.Current;
|
||||
if (current != null)
|
||||
{
|
||||
this.CallDelay(0.3f, () =>
|
||||
{
|
||||
_moveTarget = current;
|
||||
MoveController.Enable = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Process(float delta)
|
||||
{
|
||||
if (_moveTarget != null && !_moveTarget.IsDestroyed)
|
||||
{
|
||||
var position = Position;
|
||||
var targetPosition = _moveTarget.Position;
|
||||
if (position.DistanceSquaredTo(targetPosition) < 3 * 3)
|
||||
{
|
||||
_moveTarget.AddGold(GoldCount);
|
||||
ObjectPool.Reclaim(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
_speed = Mathf.MoveToward(_speed, _maxSpeed, _maxSpeed * delta);
|
||||
Position = position.MoveToward(targetPosition, _speed * delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReclaim()
|
||||
{
|
||||
GetParent().RemoveChild(this);
|
||||
_moveTarget = null;
|
||||
}
|
||||
protected override void Process(float delta)
|
||||
{
|
||||
if (_moveTarget != null && !_moveTarget.IsDestroyed)
|
||||
{
|
||||
var position = Position;
|
||||
var targetPosition = _moveTarget.Position;
|
||||
if (position.DistanceSquaredTo(targetPosition) < 3 * 3)
|
||||
{
|
||||
_moveTarget.AddGold(GoldCount);
|
||||
ObjectPool.Reclaim(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
_speed = Mathf.MoveToward(_speed, _maxSpeed, _maxSpeed * delta);
|
||||
Position = position.MoveToward(targetPosition, _speed * delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReclaim()
|
||||
{
|
||||
GetParent().RemoveChild(this);
|
||||
_moveTarget = null;
|
||||
}
|
||||
|
||||
public void OnLeavePool()
|
||||
{
|
||||
_speed = 0;
|
||||
MoveController.Enable = true;
|
||||
MoveController.ClearForce();
|
||||
MoveController.SetAllVelocity(Vector2.Zero);
|
||||
}
|
||||
}
|
||||
public void OnLeavePool()
|
||||
{
|
||||
_speed = 0;
|
||||
MoveController.Enable = true;
|
||||
MoveController.ClearForce();
|
||||
MoveController.SetAllVelocity(Vector2.Zero);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,241 +7,241 @@ using Godot;
|
|||
/// </summary>
|
||||
public partial class GameCamera : Camera2D
|
||||
{
|
||||
private class ShakeData
|
||||
{
|
||||
public Vector2 Value;
|
||||
public bool Decline;
|
||||
public float DataDelta;
|
||||
private class ShakeData
|
||||
{
|
||||
public Vector2 Value;
|
||||
public bool Decline;
|
||||
public float DataDelta;
|
||||
|
||||
public ShakeData(Vector2 value, bool decline, float dataDelta)
|
||||
{
|
||||
Value = value;
|
||||
Decline = decline;
|
||||
DataDelta = dataDelta;
|
||||
}
|
||||
}
|
||||
public ShakeData(Vector2 value, bool decline, float dataDelta)
|
||||
{
|
||||
Value = value;
|
||||
Decline = decline;
|
||||
DataDelta = dataDelta;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前场景的相机对象
|
||||
/// </summary>
|
||||
public static GameCamera Main { get; private set; }
|
||||
/// <summary>
|
||||
/// 当前场景的相机对象
|
||||
/// </summary>
|
||||
public static GameCamera Main { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 相机坐标更新完成事件, 参数为 delta
|
||||
/// </summary>
|
||||
public event Action<float> OnPositionUpdateEvent;
|
||||
/// <summary>
|
||||
/// 相机坐标更新完成事件, 参数为 delta
|
||||
/// </summary>
|
||||
public event Action<float> OnPositionUpdateEvent;
|
||||
|
||||
/// <summary>
|
||||
/// 恢复系数
|
||||
/// </summary>
|
||||
[Export] public float RecoveryCoefficient = 25f;
|
||||
/// <summary>
|
||||
/// 恢复系数
|
||||
/// </summary>
|
||||
[Export] public float RecoveryCoefficient = 25f;
|
||||
|
||||
/// <summary>
|
||||
/// 抖动开关
|
||||
/// </summary>
|
||||
public bool EnableShake { get; set; } = true;
|
||||
/// <summary>
|
||||
/// 抖动开关
|
||||
/// </summary>
|
||||
public bool EnableShake { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 镜头跟随鼠标进度 (0 - 1)
|
||||
/// </summary>
|
||||
public float FollowsMouseAmount = 0.15f;
|
||||
/// <summary>
|
||||
/// 镜头跟随鼠标进度 (0 - 1)
|
||||
/// </summary>
|
||||
public float FollowsMouseAmount = 0.15f;
|
||||
|
||||
/// <summary>
|
||||
/// 相机跟随目标
|
||||
/// </summary>
|
||||
private Role _followTarget;
|
||||
/// <summary>
|
||||
/// 相机跟随目标
|
||||
/// </summary>
|
||||
private Role _followTarget;
|
||||
|
||||
/// <summary>
|
||||
/// SubViewportContainer 中的像素偏移, 因为游戏开启了完美像素, SubViewport 节点下的相机运动会造成非常大的抖动,
|
||||
/// 为了解决这个问题, 在 SubViewport 父节点中对 SubViewport 进行整体偏移, 以抵消相机造成的巨大抖动
|
||||
/// </summary>
|
||||
public Vector2 PixelOffset { get; private set; }
|
||||
/// <summary>
|
||||
/// SubViewportContainer 中的像素偏移, 因为游戏开启了完美像素, SubViewport 节点下的相机运动会造成非常大的抖动,
|
||||
/// 为了解决这个问题, 在 SubViewport 父节点中对 SubViewport 进行整体偏移, 以抵消相机造成的巨大抖动
|
||||
/// </summary>
|
||||
public Vector2 PixelOffset { get; private set; }
|
||||
|
||||
private long _index = 0;
|
||||
|
||||
private Vector2 _processDistanceSquared = Vector2.Zero;
|
||||
private Vector2 _processDirection = Vector2.Zero;
|
||||
//抖动数据
|
||||
private readonly Dictionary<long, ShakeData> _shakeMap = new Dictionary<long, ShakeData>();
|
||||
|
||||
private Vector2 _camPos;
|
||||
private Vector2 _shakeOffset = Vector2.Zero;
|
||||
|
||||
public ShaderMaterial _offsetShader;
|
||||
private long _index = 0;
|
||||
|
||||
private Vector2 _processDistanceSquared = Vector2.Zero;
|
||||
private Vector2 _processDirection = Vector2.Zero;
|
||||
//抖动数据
|
||||
private readonly Dictionary<long, ShakeData> _shakeMap = new Dictionary<long, ShakeData>();
|
||||
|
||||
private Vector2 _camPos;
|
||||
private Vector2 _shakeOffset = Vector2.Zero;
|
||||
|
||||
public ShaderMaterial _offsetShader;
|
||||
|
||||
public GameCamera()
|
||||
{
|
||||
Main = this;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_offsetShader = (ShaderMaterial)GameApplication.Instance.SubViewportContainer.Material;
|
||||
_camPos = GlobalPosition;
|
||||
}
|
||||
|
||||
//_PhysicsProcess
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var newDelta = (float)delta;
|
||||
_Shake(newDelta);
|
||||
|
||||
var world = World.Current;
|
||||
if (world != null && _followTarget != null)
|
||||
{
|
||||
var mousePosition = InputManager.CursorPosition;
|
||||
var targetPosition = _followTarget.GlobalPosition;
|
||||
if (targetPosition.DistanceSquaredTo(mousePosition) >= (60 / FollowsMouseAmount) * (60 / FollowsMouseAmount))
|
||||
{
|
||||
_camPos = targetPosition.MoveToward(mousePosition, 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
_camPos = targetPosition.Lerp(mousePosition, FollowsMouseAmount);
|
||||
}
|
||||
public GameCamera()
|
||||
{
|
||||
Main = this;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_offsetShader = (ShaderMaterial)GameApplication.Instance.SubViewportContainer.Material;
|
||||
_camPos = GlobalPosition;
|
||||
}
|
||||
|
||||
//_PhysicsProcess
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var newDelta = (float)delta;
|
||||
_Shake(newDelta);
|
||||
|
||||
var world = World.Current;
|
||||
if (world != null && _followTarget != null)
|
||||
{
|
||||
var mousePosition = InputManager.CursorPosition;
|
||||
var targetPosition = _followTarget.GlobalPosition;
|
||||
if (targetPosition.DistanceSquaredTo(mousePosition) >= (60 / FollowsMouseAmount) * (60 / FollowsMouseAmount))
|
||||
{
|
||||
_camPos = targetPosition.MoveToward(mousePosition, 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
_camPos = targetPosition.Lerp(mousePosition, FollowsMouseAmount);
|
||||
}
|
||||
|
||||
var cameraPosition = _camPos;
|
||||
var roundPos = cameraPosition.Round();
|
||||
PixelOffset = roundPos - cameraPosition;
|
||||
_offsetShader.SetShaderParameter("offset", PixelOffset);
|
||||
GlobalPosition = roundPos;
|
||||
|
||||
Offset = _shakeOffset.Round();
|
||||
|
||||
//调用相机更新事件
|
||||
if (OnPositionUpdateEvent != null)
|
||||
{
|
||||
OnPositionUpdateEvent(newDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
var cameraPosition = _camPos;
|
||||
var roundPos = cameraPosition.Round();
|
||||
PixelOffset = roundPos - cameraPosition;
|
||||
_offsetShader.SetShaderParameter("offset", PixelOffset);
|
||||
GlobalPosition = roundPos;
|
||||
|
||||
Offset = _shakeOffset.Round();
|
||||
|
||||
//调用相机更新事件
|
||||
if (OnPositionUpdateEvent != null)
|
||||
{
|
||||
OnPositionUpdateEvent(newDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置相机跟随目标
|
||||
/// </summary>
|
||||
public void SetFollowTarget(Role target)
|
||||
{
|
||||
_followTarget = target;
|
||||
if (target != null)
|
||||
{
|
||||
_camPos = target.GlobalPosition;
|
||||
GlobalPosition = _camPos;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置相机跟随目标
|
||||
/// </summary>
|
||||
public void SetFollowTarget(Role target)
|
||||
{
|
||||
_followTarget = target;
|
||||
if (target != null)
|
||||
{
|
||||
_camPos = target.GlobalPosition;
|
||||
GlobalPosition = _camPos;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取相机跟随目标
|
||||
/// </summary>
|
||||
public Role GetFollowTarget()
|
||||
{
|
||||
return _followTarget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置帧抖动, 结束后自动清零, 需要每一帧调用
|
||||
/// </summary>
|
||||
/// <param name="value">抖动的力度</param>
|
||||
public void Shake(Vector2 value)
|
||||
{
|
||||
if (value.LengthSquared() > _processDistanceSquared.LengthSquared())
|
||||
{
|
||||
_processDistanceSquared = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个单方向上的抖动, 该帧结束后自动清零
|
||||
/// </summary>
|
||||
public void DirectionalShake(Vector2 value)
|
||||
{
|
||||
_processDirection += value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个抖动, 并设置抖动时间
|
||||
/// </summary>
|
||||
public async void CreateShake(Vector2 value, float time, bool decline = false)
|
||||
{
|
||||
if (time > 0)
|
||||
{
|
||||
value.X = Mathf.Abs(value.X);
|
||||
value.Y = Mathf.Abs(value.Y);
|
||||
var tempIndex = _index++;
|
||||
var sceneTreeTimer = GetTree().CreateTimer(time);
|
||||
if (decline)
|
||||
{
|
||||
_shakeMap[tempIndex] = new ShakeData(value, true, value.Length() / time);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shakeMap[tempIndex] = new ShakeData(value, false, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取相机跟随目标
|
||||
/// </summary>
|
||||
public Role GetFollowTarget()
|
||||
{
|
||||
return _followTarget;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置帧抖动, 结束后自动清零, 需要每一帧调用
|
||||
/// </summary>
|
||||
/// <param name="value">抖动的力度</param>
|
||||
public void Shake(Vector2 value)
|
||||
{
|
||||
if (value.LengthSquared() > _processDistanceSquared.LengthSquared())
|
||||
{
|
||||
_processDistanceSquared = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个单方向上的抖动, 该帧结束后自动清零
|
||||
/// </summary>
|
||||
public void DirectionalShake(Vector2 value)
|
||||
{
|
||||
_processDirection += value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个抖动, 并设置抖动时间
|
||||
/// </summary>
|
||||
public async void CreateShake(Vector2 value, float time, bool decline = false)
|
||||
{
|
||||
if (time > 0)
|
||||
{
|
||||
value.X = Mathf.Abs(value.X);
|
||||
value.Y = Mathf.Abs(value.Y);
|
||||
var tempIndex = _index++;
|
||||
var sceneTreeTimer = GetTree().CreateTimer(time);
|
||||
if (decline)
|
||||
{
|
||||
_shakeMap[tempIndex] = new ShakeData(value, true, value.Length() / time);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shakeMap[tempIndex] = new ShakeData(value, false, 0);
|
||||
}
|
||||
|
||||
await ToSignal(sceneTreeTimer, Timer.SignalName.Timeout);
|
||||
_shakeMap.Remove(tempIndex);
|
||||
}
|
||||
}
|
||||
await ToSignal(sceneTreeTimer, Timer.SignalName.Timeout);
|
||||
_shakeMap.Remove(tempIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 播放玩家死亡特写镜头
|
||||
/// </summary>
|
||||
public void PlayPlayerDieFeatures()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 播放玩家死亡特写镜头
|
||||
/// </summary>
|
||||
public void PlayPlayerDieFeatures()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//抖动调用
|
||||
private void _Shake(float delta)
|
||||
{
|
||||
if (EnableShake)
|
||||
{
|
||||
var distance = _CalculateDistanceSquared(delta);
|
||||
if (distance == Vector2.Zero)
|
||||
{
|
||||
_shakeOffset += _processDirection - Offset / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
distance = new Vector2(Mathf.Sqrt(Mathf.Abs(distance.X)), Mathf.Sqrt(Mathf.Abs(distance.Y)));
|
||||
var offset = Offset;
|
||||
_shakeOffset += _processDirection + new Vector2(
|
||||
(float)GD.RandRange(-distance.X, distance.X) - offset.X,
|
||||
(float)GD.RandRange(-distance.Y, distance.Y) - offset.Y
|
||||
);
|
||||
}
|
||||
//抖动调用
|
||||
private void _Shake(float delta)
|
||||
{
|
||||
if (EnableShake)
|
||||
{
|
||||
var distance = _CalculateDistanceSquared(delta);
|
||||
if (distance == Vector2.Zero)
|
||||
{
|
||||
_shakeOffset += _processDirection - Offset / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
distance = new Vector2(Mathf.Sqrt(Mathf.Abs(distance.X)), Mathf.Sqrt(Mathf.Abs(distance.Y)));
|
||||
var offset = Offset;
|
||||
_shakeOffset += _processDirection + new Vector2(
|
||||
(float)GD.RandRange(-distance.X, distance.X) - offset.X,
|
||||
(float)GD.RandRange(-distance.Y, distance.Y) - offset.Y
|
||||
);
|
||||
}
|
||||
|
||||
_processDistanceSquared = Vector2.Zero;
|
||||
_processDirection = _processDirection.Lerp(Vector2.Zero, RecoveryCoefficient * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shakeOffset = _shakeOffset.Lerp(Vector2.Zero, RecoveryCoefficient * delta);
|
||||
}
|
||||
}
|
||||
_processDistanceSquared = Vector2.Zero;
|
||||
_processDirection = _processDirection.Lerp(Vector2.Zero, RecoveryCoefficient * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shakeOffset = _shakeOffset.Lerp(Vector2.Zero, RecoveryCoefficient * delta);
|
||||
}
|
||||
}
|
||||
|
||||
//计算相机需要抖动的值
|
||||
private Vector2 _CalculateDistanceSquared(float delta)
|
||||
{
|
||||
var temp = Vector2.Zero;
|
||||
float length = 0;
|
||||
//计算相机需要抖动的值
|
||||
private Vector2 _CalculateDistanceSquared(float delta)
|
||||
{
|
||||
var temp = Vector2.Zero;
|
||||
float length = 0;
|
||||
|
||||
foreach (var keyValuePair in _shakeMap)
|
||||
{
|
||||
var shakeData = keyValuePair.Value;
|
||||
var tempLength = shakeData.Value.LengthSquared();
|
||||
if (tempLength > length)
|
||||
{
|
||||
length = tempLength;
|
||||
temp = shakeData.Value;
|
||||
if (shakeData.Decline)
|
||||
{
|
||||
shakeData.Value = shakeData.Value.MoveToward(Vector2.Zero, shakeData.DataDelta * delta);
|
||||
//Debug.Log("shakeData.Value: " + shakeData.Value + ", _processDistanceSquared: " + _processDistanceSquared);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var keyValuePair in _shakeMap)
|
||||
{
|
||||
var shakeData = keyValuePair.Value;
|
||||
var tempLength = shakeData.Value.LengthSquared();
|
||||
if (tempLength > length)
|
||||
{
|
||||
length = tempLength;
|
||||
temp = shakeData.Value;
|
||||
if (shakeData.Decline)
|
||||
{
|
||||
shakeData.Value = shakeData.Value.MoveToward(Vector2.Zero, shakeData.DataDelta * delta);
|
||||
//Debug.Log("shakeData.Value: " + shakeData.Value + ", _processDistanceSquared: " + _processDistanceSquared);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return temp;
|
||||
return _processDistanceSquared.LengthSquared() > length ? _processDistanceSquared : temp;
|
||||
}
|
||||
//return temp;
|
||||
return _processDistanceSquared.LengthSquared() > length ? _processDistanceSquared : temp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,17 @@ using Godot;
|
|||
/// </summary>
|
||||
public partial class Dungeon : World
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
Color = Colors.Black;
|
||||
}
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
Color = Colors.Black;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 TileMap 中的层级
|
||||
/// </summary>
|
||||
public void InitLayer()
|
||||
{
|
||||
MapLayerManager.InitMapLayer(TileRoot);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化 TileMap 中的层级
|
||||
/// </summary>
|
||||
public void InitLayer()
|
||||
{
|
||||
MapLayerManager.InitMapLayer(TileRoot);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
|
||||
using Godot;
|
||||
|
||||
/// <summary>
|
||||
|
@ -7,106 +7,106 @@ using Godot;
|
|||
[Tool]
|
||||
public partial class RoomDoor : ActivityObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 门的方向
|
||||
/// </summary>
|
||||
public DoorDirection Direction => _door.Direction;
|
||||
|
||||
/// <summary>
|
||||
/// 门是否关闭
|
||||
/// </summary>
|
||||
public bool IsClose { get; private set; }
|
||||
|
||||
private RoomDoorInfo _door;
|
||||
private bool waitDisabledCollision = false;
|
||||
private AnimatedSprite2D _animatedDown;
|
||||
/// <summary>
|
||||
/// 门的方向
|
||||
/// </summary>
|
||||
public DoorDirection Direction => _door.Direction;
|
||||
|
||||
/// <summary>
|
||||
/// 门是否关闭
|
||||
/// </summary>
|
||||
public bool IsClose { get; private set; }
|
||||
|
||||
private RoomDoorInfo _door;
|
||||
private bool waitDisabledCollision = false;
|
||||
private AnimatedSprite2D _animatedDown;
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
AnimatedSprite.AnimationFinished += OnAnimationFinished;
|
||||
}
|
||||
public override void OnInit()
|
||||
{
|
||||
AnimatedSprite.AnimationFinished += OnAnimationFinished;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化调用
|
||||
/// </summary>
|
||||
public void Init(RoomDoorInfo doorInfo)
|
||||
{
|
||||
_door = doorInfo;
|
||||
IsClose = false;
|
||||
if (doorInfo.Direction == DoorDirection.E || doorInfo.Direction == DoorDirection.W)
|
||||
{
|
||||
_animatedDown = GetNode<AnimatedSprite2D>("AnimatedSpriteDown");
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化调用
|
||||
/// </summary>
|
||||
public void Init(RoomDoorInfo doorInfo)
|
||||
{
|
||||
_door = doorInfo;
|
||||
IsClose = false;
|
||||
if (doorInfo.Direction == DoorDirection.E || doorInfo.Direction == DoorDirection.W)
|
||||
{
|
||||
_animatedDown = GetNode<AnimatedSprite2D>("AnimatedSpriteDown");
|
||||
}
|
||||
|
||||
OpenDoorHandler();
|
||||
}
|
||||
OpenDoorHandler();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开当前的门
|
||||
/// </summary>
|
||||
public void OpenDoor()
|
||||
{
|
||||
IsClose = false;
|
||||
//Visible = false;
|
||||
waitDisabledCollision = true;
|
||||
if (AnimatedSprite.SpriteFrames.HasAnimation(AnimatorNames.OpenDoor))
|
||||
{
|
||||
AnimatedSprite.Play(AnimatorNames.OpenDoor);
|
||||
}
|
||||
/// <summary>
|
||||
/// 打开当前的门
|
||||
/// </summary>
|
||||
public void OpenDoor()
|
||||
{
|
||||
IsClose = false;
|
||||
//Visible = false;
|
||||
waitDisabledCollision = true;
|
||||
if (AnimatedSprite.SpriteFrames.HasAnimation(AnimatorNames.OpenDoor))
|
||||
{
|
||||
AnimatedSprite.Play(AnimatorNames.OpenDoor);
|
||||
}
|
||||
|
||||
if (_animatedDown != null && _animatedDown.SpriteFrames.HasAnimation(AnimatorNames.OpenDoor))
|
||||
{
|
||||
_animatedDown.Play(AnimatorNames.OpenDoor);
|
||||
}
|
||||
}
|
||||
if (_animatedDown != null && _animatedDown.SpriteFrames.HasAnimation(AnimatorNames.OpenDoor))
|
||||
{
|
||||
_animatedDown.Play(AnimatorNames.OpenDoor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭当前的门
|
||||
/// </summary>
|
||||
public void CloseDoor()
|
||||
{
|
||||
IsClose = true;
|
||||
//Visible = true;
|
||||
Collision.Disabled = false;
|
||||
/// <summary>
|
||||
/// 关闭当前的门
|
||||
/// </summary>
|
||||
public void CloseDoor()
|
||||
{
|
||||
IsClose = true;
|
||||
//Visible = true;
|
||||
Collision.Disabled = false;
|
||||
|
||||
if (AnimatedSprite.SpriteFrames.HasAnimation(AnimatorNames.CloseDoor))
|
||||
{
|
||||
AnimatedSprite.Play(AnimatorNames.CloseDoor);
|
||||
}
|
||||
if (AnimatedSprite.SpriteFrames.HasAnimation(AnimatorNames.CloseDoor))
|
||||
{
|
||||
AnimatedSprite.Play(AnimatorNames.CloseDoor);
|
||||
}
|
||||
|
||||
if (_animatedDown != null)
|
||||
{
|
||||
_animatedDown.Visible = false;
|
||||
}
|
||||
if (_animatedDown != null)
|
||||
{
|
||||
_animatedDown.Visible = false;
|
||||
}
|
||||
|
||||
if (Direction == DoorDirection.E || Direction == DoorDirection.W)
|
||||
{
|
||||
ZIndex = MapLayer.CustomMiddleLayer2;
|
||||
}
|
||||
}
|
||||
if (Direction == DoorDirection.E || Direction == DoorDirection.W)
|
||||
{
|
||||
ZIndex = MapLayer.CustomMiddleLayer2;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnimationFinished()
|
||||
{
|
||||
if (!IsClose && waitDisabledCollision) //开门动画播放完成
|
||||
{
|
||||
waitDisabledCollision = false;
|
||||
if (_animatedDown != null)
|
||||
{
|
||||
_animatedDown.Visible = true;
|
||||
}
|
||||
private void OnAnimationFinished()
|
||||
{
|
||||
if (!IsClose && waitDisabledCollision) //开门动画播放完成
|
||||
{
|
||||
waitDisabledCollision = false;
|
||||
if (_animatedDown != null)
|
||||
{
|
||||
_animatedDown.Visible = true;
|
||||
}
|
||||
|
||||
if (Direction == DoorDirection.E || Direction == DoorDirection.W)
|
||||
{
|
||||
ZIndex = 0;
|
||||
}
|
||||
OpenDoorHandler();
|
||||
}
|
||||
}
|
||||
if (Direction == DoorDirection.E || Direction == DoorDirection.W)
|
||||
{
|
||||
ZIndex = 0;
|
||||
}
|
||||
OpenDoorHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenDoorHandler()
|
||||
{
|
||||
Collision.Disabled = true;
|
||||
//调整门的层级
|
||||
//ZIndex = MapLayer.AutoFloorLayer;
|
||||
}
|
||||
}
|
||||
private void OpenDoorHandler()
|
||||
{
|
||||
Collision.Disabled = true;
|
||||
//调整门的层级
|
||||
//ZIndex = MapLayer.AutoFloorLayer;
|
||||
}
|
||||
}
|
||||
|
|