added pickup animation

This commit is contained in:
2025-05-19 22:39:30 +02:00
parent 7276bdda38
commit 80c48ea3df
3 changed files with 23 additions and 3 deletions
@@ -14,11 +14,15 @@ public partial class Player2D : CharacterBody2D
private string _toolString;
private bool anyActionPressed;
private bool _wateringInProgress;
private bool _pickupAnimationInProgress;
private Vector2 _lastDirection = Vector2.Zero;
public override void _Process(double delta)
{
anyActionPressed = false;
if (_pickupAnimationInProgress || _wateringInProgress)
return;
if (Input.IsActionPressed("move_right"))
{
@@ -64,8 +68,6 @@ public partial class Player2D : CharacterBody2D
}
else
{
if (_wateringInProgress)
return;
//idle
if(_lastDirection == Vector2.Zero || _lastDirection == Vector2.Down)
_sprite.Animation = "front idle" + _toolString;
@@ -79,7 +81,10 @@ public partial class Player2D : CharacterBody2D
public void ActivateTool(bool success, int id)
{
if (success)
{
_toolID = id;
PlayPickUpAnimation();
}
else _toolID = -1;
switch (_toolID)
@@ -113,5 +118,18 @@ public partial class Player2D : CharacterBody2D
_wateringInProgress = false;
}
public void PlayPickUpAnimation()
{
_sprite.Animation = "side pickup";
_sprite.Play();
_pickupAnimationInProgress = true;
Task.Run(DelayedPickUpReset);
}
private async Task DelayedPickUpReset()
{
await Task.Delay(1000);
_pickupAnimationInProgress = false;
}
}