added pickup animation

remotes/checkIfPRContentChanged-1749884192368007736/inventory
kziolkowski 8 months ago
parent 7276bdda38
commit 80c48ea3df

@ -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"]

@ -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")

@ -14,12 +14,16 @@ 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"))
{
Velocity = new Vector2(_speed, 0);
@ -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;
}
}

Loading…
Cancel
Save