mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 04:35:54 +00:00
Chain activables
This commit is contained in:
parent
a430554e27
commit
77b18d250e
5 changed files with 144 additions and 32 deletions
55
Scripts/Activables/PlayerMover.cs
Normal file
55
Scripts/Activables/PlayerMover.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
||||
public partial class PlayerMover : ChainActivable
|
||||
{
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
[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;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
_gameManager = this.GetGameManager();
|
||||
}
|
||||
|
||||
public override void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (_gameManager.Player is null) return;
|
||||
|
||||
_ = MovePlayer();
|
||||
}
|
||||
|
||||
private async Task MovePlayer()
|
||||
{
|
||||
_gameManager.Player.RequestMovementDisable(true);
|
||||
|
||||
Tween tween = 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);
|
||||
|
||||
ActivateTargets();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue