From 968dec62932d728eef8b060f30be9f7c44f9117e Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 24 Feb 2025 13:54:02 +0100 Subject: [PATCH] Clear bullets on respawn --- Scripts/GameManager.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index 0e0ee9b4..56771feb 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -48,6 +48,9 @@ public partial class GameManager : Node2D [Signal] public delegate void GameStateChangeEventHandler(GameState state); + [Signal] + public delegate void PlayerRespawnedEventHandler(); + // Called when the node enters the scene tree for the first time. public override void _Ready() { @@ -77,6 +80,8 @@ public partial class GameManager : Node2D _inventoryManager.ItemRemoved += (item, currentAmount) => _hud.RemoveInventoryItem(item, currentAmount); } + PlayerRespawned += OnPlayerRespawned; + GameState = GameState.Playing; //_ = DelayPlayerSpawn(); @@ -84,6 +89,11 @@ public partial class GameManager : Node2D CallDeferred(MethodName.DelayPlayerSpawn); } + private void OnPlayerRespawned() + { + this.ClearBullets(); + } + public void ApplyMapStartData(MapStartDataResource mapStartData) { MapStartData = mapStartData; @@ -326,6 +336,15 @@ public partial class GameManager : Node2D break; } } + + public void ClearBullets() + { + if (_bulletsContainer is null) return; + foreach (var node in _bulletsContainer.GetChildren()) + { + node.QueueFree(); + } + } } public enum GameState