✨ End game
This commit is contained in:
@ -81,8 +81,7 @@ public partial class World : Node2D
|
||||
{
|
||||
var player = PlayerScene.Instantiate<Player>();
|
||||
player.PlayerId = id;
|
||||
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(GD.RandRange(-100, 100), GD.RandRange(-100, 100));
|
||||
player.Name = BuildPlayerName(id);
|
||||
player.PlayerDied += (killerId) =>
|
||||
{
|
||||
@ -109,7 +108,7 @@ public partial class World : Node2D
|
||||
{
|
||||
if (RoundCount >= RoundTotalCount)
|
||||
{
|
||||
// TODO End this game
|
||||
Rpc(nameof(EndGame));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -129,9 +128,7 @@ public partial class World : Node2D
|
||||
foreach (var child in GetChildren())
|
||||
{
|
||||
if (child is Player { IsCurrentPlayer: true } player)
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -147,4 +144,12 @@ public partial class World : Node2D
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
private void EndGame()
|
||||
{
|
||||
GetParent().GetNode<Control>("OverlayLayer/Hud").Hide();
|
||||
GetParent().GetNode<Control>("OverlayLayer/GameOverScreen").Show();
|
||||
GetTree().Paused = true;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public partial class BootScreen : Control
|
||||
var count = Multiplayer.GetPeers().Length;
|
||||
PlayerCountLabel.Text = $"{(count + 1):00}/{16}";
|
||||
|
||||
StartGameButton.Disabled = !Multiplayer.IsServer();
|
||||
StartGameButton.Disabled = !Multiplayer.IsServer() || Multiplayer.GetPeers().Length == 0;
|
||||
}
|
||||
|
||||
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||||
@ -32,7 +32,6 @@ public partial class BootScreen : Control
|
||||
{
|
||||
EmitSignal(SignalName.StartGame);
|
||||
var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
|
||||
// TODO Fix this I don't know why the first round player's name won't fully apply
|
||||
World.Scoreboard.SetName(Multiplayer.GetUniqueId(), name ?? $"Player#{Multiplayer.GetUniqueId()}");
|
||||
World.StartGame(currentPlayerName: name);
|
||||
Hide();
|
||||
|
29
Scripts/UI/GameOverScreen.cs
Normal file
29
Scripts/UI/GameOverScreen.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System.Linq;
|
||||
using AceField.Scripts.Logic;
|
||||
using Godot;
|
||||
|
||||
namespace AceField.Scripts.UI;
|
||||
|
||||
public partial class GameOverScreen : Control
|
||||
{
|
||||
[Export] public Scoreboard Scoreboard;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!Visible) return;
|
||||
|
||||
var data = Scoreboard.GetData(Multiplayer.GetUniqueId());
|
||||
if (data == null) return;
|
||||
|
||||
var place = 1;
|
||||
var list = Scoreboard.Players.ToList();
|
||||
list.Sort((a, b) => b.Value.Score.CompareTo(a.Value.Score));
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (Multiplayer.GetUniqueId() == item.Key) break;
|
||||
place++;
|
||||
}
|
||||
|
||||
GetNode<Label>("CenterContainer/Panel/VBoxContainer/Caption").Text = $"You're in the {place} place";
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ public partial class HUD : Control
|
||||
roundBar.Value = World.RoundProgress * 100;
|
||||
|
||||
var roundLabel = GetNode<Label>("BottomBox/HBox/RoundLabel");
|
||||
roundLabel.Text = $"Round {World.RoundCount}";
|
||||
roundLabel.Text = $"Round {World.RoundCount:00}/{World.RoundTotalCount:00}";
|
||||
|
||||
var player = World.GetCurrentPlayer();
|
||||
if (player == null) return;
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using AceField.Scripts.Logic;
|
||||
using Godot;
|
||||
|
||||
@ -12,7 +13,8 @@ public partial class Leaderboard : Control
|
||||
Visible = Input.IsActionPressed("ui_leaderboard");
|
||||
|
||||
if (!Visible) return;
|
||||
|
||||
if (Scoreboard.Players.Count == 1) return;
|
||||
|
||||
if (GetNode<Control>("List").GetChildCount() != Scoreboard.Players.Count)
|
||||
{
|
||||
CleanNodes();
|
||||
@ -21,16 +23,17 @@ public partial class Leaderboard : Control
|
||||
}
|
||||
|
||||
var place = 1;
|
||||
foreach (var node in GetNode<Control>("List").GetChildren())
|
||||
var data = Scoreboard.Players.ToList();
|
||||
data.Sort((a, b) => b.Value.Score.CompareTo(a.Value.Score));
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (node is not LeaderboardRecord record) continue;
|
||||
var record = GetNode<Control>("List").GetNode<LeaderboardRecord>($"Record_{place}");
|
||||
|
||||
var data = Scoreboard.GetData(record.PlayerId);
|
||||
if (data == null) continue;
|
||||
record!.PlayerId = item.Key;
|
||||
|
||||
record.Place = place;
|
||||
record.Score = data.Score;
|
||||
record.PlayerName = data.Name;
|
||||
record.Score = item.Value.Score;
|
||||
record.PlayerName = item.Value.Name;
|
||||
|
||||
place++;
|
||||
}
|
||||
@ -56,6 +59,7 @@ public partial class Leaderboard : Control
|
||||
instance.Score = record.Value.Score;
|
||||
instance.PlayerId = record.Key;
|
||||
instance.CustomMinimumSize = new Vector2(0, 80);
|
||||
instance.Name = $"Record_{place}";
|
||||
GetNode("List").AddChild(instance);
|
||||
place++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user