Merge remote-tracking branch 'origin/c_sharp_setup' into inventory
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Camera;
|
||||
|
||||
public partial class CameraController : Camera2D
|
||||
{
|
||||
[Export] private float _multiplier = 1.0f;
|
||||
[Export] private Node2D _followNode;
|
||||
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
this.Position = _followNode.Transform.Origin * _multiplier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bqomwxclsbhd3
|
||||
@@ -0,0 +1,45 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Camera;
|
||||
|
||||
public partial class CameraPivot : Node3D
|
||||
{
|
||||
[Export] private bool _canPitch;
|
||||
[Export] private bool _canYaw;
|
||||
[Export] private float _rotateSpeed = 0.003f;
|
||||
[Export] private Node3D _subPivot;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if(@event.IsActionPressed("click"))
|
||||
{
|
||||
if (Input.MouseMode == Input.MouseModeEnum.Visible)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("ui_cancel"))
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
}
|
||||
|
||||
if (@event is InputEventMouseMotion test)
|
||||
{
|
||||
if (Input.MouseMode != Input.MouseModeEnum.Captured)
|
||||
return;
|
||||
|
||||
if (_canYaw)
|
||||
_subPivot.RotateX(test.Relative.Y * -_rotateSpeed);
|
||||
if(_canPitch)
|
||||
this.RotateY(test.Relative.X * -_rotateSpeed);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://r5tahuqvbucy
|
||||
@@ -0,0 +1 @@
|
||||
uid://b4h7k5w0jsjri
|
||||
@@ -0,0 +1 @@
|
||||
uid://c81bn1w8o0n2n
|
||||
@@ -0,0 +1,34 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class InteractionArea : Node3D
|
||||
{
|
||||
[Export] private Area3D _area;
|
||||
[Export] private Label3D _label;
|
||||
[Export] private bool _showLabel = true;
|
||||
|
||||
[Signal]
|
||||
public delegate void InteractedEventHandler();
|
||||
|
||||
public void OnPlayerEntered(Node3D player)
|
||||
{
|
||||
if(_showLabel)
|
||||
_label.Show();
|
||||
}
|
||||
|
||||
public void OnPlayerExited(Node3D player)
|
||||
{
|
||||
_label.Hide();
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies())
|
||||
{
|
||||
_label.Hide();
|
||||
EmitSignal(SignalName.Interacted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://dumwt7lledufm
|
||||
@@ -0,0 +1,20 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class Player2D : Node2D
|
||||
{
|
||||
[Export] private float _speed = 100f;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionPressed("move_right"))
|
||||
Position = new Vector2(Position.X + (_speed * (float)delta), Position.Y);
|
||||
if (Input.IsActionPressed("move_left"))
|
||||
Position = new Vector2(Position.X - (_speed * (float)delta), Position.Y);
|
||||
if (Input.IsActionPressed("move_up"))
|
||||
Position = new Vector2(Position.X, Position.Y - (_speed * (float)delta));
|
||||
if (Input.IsActionPressed("move_down"))
|
||||
Position = new Vector2(Position.X, Position.Y + (_speed * (float)delta));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cjbclkxesh3hc
|
||||
@@ -0,0 +1,116 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class Player3D : CharacterBody3D
|
||||
{
|
||||
[Export] private float _speed = 1.0f;
|
||||
[Export] private Camera3D _camera;
|
||||
|
||||
/// <summary>
|
||||
/// The sprite arrays are all setup like this:
|
||||
/// 0 - idle
|
||||
/// 1 - walking
|
||||
/// </summary>
|
||||
[Export] private AnimatedSprite3D[] _frontSpritesAnimated;
|
||||
[Export] private AnimatedSprite3D[] _sideSpritesAnimated;
|
||||
[Export] private AnimatedSprite3D[] _backSpritesAnimated;
|
||||
|
||||
private bool _sideFlipped;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var inputDir = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
||||
if (inputDir == Vector2.Zero)
|
||||
return;
|
||||
|
||||
MoveOnInput(inputDir, delta);
|
||||
SwitchSprites(inputDir);
|
||||
}
|
||||
|
||||
private void MoveOnInput(Vector2 inputDir, double delta)
|
||||
{
|
||||
inputDir = inputDir.Rotated(-_camera.GlobalRotation.Y);
|
||||
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
Velocity = new Vector3(direction.X * _speed * (float) delta * Scale.X, Velocity.Y, direction.Z * _speed * (float) delta * Scale.Z);
|
||||
else
|
||||
Velocity = Velocity.MoveToward(new Vector3(0, 0, 0), _speed);
|
||||
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
private void SwitchSprites(Vector2 inputDir)
|
||||
{
|
||||
float X = inputDir.X;
|
||||
float Y = inputDir.Y;
|
||||
|
||||
if (X == 0.0 && Y == 0.0)
|
||||
{
|
||||
ActivateFrontSpriteIdle(0, true, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (X != 0)
|
||||
{
|
||||
ActivateFrontSpriteIdle(1, false, true, false);
|
||||
|
||||
if (X > 0.0f)
|
||||
{
|
||||
_sideFlipped = false;
|
||||
}
|
||||
|
||||
if (X < 0.0f)
|
||||
{
|
||||
_sideFlipped = true;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _sideSpritesAnimated)
|
||||
{
|
||||
animatedSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Y != 0)
|
||||
{
|
||||
if (Y < 0.0f)
|
||||
{
|
||||
ActivateFrontSpriteIdle(1, false, false, true);
|
||||
}
|
||||
|
||||
if (Y > 0.0f)
|
||||
{
|
||||
ActivateFrontSpriteIdle(0, true, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ActivateFrontSpriteIdle(int index, bool frontActive, bool sideActive, bool backActive)
|
||||
{
|
||||
DeactivateAll();
|
||||
_frontSpritesAnimated[index].Visible = frontActive;
|
||||
_sideSpritesAnimated[index].Visible = sideActive;
|
||||
_backSpritesAnimated[index].Visible = backActive;
|
||||
}
|
||||
|
||||
private void DeactivateAll()
|
||||
{
|
||||
foreach (var animatedSprite in _frontSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _sideSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _backSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b4ugrget2x6lb
|
||||
@@ -0,0 +1,43 @@
|
||||
using Godot;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b1sscdr4ptec8
|
||||
@@ -0,0 +1,46 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public enum FieldState
|
||||
{
|
||||
Empty = 0,
|
||||
Tilled = 1,
|
||||
Planted = 2,
|
||||
Watered = 3
|
||||
}
|
||||
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[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>.
|
||||
/// </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://histmmyi1wr
|
||||
@@ -0,0 +1,68 @@
|
||||
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)];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://yfnjmuuxs3oq
|
||||
@@ -0,0 +1 @@
|
||||
uid://dnu6bnwvhlfut
|
||||
@@ -0,0 +1 @@
|
||||
uid://cgkea4bmd6a8f
|
||||
@@ -0,0 +1 @@
|
||||
uid://tm14kfypgn0h
|
||||
@@ -0,0 +1 @@
|
||||
uid://dd7v316ib8fe7
|
||||
@@ -0,0 +1 @@
|
||||
uid://cp4snd0amnhfu
|
||||
@@ -0,0 +1,36 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Switches between two Sprite Options.
|
||||
/// </summary>
|
||||
public partial class SpriteSwitcher : Node3D
|
||||
{
|
||||
[Export] private Sprite3D _trueSprite;
|
||||
[Export] private Sprite3D _falseSprite;
|
||||
[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(_trueSprite != null)
|
||||
_trueSprite.Visible = _state;
|
||||
if(_falseSprite != null)
|
||||
_falseSprite.Visible = !_state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://v34pl0nlp4x
|
||||
@@ -1,17 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
public partial class test : Node2D
|
||||
{
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
public class test2
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user