2D farming setup #8
@@ -1581,7 +1581,7 @@ animations = [{
|
|||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": &"diagonal farming",
|
"name": &"diagonal farming",
|
||||||
"speed": 10.0
|
"speed": 12.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [{
|
"frames": [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
@@ -3502,7 +3502,7 @@ y_sort_enabled = true
|
|||||||
script = ExtResource("1_yl84k")
|
script = ExtResource("1_yl84k")
|
||||||
_farmingControls = NodePath("FarmingControls")
|
_farmingControls = NodePath("FarmingControls")
|
||||||
|
|
||||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite")]
|
[node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite") groups=["PlantGrowing"]]
|
||||||
position = Vector2(0, 374)
|
position = Vector2(0, 374)
|
||||||
collision_layer = 4
|
collision_layer = 4
|
||||||
collision_mask = 3
|
collision_mask = 3
|
||||||
@@ -3523,9 +3523,8 @@ position = Vector2(0, -374)
|
|||||||
[node name="Animated Sprites" type="AnimatedSprite2D" parent="CharacterBody2D/visuals"]
|
[node name="Animated Sprites" type="AnimatedSprite2D" parent="CharacterBody2D/visuals"]
|
||||||
position = Vector2(0, 450)
|
position = Vector2(0, 450)
|
||||||
sprite_frames = SubResource("SpriteFrames_4yiyq")
|
sprite_frames = SubResource("SpriteFrames_4yiyq")
|
||||||
animation = &"side pickup"
|
animation = &"diagonal farming"
|
||||||
frame = 6
|
frame_progress = 0.503028
|
||||||
frame_progress = 0.00476268
|
|
||||||
offset = Vector2(0, -450)
|
offset = Vector2(0, -450)
|
||||||
|
|
||||||
[node name="Hoe" type="Sprite2D" parent="CharacterBody2D/visuals"]
|
[node name="Hoe" type="Sprite2D" parent="CharacterBody2D/visuals"]
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ folder_colors={
|
|||||||
"res://shader/": "pink"
|
"res://shader/": "pink"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global_group]
|
||||||
|
|
||||||
|
PlantGrowing=""
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
move_left={
|
move_left={
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ public partial class Player2D : CharacterBody2D
|
|||||||
{
|
{
|
||||||
[Export] private float _speed = 100f;
|
[Export] private float _speed = 100f;
|
||||||
[Export] private AnimatedSprite2D _sprite;
|
[Export] private AnimatedSprite2D _sprite;
|
||||||
|
[Export] private SceneTree.GroupCallFlags _fieldFlags;
|
||||||
|
|
||||||
// -1 means no tool.
|
// -1 means no tool.
|
||||||
private int _toolID = -1;
|
private int _toolID = -1;
|
||||||
@@ -15,13 +16,14 @@ public partial class Player2D : CharacterBody2D
|
|||||||
private bool anyActionPressed;
|
private bool anyActionPressed;
|
||||||
private bool _wateringInProgress;
|
private bool _wateringInProgress;
|
||||||
private bool _pickupAnimationInProgress;
|
private bool _pickupAnimationInProgress;
|
||||||
|
private bool _farmingAnimationInProgress;
|
||||||
private Vector2 _lastDirection = Vector2.Zero;
|
private Vector2 _lastDirection = Vector2.Zero;
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
anyActionPressed = false;
|
anyActionPressed = false;
|
||||||
|
|
||||||
if (_pickupAnimationInProgress || _wateringInProgress)
|
if (_pickupAnimationInProgress || _wateringInProgress || _farmingAnimationInProgress)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Input.IsActionPressed("move_right"))
|
if (Input.IsActionPressed("move_right"))
|
||||||
@@ -115,6 +117,9 @@ public partial class Player2D : CharacterBody2D
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called by FarmingControls Signal.
|
||||||
|
/// </summary>
|
||||||
public void PlayWateringAnimation()
|
public void PlayWateringAnimation()
|
||||||
{
|
{
|
||||||
if (_toolID == 1 && !_wateringInProgress)
|
if (_toolID == 1 && !_wateringInProgress)
|
||||||
@@ -146,4 +151,18 @@ public partial class Player2D : CharacterBody2D
|
|||||||
_pickupAnimationInProgress = false;
|
_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 System;
|
||||||
|
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||||
@@ -17,6 +18,7 @@ public partial class PlantBehaviour2D : Node2D
|
|||||||
|
|
||||||
private Sprite2D _currentPlantSprite = null;
|
private Sprite2D _currentPlantSprite = null;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transitions the plant to its next growth stage.
|
/// Transitions the plant to its next growth stage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -25,6 +27,8 @@ public partial class PlantBehaviour2D : Node2D
|
|||||||
if (_field.FieldState != FieldState.Watered)
|
if (_field.FieldState != FieldState.Watered)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
GetTree().CallGroup("PlantGrowing", Player2D.MethodName.PlayFarmingAnimation);
|
||||||
|
|
||||||
switch (_state)
|
switch (_state)
|
||||||
{
|
{
|
||||||
case PlantState.None:
|
case PlantState.None:
|
||||||
|
|||||||
Reference in New Issue
Block a user