Reworking 2D interactions
This commit is contained in:
@@ -1202,6 +1202,8 @@ _farmingControls = NodePath("FarmingControls")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite")]
|
||||
position = Vector2(0, 374)
|
||||
collision_layer = 3
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_ssqtd")
|
||||
_speed = 750.0
|
||||
_sprite = NodePath("visuals/Animated Sprites")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=303 format=3 uid="uid://dbd1niu3tp8y5"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b4ugrget2x6lb" path="res://scripts/CSharp/Common/CharacterControls/Player3D.cs" id="1_3trg2"]
|
||||
[ext_resource type="Script" uid="uid://bblprbhnbyv77" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"]
|
||||
[ext_resource type="Script" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"]
|
||||
[ext_resource type="Texture2D" uid="uid://duaideiajsu8r" path="res://art/characters/Vesna/babushka concept art vesna.png" id="2_3trg2"]
|
||||
[ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farm/base_field.tscn" id="2_oq5hi"]
|
||||
[ext_resource type="Texture2D" uid="uid://3pj2q7wtuion" path="res://art/farm/farming/farmobjekte/hoe.png" id="4_pkl5l"]
|
||||
|
||||
@@ -154,5 +154,7 @@ locale/translations=PackedStringArray("res://dialog/translations/dialogic_charac
|
||||
|
||||
[layer_names]
|
||||
|
||||
2d_physics/layer_1="interaction itemss"
|
||||
3d_physics/layer_1="General"
|
||||
2d_physics/layer_2="Background elements"
|
||||
3d_physics/layer_5="Player"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=44 format=3 uid="uid://gigb28qk8t12"]
|
||||
[gd_scene load_steps=47 format=3 uid="uid://gigb28qk8t12"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/Player2D.tscn" id="1_7wfwe"]
|
||||
[ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"]
|
||||
@@ -26,6 +26,9 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dg7rlugnq0t45" path="res://art/farm/farming/farmobjekte/brünnen.png" id="21_ualyd"]
|
||||
[ext_resource type="Script" uid="uid://dhxtdhfqx3bte" path="res://scripts/CSharp/Common/Farming/FieldService2D.cs" id="25_0qu0h"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1d2e7ely6hyw" path="res://prefabs/farm/base_field_2d.tscn" id="26_vbdb2"]
|
||||
[ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interaction_area_2d.tscn" id="27_klb81"]
|
||||
[ext_resource type="PackedScene" uid="uid://ce0mc0ddijmyi" path="res://prefabs/interactions/sprite_switcher_2d.tscn" id="28_p6n74"]
|
||||
[ext_resource type="Texture2D" uid="uid://x8hr8287ff2n" path="res://art/farm/farming/farmobjekte/tools atlas.png" id="29_p6n74"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xy0kg"]
|
||||
shader = ExtResource("13_7p0hq")
|
||||
@@ -573,6 +576,8 @@ scale = Vector2(30, 1)
|
||||
texture = ExtResource("20_if5vh")
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="Fence/Fence"]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Fence/Fence/StaticBody2D"]
|
||||
position = Vector2(0.666672, 76)
|
||||
@@ -587,6 +592,8 @@ scale = Vector2(30, 1)
|
||||
texture = ExtResource("20_if5vh")
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="Fence/Fence2"]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Fence/Fence2/StaticBody2D"]
|
||||
position = Vector2(0.266632, 172)
|
||||
@@ -615,6 +622,8 @@ flip_h = true
|
||||
position = Vector2(-5888, 4624)
|
||||
rotation = 1.5708
|
||||
scale = Vector2(8, 1)
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Fence/EndLeftCollider"]
|
||||
position = Vector2(-218, -4.00146)
|
||||
@@ -624,6 +633,8 @@ shape = SubResource("RectangleShape2D_0qu0h")
|
||||
position = Vector2(15952, 4592)
|
||||
rotation = 1.5708
|
||||
scale = Vector2(8, 1)
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Fence/EndRightCollider"]
|
||||
position = Vector2(-206.5, 12.001)
|
||||
@@ -640,6 +651,8 @@ scale = Vector2(5, 5)
|
||||
texture = ExtResource("2_lhtpe")
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="Farm visuals/Static/House Mockup"]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Farm visuals/Static/House Mockup/StaticBody2D"]
|
||||
position = Vector2(-257.6, 236.8)
|
||||
@@ -683,3 +696,35 @@ position = Vector2(12080, 3296)
|
||||
|
||||
[node name="BaseField4" parent="." instance=ExtResource("26_vbdb2")]
|
||||
position = Vector2(12080, 2544)
|
||||
|
||||
[node name="Hoe Pickup" parent="." instance=ExtResource("27_klb81")]
|
||||
position = Vector2(3264, 2120)
|
||||
rotation = 3.3074
|
||||
|
||||
[node name="SpriteSwitcher2d" parent="Hoe Pickup" instance=ExtResource("28_p6n74")]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
|
||||
[node name="Watercan Pickup" parent="." instance=ExtResource("27_klb81")]
|
||||
position = Vector2(6216, 2248)
|
||||
|
||||
[node name="Label" parent="Watercan Pickup" index="1"]
|
||||
z_index = 1
|
||||
|
||||
[node name="SpriteSwitcher2d" parent="Watercan Pickup" instance=ExtResource("28_p6n74")]
|
||||
|
||||
[node name="FirstSprite" parent="Watercan Pickup/SpriteSwitcher2d" index="0"]
|
||||
texture = ExtResource("29_p6n74")
|
||||
region_rect = Rect2(-2, 1119, 430, 301)
|
||||
|
||||
[node name="SecondSprite" parent="Watercan Pickup/SpriteSwitcher2d" index="1"]
|
||||
texture = ExtResource("29_p6n74")
|
||||
region_rect = Rect2(1, 1127, 423, 301)
|
||||
|
||||
[connection signal="Interacted" from="Hoe Pickup" to="Hoe Pickup/SpriteSwitcher2d" method="SwitchState"]
|
||||
[connection signal="Switch" from="Hoe Pickup/SpriteSwitcher2d" to="YSorted/Player2d" method="ActivateHoe"]
|
||||
[connection signal="Interacted" from="Watercan Pickup" to="Watercan Pickup/SpriteSwitcher2d" method="SwitchState"]
|
||||
[connection signal="Switch" from="Watercan Pickup/SpriteSwitcher2d" to="YSorted/Player2d" method="ActivateWateringCan"]
|
||||
|
||||
[editable path="Hoe Pickup"]
|
||||
[editable path="Watercan Pickup"]
|
||||
[editable path="Watercan Pickup/SpriteSwitcher2d"]
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using Babushka.scripts.CSharp.Common.Farming;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class VesnaBehaviour : Node
|
||||
{
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private FieldService2D _fieldParent;
|
||||
[Export] private FarmingControls2D _farmingControls;
|
||||
|
||||
[Signal] public delegate void ToolPickupEventHandler(bool success);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_farmingControls.FieldParent = _fieldParent;
|
||||
}
|
||||
|
||||
#region Farming
|
||||
|
||||
public void ActivateHoe(bool activate)
|
||||
{
|
||||
ActivateTool(activate, 0);
|
||||
}
|
||||
|
||||
public void ActivateWateringCan(bool activate)
|
||||
{
|
||||
ActivateTool(activate, 1);
|
||||
}
|
||||
|
||||
private void ActivateTool(bool activate , int toolId)
|
||||
{
|
||||
bool success = false;
|
||||
if (toolId == 0)
|
||||
{
|
||||
success = _farmingControls.ActivateHoe(activate);
|
||||
}
|
||||
else if (toolId == 1)
|
||||
{
|
||||
success = _farmingControls.ActivateWateringCan(activate);
|
||||
}
|
||||
EmitSignal(SignalName.ToolPickup, success);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://bblprbhnbyv77
|
||||
@@ -14,28 +14,29 @@ public partial class FarmingControls2D : Node2D
|
||||
|
||||
public FieldService2D FieldParent;
|
||||
|
||||
private bool _hoeInHand = false;
|
||||
private bool _waterCanInHand = false;
|
||||
private int _toolId = -1;
|
||||
|
||||
#region Tools
|
||||
|
||||
public bool ActivateHoe(bool activate)
|
||||
public bool ActivateTool(bool activate, int toolId)
|
||||
{
|
||||
bool success = ActivateTool(activate, _hoeSprite);
|
||||
_hoeInHand = success;
|
||||
return success;
|
||||
}
|
||||
if(_toolId < 0)
|
||||
return false;
|
||||
|
||||
public bool ActivateWateringCan(bool activate)
|
||||
switch (toolId)
|
||||
{
|
||||
bool success = ActivateTool(activate, _wateringCanSprite);
|
||||
_waterCanInHand = success;
|
||||
return success;
|
||||
}
|
||||
case 0:
|
||||
_hoeSprite.Visible = activate;
|
||||
break;
|
||||
case 1:
|
||||
_wateringCanSprite.Visible = activate;
|
||||
|
||||
private bool ActivateTool(bool activate, Sprite2D tool)
|
||||
{
|
||||
tool.Visible = !activate;
|
||||
break;
|
||||
default:
|
||||
_toolId = -1;
|
||||
break;
|
||||
}
|
||||
_toolId = toolId;
|
||||
return !activate;
|
||||
}
|
||||
|
||||
@@ -47,12 +48,12 @@ public partial class FarmingControls2D : Node2D
|
||||
|
||||
Vector2I adjustedPosition = new Vector2I(AdjustValue(mousePosition.X), AdjustValue(mousePosition.Y));
|
||||
|
||||
if (@event.IsActionPressed("click") && _hoeInHand)
|
||||
if (@event.IsActionPressed("click") && _toolId == 0)
|
||||
{
|
||||
MakeField(adjustedPosition);
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("click") && _waterCanInHand)
|
||||
if (@event.IsActionPressed("click") && _toolId == 1)
|
||||
{
|
||||
WaterTheField(adjustedPosition);
|
||||
}
|
||||
|
||||
@@ -29,16 +29,8 @@ public partial class VesnaBehaviour2D : Node
|
||||
|
||||
private void ActivateTool(bool activate , int toolId)
|
||||
{
|
||||
bool success = false;
|
||||
if (toolId == 0)
|
||||
{
|
||||
success = _farmingControls.ActivateHoe(activate);
|
||||
}
|
||||
else if (toolId == 1)
|
||||
{
|
||||
success = _farmingControls.ActivateWateringCan(activate);
|
||||
}
|
||||
EmitSignal(SignalName.ToolPickup, success);
|
||||
bool activated = _farmingControls.ActivateTool(activate, toolId);
|
||||
EmitSignal(SignalName.ToolPickup, activated);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Switches between two available Sprite Options.
|
||||
/// </summary>
|
||||
public partial class SpriteSwitcher2D : Node2D
|
||||
{
|
||||
[Export] private Sprite2D _firstSprite;
|
||||
[Export] private Sprite2D _secondSprite;
|
||||
[Export] private bool _state = true;
|
||||
|
||||
[Signal]
|
||||
public delegate void SwitchEventHandler(bool state);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetState();
|
||||
}
|
||||
|
||||
public void SwitchState()
|
||||
{
|
||||
_state = !_state;
|
||||
EmitSignal(SignalName.Switch, _state);
|
||||
SetState();
|
||||
}
|
||||
|
||||
private void SetState()
|
||||
{
|
||||
if(_firstSprite != null)
|
||||
_firstSprite.Visible = _state;
|
||||
if(_secondSprite != null)
|
||||
_secondSprite.Visible = !_state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user