mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
Game Pausing
This commit is contained in:
parent
401d944ab4
commit
e86e9a2bf7
8 changed files with 160 additions and 22 deletions
|
|
@ -8,6 +8,8 @@ public partial class GameManager : Node2D
|
|||
|
||||
private PlayerMovement _player;
|
||||
|
||||
public GameState GameState { get; private set; }
|
||||
|
||||
public PlayerMovement Player => _player;
|
||||
|
||||
private Node2D _cameraTarget;
|
||||
|
|
@ -31,6 +33,9 @@ public partial class GameManager : Node2D
|
|||
private Node2D _bulletsContainer;
|
||||
public Node2D BulletsContainer => _bulletsContainer;
|
||||
|
||||
[Signal]
|
||||
public delegate void GameStateChangeEventHandler(GameState state);
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -64,11 +69,17 @@ public partial class GameManager : Node2D
|
|||
|
||||
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
|
||||
}
|
||||
|
||||
GameState = GameState.Playing;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("pause"))
|
||||
{
|
||||
TogglePause();
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnPlayer()
|
||||
|
|
@ -96,4 +107,48 @@ public partial class GameManager : Node2D
|
|||
|
||||
AddChild(_bulletsContainer);
|
||||
}
|
||||
|
||||
public void TogglePause()
|
||||
{
|
||||
if (GameState == GameState.Paused)
|
||||
{
|
||||
Unpause();
|
||||
}
|
||||
else if (GameState == GameState.Playing)
|
||||
{
|
||||
Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (GameState == GameState.Playing)
|
||||
{
|
||||
ChangeState(GameState.Paused);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unpause()
|
||||
{
|
||||
if (GameState == GameState.Paused)
|
||||
{
|
||||
ChangeState(GameState.Playing);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeState(GameState state)
|
||||
{
|
||||
if (state == GameState) return;
|
||||
GameState = state;
|
||||
EmitSignal(nameof(GameStateChange), (int)GameState);
|
||||
GD.Print($"Game state changed to {state}");
|
||||
}
|
||||
}
|
||||
|
||||
public enum GameState
|
||||
{
|
||||
Menu,
|
||||
Paused,
|
||||
Playing,
|
||||
Dialogue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue