Improve game over conditions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -17,6 +17,7 @@ public partial class Player1 : Character
|
||||
{
|
||||
CanShoot = true;
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public partial class StageGUI : Control
|
||||
|
||||
public void OnCharacterSelect()
|
||||
{
|
||||
if (_gameManager.P1GameOver)
|
||||
if (_gameManager.IsP1GameOver)
|
||||
return;
|
||||
|
||||
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
||||
|
||||
Reference in New Issue
Block a user