Clear bullets on respawn

This commit is contained in:
Marco 2025-02-24 13:54:02 +01:00
commit 968dec6293

View file

@ -48,6 +48,9 @@ public partial class GameManager : Node2D
[Signal] [Signal]
public delegate void GameStateChangeEventHandler(GameState state); public delegate void GameStateChangeEventHandler(GameState state);
[Signal]
public delegate void PlayerRespawnedEventHandler();
// Called when the node enters the scene tree for the first time. // Called when the node enters the scene tree for the first time.
public override void _Ready() public override void _Ready()
{ {
@ -77,6 +80,8 @@ public partial class GameManager : Node2D
_inventoryManager.ItemRemoved += (item, currentAmount) => _hud.RemoveInventoryItem(item, currentAmount); _inventoryManager.ItemRemoved += (item, currentAmount) => _hud.RemoveInventoryItem(item, currentAmount);
} }
PlayerRespawned += OnPlayerRespawned;
GameState = GameState.Playing; GameState = GameState.Playing;
//_ = DelayPlayerSpawn(); //_ = DelayPlayerSpawn();
@ -84,6 +89,11 @@ public partial class GameManager : Node2D
CallDeferred(MethodName.DelayPlayerSpawn); CallDeferred(MethodName.DelayPlayerSpawn);
} }
private void OnPlayerRespawned()
{
this.ClearBullets();
}
public void ApplyMapStartData(MapStartDataResource mapStartData) public void ApplyMapStartData(MapStartDataResource mapStartData)
{ {
MapStartData = mapStartData; MapStartData = mapStartData;
@ -326,6 +336,15 @@ public partial class GameManager : Node2D
break; break;
} }
} }
public void ClearBullets()
{
if (_bulletsContainer is null) return;
foreach (var node in _bulletsContainer.GetChildren())
{
node.QueueFree();
}
}
} }
public enum GameState public enum GameState