Finalized new watering can mechanic with vfx and ui

pull/10/head
kziolkowski 6 months ago
parent 35c7e9a25e
commit fbad33213c

@ -2071,13 +2071,14 @@ script = ExtResource("1_yd5ep")
_farmingControls = NodePath("FarmingControls") _farmingControls = NodePath("FarmingControls")
_player2d = NodePath("CharacterBody2D") _player2d = NodePath("CharacterBody2D")
[node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite") groups=["PlantGrowing"]] [node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite", "_wateringParticles") groups=["PlantGrowing"]]
position = Vector2(0, 374) position = Vector2(0, 374)
collision_layer = 4 collision_layer = 4
collision_mask = 3 collision_mask = 3
script = ExtResource("2_1vqmv") script = ExtResource("2_1vqmv")
_speed = 1500.0 _speed = 1500.0
_sprite = NodePath("visuals/Animated Sprites") _sprite = NodePath("visuals/Animated Sprites")
_wateringParticles = NodePath("../pouring water vfx")
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
z_index = 1 z_index = 1
@ -2166,16 +2167,37 @@ visible = false
position = Vector2(3, 12) position = Vector2(3, 12)
texture = ExtResource("473_g32y8") texture = ExtResource("473_g32y8")
[node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer", "_camera")] [node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer", "_camera", "_wateringParticles")]
script = ExtResource("817_6nrw3") script = ExtResource("817_6nrw3")
_fieldPrefab = ExtResource("818_16w6h") _fieldPrefab = ExtResource("818_16w6h")
_movingPlayer = NodePath("../CharacterBody2D") _movingPlayer = NodePath("../CharacterBody2D")
_camera = NodePath("../CharacterBody2D/Camera2D") _camera = NodePath("../CharacterBody2D/Camera2D")
_wateringParticles = NodePath("../pouring water vfx")
_wateringCanParticlesVerticalOffset = -100.0
[node name="dialogic toggle" type="Node2D" parent="."] [node name="dialogic toggle" type="Node2D" parent="."]
position = Vector2(0, 374) position = Vector2(0, 374)
script = ExtResource("819_4na52") script = ExtResource("819_4na52")
[node name="pouring water vfx" type="CPUParticles2D" parent="."]
position = Vector2(-652, -599)
rotation = -0.333807
emitting = false
amount = 20
texture = ExtResource("473_g32y8")
lifetime = 0.5
randomness = 1.0
local_coords = true
draw_order = 1
emission_shape = 2
emission_sphere_radius = 128.0
linear_accel_min = 44.07
linear_accel_max = 78.81
scale_amount_min = 0.4
scale_amount_max = 0.8
color = Color(0.400601, 0.62444, 0.791217, 1)
hue_variation_max = 0.4
[connection signal="FilledWateringCan" from="." to="CharacterBody2D/WateringCanUI" method="Refill"] [connection signal="FilledWateringCan" from="." to="CharacterBody2D/WateringCanUI" method="Refill"]
[connection signal="InventorySelectionChanged" from="." to="CharacterBody2D/WateringCanUI" method="IsWateringCanActive"] [connection signal="InventorySelectionChanged" from="." to="CharacterBody2D/WateringCanUI" method="IsWateringCanActive"]
[connection signal="PickedUpTool" from="." to="CharacterBody2D" method="ActivateTool"] [connection signal="PickedUpTool" from="." to="CharacterBody2D" method="ActivateTool"]

@ -49,7 +49,6 @@ autowrap_mode = 3
shape = SubResource("CircleShape2D_tlhp6") shape = SubResource("CircleShape2D_tlhp6")
[node name="Label" parent="InteractionArea2" index="1"] [node name="Label" parent="InteractionArea2" index="1"]
visible = true
z_index = 5 z_index = 5
offset_left = -68.0 offset_left = -68.0
offset_top = -111.0 offset_top = -111.0

@ -127,7 +127,7 @@ size = Vector2(1041, 368)
[sub_resource type="CircleShape2D" id="CircleShape2D_p6n74"] [sub_resource type="CircleShape2D" id="CircleShape2D_p6n74"]
resource_local_to_scene = true resource_local_to_scene = true
radius = 600.0 radius = 371.058
[sub_resource type="CircleShape2D" id="CircleShape2D_2nee2"] [sub_resource type="CircleShape2D" id="CircleShape2D_2nee2"]
resource_local_to_scene = true resource_local_to_scene = true
@ -352,7 +352,7 @@ texture = ExtResource("11_vbdb2")
[node name="background layer 4" type="ParallaxLayer" parent="ParallaxBackground"] [node name="background layer 4" type="ParallaxLayer" parent="ParallaxBackground"]
position = Vector2(0, -82) position = Vector2(0, -82)
motion_scale = Vector2(0.5, 0.5) motion_scale = Vector2(0.5, 0.5)
motion_mirroring = Vector2(10500, 0) motion_mirroring = Vector2(10480, 0)
[node name="Kenney Assets" type="Node2D" parent="ParallaxBackground/background layer 4"] [node name="Kenney Assets" type="Node2D" parent="ParallaxBackground/background layer 4"]
visible = false visible = false
@ -475,7 +475,7 @@ texture = ExtResource("13_0qu0h")
[node name="JelenaMockupBg03" type="Sprite2D" parent="ParallaxBackground/background layer 4"] [node name="JelenaMockupBg03" type="Sprite2D" parent="ParallaxBackground/background layer 4"]
material = SubResource("ShaderMaterial_wtdui") material = SubResource("ShaderMaterial_wtdui")
position = Vector2(7965, 728) position = Vector2(7923, 727)
scale = Vector2(2.75, 2.75) scale = Vector2(2.75, 2.75)
texture = ExtResource("13_0qu0h") texture = ExtResource("13_0qu0h")
@ -869,7 +869,7 @@ shape = SubResource("RectangleShape2D_0sfl7")
_id = 1 _id = 1
[node name="CollisionShape3D" parent="YSorted/Brünnen/InteractionArea/Area2D" index="0"] [node name="CollisionShape3D" parent="YSorted/Brünnen/InteractionArea/Area2D" index="0"]
position = Vector2(80, -368) position = Vector2(146, -130)
shape = SubResource("CircleShape2D_p6n74") shape = SubResource("CircleShape2D_p6n74")
[node name="HoeGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")] [node name="HoeGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
@ -888,6 +888,9 @@ position = Vector2(8192, 3507)
[node name="SpawnWithItem" parent="YSorted/CanGenericPickup" index="0"] [node name="SpawnWithItem" parent="YSorted/CanGenericPickup" index="0"]
_blueprint = ExtResource("28_ipqaa") _blueprint = ExtResource("28_ipqaa")
[node name="InteractionArea2" parent="YSorted/CanGenericPickup" index="3"]
position = Vector2(0, -159)
[node name="CollisionShape3D" parent="YSorted/CanGenericPickup/InteractionArea2/Area2D" index="0"] [node name="CollisionShape3D" parent="YSorted/CanGenericPickup/InteractionArea2/Area2D" index="0"]
shape = SubResource("CircleShape2D_ipqaa") shape = SubResource("CircleShape2D_ipqaa")

@ -10,6 +10,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; [Export] private SceneTree.GroupCallFlags _fieldFlags;
[Export] private CpuParticles2D _wateringParticles;
// -1 means no tool. // -1 means no tool.
private int _toolID = -1; private int _toolID = -1;
@ -156,6 +157,7 @@ public partial class Player2D : CharacterBody2D
_sprite.Animation = "diagonal wateringcan"; _sprite.Animation = "diagonal wateringcan";
_sprite.Play(); _sprite.Play();
_canHandleInput = false; _canHandleInput = false;
_wateringParticles.Emitting = true;
Task.Run(DelayedInputHandlerReset); Task.Run(DelayedInputHandlerReset);
} }
} }
@ -163,6 +165,7 @@ public partial class Player2D : CharacterBody2D
private async Task DelayedInputHandlerReset() private async Task DelayedInputHandlerReset()
{ {
await Task.Delay(1000); await Task.Delay(1000);
_wateringParticles.Emitting = false;
_canHandleInput = true; _canHandleInput = true;
} }

@ -9,6 +9,8 @@ public partial class FarmingControls2D : Node2D
[Export] private PackedScene _fieldPrefab; [Export] private PackedScene _fieldPrefab;
[Export] private Node2D _movingPlayer; [Export] private Node2D _movingPlayer;
[Export] private Camera2D _camera; [Export] private Camera2D _camera;
[Export] private CpuParticles2D _wateringParticles;
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
public FieldService2D FieldService; public FieldService2D FieldService;
@ -40,6 +42,9 @@ public partial class FarmingControls2D : Node2D
} }
_toolId = activate ? toolId : -1; _toolId = activate ? toolId : -1;
WateringCanState.SetActive(_toolId == WateringCanState.WATERING_CAN_ID);
return activate; return activate;
} }
@ -56,15 +61,18 @@ public partial class FarmingControls2D : Node2D
MakeField(adjustedPosition); MakeField(adjustedPosition);
} }
if (@event.IsActionPressed("click") && _toolId == 1 && _wateringCanFilled) if (@event.IsActionPressed("click")
&& _toolId == WateringCanState.WATERING_CAN_ID
&& WateringCanState.GetFillState() > 0)
{ {
WaterTheField(adjustedPosition); WaterTheField(adjustedPosition);
} }
} }
#region WATERING
public void FillWateringCan() public void FillWateringCan()
{ {
if (_toolId == 1 ) if (_toolId == WateringCanState.WATERING_CAN_ID)
{ {
WateringCanState.Fill(); WateringCanState.Fill();
} }
@ -77,10 +85,14 @@ public partial class FarmingControls2D : Node2D
return; return;
field.Water(); field.Water();
_wateringParticles.GlobalPosition = new Vector2(field.GlobalPosition.X, field.GlobalPosition.Y + _wateringCanParticlesVerticalOffset);
WateringCanState.Water(); WateringCanState.Water();
EmitSignal(SignalName.WateringField); EmitSignal(SignalName.WateringField);
} }
#endregion
#region FIELD CREATION
private void MakeField(Vector2I fieldPosition) private void MakeField(Vector2I fieldPosition)
{ {
if(FieldService == null || _fieldPrefab == null) if(FieldService == null || _fieldPrefab == null)
@ -120,4 +132,6 @@ public partial class FarmingControls2D : Node2D
{ {
return input.Snapped(step); return input.Snapped(step);
} }
#endregion
} }

@ -1,29 +1,70 @@
namespace Babushka.scripts.CSharp.Common.Farming; namespace Babushka.scripts.CSharp.Common.Farming;
/// <summary>
/// Holds Information about the current state of the watering can.
/// Since there is only one watering can, we can track this in one central static class.
/// </summary>
public static class WateringCanState public static class WateringCanState
{ {
private static int _fillstate = 0; private static int _fillstate = 0;
/// <summary>
/// How many fields can be watered with one filling of the watering can.
/// </summary>
public const int MAX_FILLSTATE = 6; public const int MAX_FILLSTATE = 6;
/// <summary>
/// The Tool ID of the watering can. Used to identify it amongst other pickup items (and things that can be held by Vesna).
/// </summary>
public const int WATERING_CAN_ID = 1;
/// <summary>
/// Whether or not the watering can is currently active, i.e. held in hand by Vesna.
/// Triggers animations and ui.
/// </summary>
public static bool Active = false;
/// <summary>
/// Resets the fillstate to the max amount.
/// </summary>
public static void Fill() public static void Fill()
{ {
_fillstate = MAX_FILLSTATE; _fillstate = MAX_FILLSTATE;
} }
/// <summary>
/// Called when watering a field. Reduces the current fillstate.
/// </summary>
public static void Water() public static void Water()
{ {
if(_fillstate > 0) if(_fillstate > 0)
_fillstate--; _fillstate--;
} }
/// <summary>
/// Resets the watering can. Equivalent to "Empty" state.
/// </summary>
public static void Reset() public static void Reset()
{ {
_fillstate = 0; _fillstate = 0;
} }
/// <summary>
/// Returns the current fill state of the watering can.
/// </summary>
/// <returns></returns>
public static int GetFillState() public static int GetFillState()
{ {
return _fillstate; return _fillstate;
} }
/// <summary>
/// Sets the Active state of the watering can, i.e. if it is currently in hand and if the ui should be active.
/// </summary>
/// <param name="active"></param>
public static void SetActive(bool active)
{
Active = active;
}
} }

@ -37,7 +37,7 @@ public partial class WateringCanUi : Node2D
{ {
for (int i = 0; i < _stages.Length; i++) for (int i = 0; i < _stages.Length; i++)
{ {
_stages[i].Visible = i < WateringCanState.GetFillState(); _stages[i].Visible = WateringCanState.Active && i < WateringCanState.GetFillState();
} }
} }

Loading…
Cancel
Save