Farming part I
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
public enum FieldState
|
||||
{
|
||||
Empty = 0,
|
||||
Tilled = 1,
|
||||
Planted = 2,
|
||||
Watered = 3
|
||||
}
|
||||
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Untilled;
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture3D Watered;
|
||||
[Export] private FieldState FieldState = FieldState.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the field'S interaction area and presses <E>.
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dnu6bnwvhlfut
|
||||
@@ -6,24 +6,29 @@ public partial class InteractionArea : Node3D
|
||||
{
|
||||
[Export] private Area3D _area;
|
||||
[Export] private Label3D _label;
|
||||
[Export] private bool _showLabel = true;
|
||||
|
||||
[Signal]
|
||||
public delegate void InteractedEventHandler();
|
||||
|
||||
public override void _Process(double d)
|
||||
public void OnPlayerEntered(Node3D player)
|
||||
{
|
||||
if (_area.HasOverlappingBodies())
|
||||
if(_showLabel)
|
||||
_label.Show();
|
||||
else
|
||||
_label.Hide();
|
||||
}
|
||||
|
||||
public void OnPlayerExited(Node3D player)
|
||||
{
|
||||
_label.Hide();
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if(@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies())
|
||||
if (@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies())
|
||||
{
|
||||
_label.Hide();
|
||||
EmitSignal(SignalName.Interacted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
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)];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://tm14kfypgn0h
|
||||
@@ -16,11 +16,11 @@ public partial class Player3D : CharacterBody3D
|
||||
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
Velocity = new Vector3(direction.X * _speed, Velocity.Y, direction.Z * _speed);
|
||||
Velocity = new Vector3(direction.X * _speed, Velocity.Y, direction.Z * _speed * (float) delta * Scale.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
Velocity = Velocity.MoveToward(new Vector3(0, 0, 0), _speed);
|
||||
Velocity = Velocity.MoveToward(new Vector3(0, 0, 0), _speed);
|
||||
}
|
||||
|
||||
MoveAndSlide();
|
||||
|
||||
Reference in New Issue
Block a user