added farming animation mechanic
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Threading;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
@@ -8,6 +8,7 @@ public partial class Player2D : CharacterBody2D
|
||||
{
|
||||
[Export] private float _speed = 100f;
|
||||
[Export] private AnimatedSprite2D _sprite;
|
||||
[Export] private SceneTree.GroupCallFlags _fieldFlags;
|
||||
|
||||
// -1 means no tool.
|
||||
private int _toolID = -1;
|
||||
@@ -15,13 +16,14 @@ public partial class Player2D : CharacterBody2D
|
||||
private bool anyActionPressed;
|
||||
private bool _wateringInProgress;
|
||||
private bool _pickupAnimationInProgress;
|
||||
private bool _farmingAnimationInProgress;
|
||||
private Vector2 _lastDirection = Vector2.Zero;
|
||||
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
anyActionPressed = false;
|
||||
|
||||
if (_pickupAnimationInProgress || _wateringInProgress)
|
||||
if (_pickupAnimationInProgress || _wateringInProgress || _farmingAnimationInProgress)
|
||||
return;
|
||||
|
||||
if (Input.IsActionPressed("move_right"))
|
||||
@@ -115,6 +117,9 @@ public partial class Player2D : CharacterBody2D
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by FarmingControls Signal.
|
||||
/// </summary>
|
||||
public void PlayWateringAnimation()
|
||||
{
|
||||
if (_toolID == 1 && !_wateringInProgress)
|
||||
@@ -146,4 +151,18 @@ public partial class Player2D : CharacterBody2D
|
||||
_pickupAnimationInProgress = false;
|
||||
}
|
||||
|
||||
public void PlayFarmingAnimation()
|
||||
{
|
||||
_sprite.Animation = "diagonal farming";
|
||||
_sprite.Play();
|
||||
_farmingAnimationInProgress = true;
|
||||
Task.Run(DelayedFarmingReset);
|
||||
}
|
||||
|
||||
private async Task DelayedFarmingReset()
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
_farmingAnimationInProgress = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -14,9 +15,10 @@ public partial class PlantBehaviour2D : Node2D
|
||||
[Export] private Sprite2D[] _readyPlants;
|
||||
[Export] private PlantState _state = PlantState.None;
|
||||
[Export] private FieldBehaviour2D _field;
|
||||
|
||||
|
||||
private Sprite2D _currentPlantSprite = null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Transitions the plant to its next growth stage.
|
||||
/// </summary>
|
||||
@@ -25,6 +27,8 @@ public partial class PlantBehaviour2D : Node2D
|
||||
if (_field.FieldState != FieldState.Watered)
|
||||
return;
|
||||
|
||||
GetTree().CallGroup("PlantGrowing", Player2D.MethodName.PlayFarmingAnimation);
|
||||
|
||||
switch (_state)
|
||||
{
|
||||
case PlantState.None:
|
||||
@@ -58,7 +62,7 @@ public partial class PlantBehaviour2D : Node2D
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
_field.UpdateFieldState(FieldState.Tilled);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user