added pickup animation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user