parent
2e21fb7e98
commit
8e0dced918
@ -0,0 +1 @@
|
|||||||
|
uid://n7oihifvqp23
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
using Babushka.scripts.CSharp.Common.Services;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||||
|
|
||||||
|
public partial class PlayerMovement : CharacterBody2D
|
||||||
|
{
|
||||||
|
[Export] private float _speed = 1000f;
|
||||||
|
|
||||||
|
private InventoryManager _inventoryManager;
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
bool anyActionPressed = false;
|
||||||
|
Vector2 currentVelocity = Vector2.Zero;
|
||||||
|
|
||||||
|
if (!InputService.Instance.InputEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool right = Input.IsActionPressed("move_right");
|
||||||
|
bool left = Input.IsActionPressed("move_left");
|
||||||
|
bool up = Input.IsActionPressed("move_up");
|
||||||
|
bool down = Input.IsActionPressed("move_down");
|
||||||
|
|
||||||
|
if (up)
|
||||||
|
{
|
||||||
|
currentVelocity += new Vector2(0, -_speed);
|
||||||
|
anyActionPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (down)
|
||||||
|
{
|
||||||
|
currentVelocity += new Vector2(0, _speed);
|
||||||
|
anyActionPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (right)
|
||||||
|
{
|
||||||
|
currentVelocity += new Vector2(_speed, 0);
|
||||||
|
|
||||||
|
anyActionPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left)
|
||||||
|
{
|
||||||
|
currentVelocity += new Vector2(-_speed, 0);
|
||||||
|
|
||||||
|
anyActionPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anyActionPressed)
|
||||||
|
{
|
||||||
|
Velocity = currentVelocity;
|
||||||
|
MoveAndSlide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.Common.Services;
|
||||||
|
|
||||||
|
public partial class InputService : Node
|
||||||
|
{
|
||||||
|
public static InputService Instance { get; private set; } = null!;
|
||||||
|
|
||||||
|
[Signal]
|
||||||
|
public delegate void InputEnabledChangedEventHandler(bool enabled);
|
||||||
|
|
||||||
|
private static bool _inputEnabled = true;
|
||||||
|
|
||||||
|
public bool InputEnabled
|
||||||
|
{
|
||||||
|
get => _inputEnabled;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_inputEnabled != value)
|
||||||
|
{
|
||||||
|
CallDeferred(nameof(SetInputEnabled), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetInputEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
_inputEnabled = enabled;
|
||||||
|
EmitSignal(SignalName.InputEnabledChanged, _inputEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _EnterTree()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://blmbgmdv4aui8
|
||||||
Loading…
Reference in new issue