AceField/Scripts/Logic/PlayerInput.cs

53 lines
1.2 KiB
C#
Raw Normal View History

2024-08-05 11:08:28 +00:00
using Godot;
2024-08-07 15:01:57 +00:00
namespace AceField.Scripts.Logic;
2024-08-05 11:08:28 +00:00
public partial class PlayerInput : MultiplayerSynchronizer
{
2024-08-07 15:01:57 +00:00
[Export] public bool IsDashing;
2024-08-08 15:23:31 +00:00
[Export] public bool IsBuilding;
[Export] public bool IsShooting;
2024-08-08 09:10:48 +00:00
[Export] public bool IsReloading;
2024-08-05 11:08:28 +00:00
2024-08-07 15:01:57 +00:00
[Export] public Vector2 MovementDirection;
2024-08-05 15:54:22 +00:00
2024-08-07 15:01:57 +00:00
private bool IsCurrentPlayer => GetMultiplayerAuthority() == Multiplayer.GetUniqueId();
2024-08-05 11:08:28 +00:00
2024-08-07 15:01:57 +00:00
public override void _Ready()
{
if (IsCurrentPlayer) return;
SetProcess(false);
SetPhysicsProcess(false);
}
2024-08-05 15:54:22 +00:00
2024-08-07 15:01:57 +00:00
[Rpc(CallLocal = true)]
private void Dash()
=> IsDashing = true;
2024-08-05 11:08:28 +00:00
[Rpc(CallLocal = true)]
private void Shoot()
=> IsShooting = true;
2024-08-08 09:10:48 +00:00
[Rpc(CallLocal = true)]
private void Reload()
=> IsReloading = true;
2024-08-08 15:23:31 +00:00
[Rpc(CallLocal = true)]
private void Build()
=> IsBuilding = true;
2024-08-07 15:01:57 +00:00
public override void _Process(double delta)
{
MovementDirection = Input.GetVector("move_left", "move_right", "move_up", "move_down");
2024-08-05 15:54:22 +00:00
2024-08-07 15:01:57 +00:00
if (Input.IsActionJustPressed("move_dash"))
Rpc(nameof(Dash));
2024-08-08 09:10:48 +00:00
if (Input.IsActionJustPressed("weapon_shoot"))
Rpc(nameof(Shoot));
2024-08-08 09:10:48 +00:00
if (Input.IsActionJustPressed("weapon_reload"))
Rpc(nameof(Reload));
2024-08-08 16:42:22 +00:00
if (Input.IsActionJustPressed("skill_place_tile"))
2024-08-08 15:23:31 +00:00
Rpc(nameof(Build));
2024-08-07 15:01:57 +00:00
}
}