From 80c48ea3dfc5ca771951c242ac0eabc43e27b252 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Mon, 19 May 2025 22:39:30 +0200 Subject: [PATCH] added pickup animation --- prefabs/Player2D.tscn | 2 +- prefabs/UI/Inventory/Inventory.tscn | 2 ++ .../Common/CharacterControls/Player2D.cs | 22 +++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/prefabs/Player2D.tscn b/prefabs/Player2D.tscn index 76be895..5f3aa27 100644 --- a/prefabs/Player2D.tscn +++ b/prefabs/Player2D.tscn @@ -3524,7 +3524,7 @@ position = Vector2(0, -374) position = Vector2(0, 450) sprite_frames = SubResource("SpriteFrames_4yiyq") animation = &"diagonal wateringcan" -frame_progress = 0.0934381 +frame_progress = 0.234463 offset = Vector2(0, -450) [node name="Hoe" type="Sprite2D" parent="CharacterBody2D/visuals"] diff --git a/prefabs/UI/Inventory/Inventory.tscn b/prefabs/UI/Inventory/Inventory.tscn index 333cb4e..b4a294f 100644 --- a/prefabs/UI/Inventory/Inventory.tscn +++ b/prefabs/UI/Inventory/Inventory.tscn @@ -51,6 +51,7 @@ grow_horizontal = 2 grow_vertical = 0 [node name="Selector" type="TextureRect" parent="SlotsContainer/SlotSelectContainer"] +visible = false custom_minimum_size = Vector2(100, 100) layout_mode = 0 offset_left = 1.0 @@ -64,5 +65,6 @@ script = ExtResource("3_exrk4") _testItemToCreate = ExtResource("4_5fdxq") [node name="BabushkaUiTmpInventorySelect" type="Sprite2D" parent="."] +visible = false position = Vector2(-648, 1020) texture = ExtResource("4_tiss4") diff --git a/scripts/CSharp/Common/CharacterControls/Player2D.cs b/scripts/CSharp/Common/CharacterControls/Player2D.cs index e771b73..b2e3550 100644 --- a/scripts/CSharp/Common/CharacterControls/Player2D.cs +++ b/scripts/CSharp/Common/CharacterControls/Player2D.cs @@ -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; + } }