🐛 Bug fixes
This commit is contained in:
parent
6b48561f45
commit
34100ee727
@ -22,27 +22,24 @@ properties/1/replication_mode = 1
|
|||||||
properties/2/path = NodePath("RotationCentre:rotation")
|
properties/2/path = NodePath("RotationCentre:rotation")
|
||||||
properties/2/spawn = true
|
properties/2/spawn = true
|
||||||
properties/2/replication_mode = 1
|
properties/2/replication_mode = 1
|
||||||
properties/3/path = NodePath(".:PlayerName")
|
properties/3/path = NodePath(".:Health")
|
||||||
properties/3/spawn = true
|
properties/3/spawn = true
|
||||||
properties/3/replication_mode = 1
|
properties/3/replication_mode = 1
|
||||||
properties/4/path = NodePath(".:Health")
|
properties/4/path = NodePath(".:MaxHealth")
|
||||||
properties/4/spawn = true
|
properties/4/spawn = true
|
||||||
properties/4/replication_mode = 1
|
properties/4/replication_mode = 1
|
||||||
properties/5/path = NodePath(".:MaxHealth")
|
properties/5/path = NodePath(".:ActionPoints")
|
||||||
properties/5/spawn = true
|
properties/5/spawn = true
|
||||||
properties/5/replication_mode = 1
|
properties/5/replication_mode = 1
|
||||||
properties/6/path = NodePath(".:ActionPoints")
|
properties/6/path = NodePath(".:MaxActionPoints")
|
||||||
properties/6/spawn = true
|
properties/6/spawn = true
|
||||||
properties/6/replication_mode = 1
|
properties/6/replication_mode = 1
|
||||||
properties/7/path = NodePath(".:MaxActionPoints")
|
properties/7/path = NodePath(".:AmmoAmount")
|
||||||
properties/7/spawn = true
|
properties/7/spawn = true
|
||||||
properties/7/replication_mode = 1
|
properties/7/replication_mode = 1
|
||||||
properties/8/path = NodePath(".:AmmoAmount")
|
properties/8/path = NodePath(".:MaxAmmoAmount")
|
||||||
properties/8/spawn = true
|
properties/8/spawn = true
|
||||||
properties/8/replication_mode = 1
|
properties/8/replication_mode = 1
|
||||||
properties/9/path = NodePath(".:MaxAmmoAmount")
|
|
||||||
properties/9/spawn = true
|
|
||||||
properties/9/replication_mode = 1
|
|
||||||
|
|
||||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_hojn2"]
|
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_hojn2"]
|
||||||
properties/0/path = NodePath("InputSynchronizer:IsDashing")
|
properties/0/path = NodePath("InputSynchronizer:IsDashing")
|
||||||
|
@ -97,10 +97,10 @@ size_flags_horizontal = 3
|
|||||||
text = "Round 1"
|
text = "Round 1"
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
|
|
||||||
[node name="RoundSecondLabel" type="Label" parent="BottomBox/HBox"]
|
[node name="ScoreLabel" type="Label" parent="BottomBox/HBox"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "60.00"
|
text = "Score 0"
|
||||||
horizontal_alignment = 2
|
horizontal_alignment = 2
|
||||||
|
|
||||||
[node name="ProgressBar" type="ProgressBar" parent="BottomBox"]
|
[node name="ProgressBar" type="ProgressBar" parent="BottomBox"]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
@ -16,17 +15,55 @@ public partial class Scoreboard : Node
|
|||||||
|
|
||||||
public void AddPlayer(int networkId, string playerName = null)
|
public void AddPlayer(int networkId, string playerName = null)
|
||||||
{
|
{
|
||||||
Players[networkId] = new PlayerData(playerName ?? $"Player#{networkId}");
|
Rpc(nameof(UpdateEntry), networkId, 0, playerName ?? $"Player#{networkId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemovePlayer(int networkId)
|
public void RemovePlayer(int networkId)
|
||||||
{
|
{
|
||||||
Players.Remove(networkId);
|
Rpc(nameof(DropEntry), networkId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddScore(int networkId, int amount = 1)
|
public void AddScore(int networkId, int amount = 1)
|
||||||
{
|
{
|
||||||
if (Players[networkId]?.Score == null) return;
|
if (!Players.TryGetValue(networkId, out var player)) return;
|
||||||
Players[networkId]!.Score += amount;
|
player.Score += amount;
|
||||||
|
Rpc(nameof(UpdateEntry), networkId, player.Score, player.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetName(int networkId, string name)
|
||||||
|
{
|
||||||
|
if (!Players.TryGetValue(networkId, out var player)) return;
|
||||||
|
player.Name = name;
|
||||||
|
Rpc(nameof(UpdateEntry), networkId, player.Score, player.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerData GetData(int networkId)
|
||||||
|
{
|
||||||
|
return Players.GetValueOrDefault(networkId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerData GetCurrentData()
|
||||||
|
{
|
||||||
|
return Players.GetValueOrDefault(Multiplayer.GetUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||||
|
private void UpdateEntry(int networkId, int score, string name)
|
||||||
|
{
|
||||||
|
if (Players.ContainsKey(networkId))
|
||||||
|
{
|
||||||
|
Players[networkId].Score = score;
|
||||||
|
Players[networkId].Name = name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Players.Add(networkId, new PlayerData(name, score));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||||
|
private void DropEntry(int networkId)
|
||||||
|
{
|
||||||
|
Players.Remove(networkId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ public partial class World : Node2D
|
|||||||
var position = Vector2.FromAngle(GD.Randf() * 2 * Mathf.Pi);
|
var position = Vector2.FromAngle(GD.Randf() * 2 * Mathf.Pi);
|
||||||
player.Position = new Vector2(position.X * 5f * GD.Randf(), position.Y * 5f * GD.Randf());
|
player.Position = new Vector2(position.X * 5f * GD.Randf(), position.Y * 5f * GD.Randf());
|
||||||
player.Name = BuildPlayerName(id);
|
player.Name = BuildPlayerName(id);
|
||||||
player.PlayerName = name;
|
|
||||||
player.PlayerDied += (killerId) =>
|
player.PlayerDied += (killerId) =>
|
||||||
{
|
{
|
||||||
if (killerId == 0) return;
|
if (killerId == 0) return;
|
||||||
@ -85,6 +84,7 @@ public partial class World : Node2D
|
|||||||
};
|
};
|
||||||
|
|
||||||
AddChild(player, true);
|
AddChild(player, true);
|
||||||
|
player.PlayerName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PutPlayers(string currentPlayerName = null)
|
private void PutPlayers(string currentPlayerName = null)
|
||||||
@ -108,7 +108,6 @@ public partial class World : Node2D
|
|||||||
}
|
}
|
||||||
|
|
||||||
PutPlayers();
|
PutPlayers();
|
||||||
|
|
||||||
_roundTimer.Start();
|
_roundTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,12 @@ public partial class Player : CharacterBody2D
|
|||||||
|
|
||||||
[Export] public float TileSize;
|
[Export] public float TileSize;
|
||||||
|
|
||||||
[Export] public string PlayerName;
|
[Export]
|
||||||
|
public string PlayerName
|
||||||
|
{
|
||||||
|
get => GetParent<World>()?.Scoreboard.GetData(PlayerId)?.Name;
|
||||||
|
set => GetParent<World>()?.Scoreboard.SetName(PlayerId, value);
|
||||||
|
}
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public int PlayerId
|
public int PlayerId
|
||||||
@ -64,9 +69,6 @@ public partial class Player : CharacterBody2D
|
|||||||
if (PlayerId == Multiplayer.GetUniqueId())
|
if (PlayerId == Multiplayer.GetUniqueId())
|
||||||
PlayerCamera.Enabled = true;
|
PlayerCamera.Enabled = true;
|
||||||
|
|
||||||
PlayerName ??= $"Player#{PlayerId}";
|
|
||||||
GetNode<Label>("Overlay/NameTag").Text = PlayerName;
|
|
||||||
|
|
||||||
GetNode<ProgressBar>("Overlay/HealthBar").Value = Health / MaxHealth * 100;
|
GetNode<ProgressBar>("Overlay/HealthBar").Value = Health / MaxHealth * 100;
|
||||||
|
|
||||||
GetNode<Timer>("ReloadTimer").Timeout += () =>
|
GetNode<Timer>("ReloadTimer").Timeout += () =>
|
||||||
@ -81,6 +83,8 @@ public partial class Player : CharacterBody2D
|
|||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
|
GetNode<Label>("Overlay/NameTag").Text = PlayerName;
|
||||||
|
|
||||||
if (PlayerInput.IsShooting)
|
if (PlayerInput.IsShooting)
|
||||||
{
|
{
|
||||||
PlayerInput.IsShooting = false;
|
PlayerInput.IsShooting = false;
|
||||||
|
@ -22,9 +22,7 @@ public partial class HUD : Control
|
|||||||
roundBar.Value = World.RoundProgress * 100;
|
roundBar.Value = World.RoundProgress * 100;
|
||||||
|
|
||||||
var roundLabel = GetNode<Label>("BottomBox/HBox/RoundLabel");
|
var roundLabel = GetNode<Label>("BottomBox/HBox/RoundLabel");
|
||||||
var roundSecLabel = GetNode<Label>("BottomBox/HBox/RoundSecondLabel");
|
|
||||||
roundLabel.Text = $"Round {World.RoundCount}";
|
roundLabel.Text = $"Round {World.RoundCount}";
|
||||||
roundSecLabel.Text = World.RoundTimeLeft.ToString("F2");
|
|
||||||
|
|
||||||
var player = World.GetCurrentPlayer();
|
var player = World.GetCurrentPlayer();
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
@ -48,5 +46,8 @@ public partial class HUD : Control
|
|||||||
|
|
||||||
var positionLabel = GetNode<Label>("BottomBox/HBox/PositionLabel");
|
var positionLabel = GetNode<Label>("BottomBox/HBox/PositionLabel");
|
||||||
positionLabel.Text = $"({player.Position.X:F2}, {player.Position.Y:F2})";
|
positionLabel.Text = $"({player.Position.X:F2}, {player.Position.Y:F2})";
|
||||||
|
|
||||||
|
var scoreLabel = GetNode<Label>("BottomBox/HBox/ScoreLabel");
|
||||||
|
scoreLabel.Text = $"Score {World.Scoreboard.GetCurrentData()?.Score.ToString() ?? "-"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user