mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 06:25:53 +00:00
Event System
This commit is contained in:
parent
797e24d766
commit
f379eac5c3
10 changed files with 336 additions and 10 deletions
56
Scripts/Resources/Events/MovePlayerEvent.cs
Normal file
56
Scripts/Resources/Events/MovePlayerEvent.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
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 Start(Node2D parentNode)
|
||||
{
|
||||
_gameManager = parentNode.GetGameManager();
|
||||
_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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue