You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/Temp/MVPDuck.cs

46 lines
1.1 KiB

using System.Threading.Tasks;
using Godot;
namespace Babushka.scripts.CSharp.Common.Temp;
/// <summary>
/// Temporary Duck behaviour to make sure we can use them in the first showcase
/// </summary>
public partial class MVPDuck : Node2D
{
[Export] private Node2D _penTarget;
[Export] private int _transferDelayMs;
[Export] private AnimationPlayer _animationPlayer;
[Export] private string _flapAnimationName = "flapFlap";
private bool _collected;
[Signal] public delegate void DuckCollectedEventHandler();
public void TransferToTargetAfterDelay()
{
if (!_collected)
{
MoveAfterDelay();
PlayAnimation();
_collected = true;
}
}
private void PlayAnimation()
{
_animationPlayer.CurrentAnimation = _flapAnimationName;
_animationPlayer.Play();
}
public async void MoveAfterDelay()
{
await ToSignal(GetTree().CreateTimer(1.0f), "timeout");
if(!_penTarget.Equals(null))
Position = _penTarget.GlobalPosition;
EmitSignal(SignalName.DuckCollected);
}
}