AceField/Scripts/Logic/PlayerInput.cs

44 lines
1.1 KiB
C#
Raw Normal View History

2024-08-05 11:08:28 +00:00
using Godot;
namespace CodingLand.Scripts.Logic;
public partial class PlayerInput : MultiplayerSynchronizer
{
[Export] public bool IsDashing;
2024-08-05 15:54:22 +00:00
[Export] public Vector2 BuildingAt;
2024-08-05 11:08:28 +00:00
[Export] public Vector2 MovementDirection;
2024-08-05 15:54:22 +00:00
private bool IsCurrentPlayer => GetMultiplayerAuthority() == Multiplayer.GetUniqueId();
2024-08-05 11:08:28 +00:00
public override void _Ready()
{
2024-08-05 15:54:22 +00:00
if (IsCurrentPlayer) return;
SetProcess(false);
SetPhysicsProcess(false);
2024-08-05 11:08:28 +00:00
}
[Rpc(CallLocal = true)]
private void Dash()
2024-08-05 15:54:22 +00:00
=> IsDashing = true;
[Rpc(CallLocal = true)]
private void Build(Vector2 pos)
=> BuildingAt = pos;
2024-08-05 11:08:28 +00:00
public override void _Process(double delta)
{
MovementDirection = Input.GetVector("move_left", "move_right", "move_up", "move_down");
if (Input.IsActionJustPressed("move_dash"))
Rpc(nameof(Dash));
}
2024-08-05 15:54:22 +00:00
public override void _Input(InputEvent evt)
{
if (!IsCurrentPlayer) return;
if (evt is InputEventMouseButton { Pressed: true })
Rpc(nameof(Build), GetViewport().GetMousePosition());
}
2024-08-05 11:08:28 +00:00
}