mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
59 lines
No EOL
1.4 KiB
C#
59 lines
No EOL
1.4 KiB
C#
using System.Threading.Tasks;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Resources.Events;
|
|
|
|
[GlobalClass]
|
|
public partial class MovePlayerEvent : EventResource
|
|
{
|
|
[Export]
|
|
public Vector2 RelativeTargetPosition = Vector2.Zero;
|
|
|
|
[Export]
|
|
public float MovementTime = 1f;
|
|
|
|
[Export]
|
|
public Tween.EaseType EaseType = Tween.EaseType.InOut;
|
|
|
|
[Export]
|
|
public Tween.TransitionType TransitionType = Tween.TransitionType.Linear;
|
|
|
|
private bool _isComplete = false;
|
|
|
|
private GameManager _gameManager;
|
|
|
|
public override void Init(Node2D parent)
|
|
{
|
|
_gameManager = parent.GetGameManager();
|
|
}
|
|
|
|
public override void Start(Node2D parentNode)
|
|
{
|
|
_isComplete = false;
|
|
_ = MovePlayer();
|
|
}
|
|
|
|
protected async Task MovePlayer()
|
|
{
|
|
_gameManager.Player.RequestMovementDisable(true);
|
|
|
|
Tween tween = _gameManager.GetTree().CreateTween();
|
|
tween.SetEase(EaseType);
|
|
tween.SetTrans(TransitionType);
|
|
tween.TweenProperty(_gameManager.Player, "global_position", _gameManager.Player.GlobalPosition + RelativeTargetPosition, MovementTime);
|
|
|
|
// Wait for the tween to finish
|
|
await ToSignal(tween, "finished");
|
|
|
|
_gameManager.Player.RequestMovementDisable(false);
|
|
|
|
_isComplete = true;
|
|
}
|
|
|
|
public override void UpdateEvent(double delta) { }
|
|
|
|
public override bool IsComplete()
|
|
{
|
|
return _isComplete;
|
|
}
|
|
} |