Block placing

This commit is contained in:
2024-08-05 23:54:22 +08:00
parent 3788e640a9
commit eb29e137a6
14 changed files with 282 additions and 42 deletions

View File

@ -6,22 +6,26 @@ public partial class PlayerInput : MultiplayerSynchronizer
{
[Export] public bool IsDashing;
[Export] public Vector2 BuildingAt;
[Export] public Vector2 MovementDirection;
private bool IsCurrentPlayer => GetMultiplayerAuthority() == Multiplayer.GetUniqueId();
public override void _Ready()
{
if (GetMultiplayerAuthority() != Multiplayer.GetUniqueId())
{
SetProcess(false);
SetPhysicsProcess(false);
}
if (IsCurrentPlayer) return;
SetProcess(false);
SetPhysicsProcess(false);
}
[Rpc(CallLocal = true)]
private void Dash()
{
IsDashing = true;
}
=> IsDashing = true;
[Rpc(CallLocal = true)]
private void Build(Vector2 pos)
=> BuildingAt = pos;
public override void _Process(double delta)
{
@ -30,4 +34,11 @@ public partial class PlayerInput : MultiplayerSynchronizer
if (Input.IsActionJustPressed("move_dash"))
Rpc(nameof(Dash));
}
public override void _Input(InputEvent evt)
{
if (!IsCurrentPlayer) return;
if (evt is InputEventMouseButton { Pressed: true })
Rpc(nameof(Build), GetViewport().GetMousePosition());
}
}

View File

@ -1,4 +1,3 @@
using System.Numerics;
using Godot;
using Vector2 = Godot.Vector2;