folder refactoring, plant_base adjustments
This commit is contained in:
@@ -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,79 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class Player3D : CharacterBody3D
|
||||
{
|
||||
[Export] private float _speed = 1.0f;
|
||||
[Export] private Camera3D _camera;
|
||||
[Export] private Sprite3D _frontSprite;
|
||||
[Export] private Sprite3D _sideSprite;
|
||||
|
||||
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)
|
||||
{
|
||||
ActivateFrontSprite(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (X != 0)
|
||||
{
|
||||
ActivateFrontSprite(false);
|
||||
|
||||
if (X > 0.0f)
|
||||
{
|
||||
_sideFlipped = false;
|
||||
_sideSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
|
||||
if (X < 0.0f)
|
||||
{
|
||||
_sideFlipped = true;
|
||||
_sideSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Y != 0)
|
||||
{
|
||||
ActivateFrontSprite(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ActivateFrontSprite(bool activate)
|
||||
{
|
||||
_frontSprite.Visible = activate;
|
||||
_sideSprite.Visible = !activate;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b4ugrget2x6lb
|
||||
Reference in New Issue
Block a user