diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index efbf6e0..5e4c2f1 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -4,6 +4,16 @@ using System.Linq; public partial class GameManager : Node { + [Signal] + public delegate void OnGameOverEventHandler(); + + [Signal] + public delegate void OnP1GameOverEventHandler(); + [Signal] + public delegate void OnP2GameOverEventHandler(); + + public int NumberOfPlayers; + public bool IsP1SelectingCharacter = true; public bool IsP2SelectingCharacter = true; @@ -18,7 +28,8 @@ public partial class GameManager : Node [Export] public Character _p2SelectedCharacter; - public bool P1GameOver = false; + private bool _p1GameOver = false; + private bool _p2GameOver = false; private int _p1CharacterIndex = 0; private int _p2CharacterIndex = 0; @@ -42,6 +53,34 @@ public partial class GameManager : Node _p1SelectedCharacter?.QueueFree(); _p1CharacterIndex = 0; } + + public void SetP1GameOver(bool isGameOver) + { + _p1GameOver = isGameOver; + if (isGameOver) + { + EmitSignal(SignalName.OnP1GameOver); + CheckForOverallGameOver(); + } + } + + public bool IsP1GameOver => _p1GameOver; + + public void SetP2GameOver(bool isGameOver) + { + _p2GameOver = isGameOver; + if (isGameOver) + { + EmitSignal(SignalName.OnP2GameOver); + CheckForOverallGameOver(); + } + } + + private void CheckForOverallGameOver() + { + if (_p1GameOver && _p2GameOver) + EmitSignal(SignalName.OnGameOver); + } } public partial class Character : CharacterBody3D diff --git a/Scripts/Player1.cs b/Scripts/Player1.cs index 5f92067..ab49910 100644 --- a/Scripts/Player1.cs +++ b/Scripts/Player1.cs @@ -17,6 +17,7 @@ public partial class Player1 : Character { CanShoot = true; _gameManager = GetTree().Root.GetNode("Main/GameManager"); + _gameManager.SetP1GameOver(false); } public override void _PhysicsProcess(double delta) @@ -94,7 +95,7 @@ public partial class Player1 : Character if (_gameManager._p1Characters.Count == 0) { GD.Print("Game over for P1"); - _gameManager.P1GameOver = true; + _gameManager.SetP1GameOver(true); } } } diff --git a/Scripts/StageGUI.cs b/Scripts/StageGUI.cs index 993ea82..624b9cf 100644 --- a/Scripts/StageGUI.cs +++ b/Scripts/StageGUI.cs @@ -14,7 +14,7 @@ public partial class StageGUI : Control public void OnCharacterSelect() { - if (_gameManager.P1GameOver) + if (_gameManager.IsP1GameOver) return; var wheel1 = GetNode("CharacterSelect/Wheel");