You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.0 KiB
68 lines
2.0 KiB
using System;
|
|
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
|
|
|
public enum PlantState
|
|
{
|
|
None = 0,
|
|
Planted = 1,
|
|
SmallPlant = 2,
|
|
BigPlant = 3,
|
|
Ready = 4
|
|
}
|
|
|
|
public partial class PlantBehaviour : Node3D
|
|
{
|
|
[Export] private Sprite3D[] _seeds;
|
|
[Export] private Sprite3D[] _smallPlants;
|
|
[Export] private Sprite3D[] _bigPlants;
|
|
[Export] private Sprite3D[] _readyPlants;
|
|
[Export] private PlantState _state = PlantState.None;
|
|
|
|
private Sprite3D _currentPlantSprite = null;
|
|
|
|
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 Sprite3D GetRandomSprite(Sprite3D[] sprites)
|
|
{
|
|
Random rand = new Random();
|
|
return sprites[rand.Next(sprites.Length)];
|
|
}
|
|
|
|
} |