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