diff --git a/prefabs/Player2D.tscn b/prefabs/Player2D.tscn index c108066..76be895 100644 --- a/prefabs/Player2D.tscn +++ b/prefabs/Player2D.tscn @@ -2010,6 +2010,71 @@ animations = [{ }, { "frames": [{ "duration": 1.0, +"texture": ExtResource("229_2s7fx") +}, { +"duration": 1.0, +"texture": ExtResource("230_ft22h") +}, { +"duration": 1.0, +"texture": ExtResource("231_wvuim") +}, { +"duration": 1.0, +"texture": ExtResource("232_yiifo") +}, { +"duration": 1.0, +"texture": ExtResource("233_csnrs") +}, { +"duration": 1.0, +"texture": ExtResource("234_i8lry") +}, { +"duration": 1.0, +"texture": ExtResource("235_qr0ap") +}, { +"duration": 1.0, +"texture": ExtResource("236_08v00") +}, { +"duration": 1.0, +"texture": ExtResource("237_76nv2") +}, { +"duration": 1.0, +"texture": ExtResource("238_3xrgm") +}, { +"duration": 1.0, +"texture": ExtResource("239_ocv1s") +}, { +"duration": 1.0, +"texture": ExtResource("240_pabw7") +}, { +"duration": 1.0, +"texture": ExtResource("241_8dulv") +}, { +"duration": 1.0, +"texture": ExtResource("242_2sx3q") +}, { +"duration": 1.0, +"texture": ExtResource("243_wae3h") +}, { +"duration": 1.0, +"texture": ExtResource("244_knca5") +}, { +"duration": 1.0, +"texture": ExtResource("245_ojre6") +}, { +"duration": 1.0, +"texture": ExtResource("246_pc1oo") +}, { +"duration": 1.0, +"texture": ExtResource("247_7uiao") +}, { +"duration": 1.0, +"texture": ExtResource("248_ej4wx") +}], +"loop": true, +"name": &"diagonal wateringcan", +"speed": 15.0 +}, { +"frames": [{ +"duration": 1.0, "texture": ExtResource("249_hrc6p") }, { "duration": 1.0, @@ -3458,7 +3523,8 @@ position = Vector2(0, -374) [node name="Animated Sprites" type="AnimatedSprite2D" parent="CharacterBody2D/visuals"] position = Vector2(0, 450) sprite_frames = SubResource("SpriteFrames_4yiyq") -animation = &"back walking rake" +animation = &"diagonal wateringcan" +frame_progress = 0.0934381 offset = Vector2(0, -450) [node name="Hoe" type="Sprite2D" parent="CharacterBody2D/visuals"] @@ -3505,3 +3571,4 @@ _movingPlayer = NodePath("../CharacterBody2D") _camera = NodePath("../CharacterBody2D/Camera2D") [connection signal="PickedUpTool" from="." to="CharacterBody2D" method="ActivateTool"] +[connection signal="WateringField" from="FarmingControls" to="CharacterBody2D" method="PlayWateringAnimation"] diff --git a/scripts/CSharp/Common/CharacterControls/Player2D.cs b/scripts/CSharp/Common/CharacterControls/Player2D.cs index 14b0ae3..e771b73 100644 --- a/scripts/CSharp/Common/CharacterControls/Player2D.cs +++ b/scripts/CSharp/Common/CharacterControls/Player2D.cs @@ -1,3 +1,5 @@ +using System.Threading; +using System.Threading.Tasks; using Godot; namespace Babushka.scripts.CSharp.Common.CharacterControls; @@ -11,6 +13,7 @@ public partial class Player2D : CharacterBody2D private int _toolID = -1; private string _toolString; private bool anyActionPressed; + private bool _wateringInProgress; private Vector2 _lastDirection = Vector2.Zero; public override void _Process(double delta) @@ -61,6 +64,8 @@ public partial class Player2D : CharacterBody2D } else { + if (_wateringInProgress) + return; //idle if(_lastDirection == Vector2.Zero || _lastDirection == Vector2.Down) _sprite.Animation = "front idle" + _toolString; @@ -90,4 +95,23 @@ public partial class Player2D : CharacterBody2D break; } } + + public void PlayWateringAnimation() + { + if (_toolID == 1 && !_wateringInProgress) + { + _sprite.Animation = "diagonal wateringcan"; + _sprite.Play(); + _wateringInProgress = true; + Task.Run(DelayedWateringCanReset); + } + } + + private async Task DelayedWateringCanReset() + { + await Task.Delay(1000); + _wateringInProgress = false; + } + + } diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index 2db6caf..71e4272 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -17,6 +17,8 @@ public partial class FarmingControls2D : Node2D private int _currentWateringCanStep = 0; private int _wateringCanCapacity = 3; + [Signal] public delegate void WateringFieldEventHandler(); + #region Tools /// @@ -84,6 +86,7 @@ public partial class FarmingControls2D : Node2D return; field.Water(); + EmitSignal(SignalName.WateringField); if (_currentWateringCanStep < _wateringCanCapacity) {