Spawning fields works
This commit is contained in:
@@ -5,13 +5,44 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
public partial class FarmingControls : Node3D
|
||||
{
|
||||
[Export] private Sprite3D _hoeSprite;
|
||||
[Export] private PackedScene _fieldPrefab;
|
||||
[Export] private Node _fieldParent;
|
||||
[Export] private Node3D _movingPlayer;
|
||||
|
||||
private bool _hoeInHand = false;
|
||||
|
||||
public void ActivateHoe(bool activate)
|
||||
{
|
||||
_hoeSprite.Visible = !activate;
|
||||
_hoeInHand = !activate;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("click") && _hoeInHand)
|
||||
{
|
||||
MakeField();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Notification(int notification)
|
||||
{
|
||||
GD.Print("Player global position: " + _movingPlayer.GlobalPosition);
|
||||
}
|
||||
|
||||
private void MakeField()
|
||||
{
|
||||
if(_fieldParent == null || _fieldPrefab == null)
|
||||
return;
|
||||
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
|
||||
if (fieldInstance is Node3D field3d)
|
||||
{
|
||||
field3d.Position = _movingPlayer.GlobalPosition;
|
||||
}
|
||||
|
||||
_fieldParent.AddChild(fieldInstance);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,15 @@ public enum FieldState
|
||||
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Untilled;
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture3D Watered;
|
||||
[Export] private FieldState FieldState = FieldState.Empty;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Texture = Tilled;
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the field'S interaction area and presses <E>.
|
||||
|
||||
Reference in New Issue
Block a user