Made interaction area 2d work - and farming/growing work again.
This commit is contained in:
@@ -3,6 +3,7 @@ using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FieldService2D : Node2D
|
||||
{
|
||||
[Export] private Dictionary<Vector2I, FieldBehaviour2D> fields = new Dictionary<Vector2I, FieldBehaviour2D>();
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
/// <summary>
|
||||
/// Determines the behaviour of a plant in Babushka.
|
||||
/// </summary>
|
||||
public partial class PlantBehaviour2D : Node2D
|
||||
{
|
||||
[Export] private Sprite2D[] _seeds;
|
||||
[Export] private Sprite2D[] _smallPlants;
|
||||
[Export] private Sprite2D[] _bigPlants;
|
||||
[Export] private Sprite2D[] _readyPlants;
|
||||
[Export] private PlantState _state = PlantState.None;
|
||||
|
||||
private Sprite2D _currentPlantSprite = null;
|
||||
|
||||
/// <summary>
|
||||
/// Transitions the plant to its next groth stage.
|
||||
/// </summary>
|
||||
public void Grow()
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case PlantState.None:
|
||||
_state = PlantState.Planted;
|
||||
_currentPlantSprite = GetRandomSprite(_seeds);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.Planted:
|
||||
_state = PlantState.SmallPlant;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = GetRandomSprite(_smallPlants);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.SmallPlant:
|
||||
_state = PlantState.BigPlant;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = GetRandomSprite(_bigPlants);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.BigPlant:
|
||||
_state = PlantState.Ready;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = GetRandomSprite(_readyPlants);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.Ready:
|
||||
_state = PlantState.None;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Sprite2D GetRandomSprite(Sprite2D[] sprites)
|
||||
{
|
||||
Random rand = new Random();
|
||||
return sprites[rand.Next(sprites.Length)];
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
public partial class VesnaBehaviour2D : Node
|
||||
{
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private FieldService _fieldParent;
|
||||
[Export] private FarmingControls _farmingControls;
|
||||
[Export] private FieldService2D _fieldParent;
|
||||
[Export] private FarmingControls2D _farmingControls;
|
||||
|
||||
[Signal] public delegate void ToolPickupEventHandler(bool success);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user