End game

This commit is contained in:
2024-08-09 15:45:40 +08:00
parent 8390fb2794
commit 33c6762ed3
8 changed files with 134 additions and 23 deletions

View File

@ -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;
}
}