Speed up round when no body alive

This commit is contained in:
LittleSheep 2024-08-09 15:52:00 +08:00
parent 33c6762ed3
commit dd27528fed

View File

@ -25,8 +25,8 @@ public partial class World : Node2D
_roundTimer.Autostart = true; _roundTimer.Autostart = true;
_roundTimer.Timeout += NewRound; _roundTimer.Timeout += NewRound;
_roundTimer.OneShot = true; _roundTimer.OneShot = true;
AddChild(_roundTimer); GetParent().AddChild(_roundTimer);
_roundTimer.Start(); _roundTimer.Start(RoundDuration);
// Add players into the game // Add players into the game
PutPlayers(currentPlayerName); PutPlayers(currentPlayerName);
@ -87,6 +87,8 @@ public partial class World : Node2D
{ {
if (killerId == 0) return; if (killerId == 0) return;
Scoreboard.AddScore(killerId); Scoreboard.AddScore(killerId);
if (CountPlayer() <= 2)
_roundTimer.Start(3);
}; };
AddChild(player, true); AddChild(player, true);
@ -113,14 +115,10 @@ public partial class World : Node2D
} }
RoundCount++; RoundCount++;
foreach (var child in GetChildren()) Rpc(nameof(CleanWorld));
{
if (child is not Timer)
child.QueueFree();
}
PutPlayers(); PutPlayers();
_roundTimer.Start(); _roundTimer.Start(RoundDuration);
} }
public Player GetCurrentPlayer() public Player GetCurrentPlayer()
@ -134,6 +132,18 @@ public partial class World : Node2D
return null; return null;
} }
public int CountPlayer()
{
var count = 0;
foreach (var child in GetChildren())
{
if (child is Player)
count++;
}
return count;
}
public T GetTileByPosition<T>(Vector2 position) where T : Node2D public T GetTileByPosition<T>(Vector2 position) where T : Node2D
{ {
foreach (var item in GetChildren()) foreach (var item in GetChildren())
@ -145,6 +155,16 @@ public partial class World : Node2D
return null; return null;
} }
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
private void CleanWorld()
{
foreach (var child in GetChildren())
{
child.QueueFree();
}
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)] [Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
private void EndGame() private void EndGame()
{ {