mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 07:55:54 +00:00
Added game over
This commit is contained in:
parent
1e116090e5
commit
8151298b44
14 changed files with 160 additions and 35 deletions
|
|
@ -18,6 +18,8 @@ public partial class Dead : PlayerStateBase
|
|||
|
||||
[Export]
|
||||
private ActorResourceProvider _motivationProvider;
|
||||
|
||||
private bool _isGameOver = false;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
|
|
@ -26,19 +28,21 @@ public partial class Dead : PlayerStateBase
|
|||
if (_motivationProvider.CurrentResource < 100f)
|
||||
{
|
||||
// If motivation is not enough show game over scene
|
||||
GD.Print("Game over");
|
||||
Hud.Instance.ShowGameOver();
|
||||
_isGameOver = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Else show respawn notification
|
||||
Hud.Instance.ShowGameOver();
|
||||
Hud.Instance.ShowTerminated();
|
||||
_isGameOver = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
// Hide game over
|
||||
Hud.Instance.HideGameOver();
|
||||
Hud.Instance.HideTerminated();
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
|
|
@ -46,7 +50,16 @@ public partial class Dead : PlayerStateBase
|
|||
// wait for button
|
||||
if (_inputProvider.GetShootJustPressed())
|
||||
{
|
||||
Respawn();
|
||||
if (_isGameOver)
|
||||
{
|
||||
// Restart Level
|
||||
GlobalState.Instance.RestartLevel();
|
||||
}
|
||||
else
|
||||
{
|
||||
Respawn();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -218,5 +218,9 @@ public partial class GlobalState : Node
|
|||
|
||||
DisplayServer.CursorSetCustomImage(scaled);
|
||||
}
|
||||
|
||||
|
||||
public void RestartLevel()
|
||||
{
|
||||
GotoScene(CurrentScene.GetSceneFilePath());
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,9 @@ public partial class Hud : CanvasLayer
|
|||
[Export] private LabelSettings _labelSettings;
|
||||
|
||||
[Export] private Container _gameOverPanel;
|
||||
[Export] private Container _fairyTerminatedPanel;
|
||||
|
||||
[Export] private Container _hudInfoPanel;
|
||||
|
||||
[ExportGroup("Pause Menu")] [Export]
|
||||
public Control PauseMenuContainer;
|
||||
|
|
@ -92,14 +95,40 @@ public partial class Hud : CanvasLayer
|
|||
public void ShowGameOver()
|
||||
{
|
||||
_gameOverPanel.Show();
|
||||
HideHud();
|
||||
_playerDead = true;
|
||||
}
|
||||
|
||||
public void HideGameOver()
|
||||
{
|
||||
_gameOverPanel.Hide();
|
||||
ShowHud();
|
||||
_playerDead = false;
|
||||
}
|
||||
|
||||
public void ShowTerminated()
|
||||
{
|
||||
_fairyTerminatedPanel.Show();
|
||||
HideHud();
|
||||
_playerDead = true;
|
||||
}
|
||||
|
||||
public void HideTerminated()
|
||||
{
|
||||
_fairyTerminatedPanel.Hide();
|
||||
ShowHud();
|
||||
_playerDead = false;
|
||||
}
|
||||
|
||||
public void ShowHud()
|
||||
{
|
||||
_hudInfoPanel.Show();
|
||||
}
|
||||
|
||||
public void HideHud()
|
||||
{
|
||||
_hudInfoPanel.Hide();
|
||||
}
|
||||
|
||||
public void UpdateHealth(float newHealth, float maxHealth)
|
||||
{
|
||||
|
|
@ -107,7 +136,7 @@ public partial class Hud : CanvasLayer
|
|||
if (_playerDead && newHealth > 0)
|
||||
{
|
||||
_playerDead = false;
|
||||
_gameOverPanel.Hide();
|
||||
_fairyTerminatedPanel.Hide();
|
||||
}
|
||||
|
||||
_healthLabel.Text = $"{newHealth}/{maxHealth}";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue