Skip to content

Game Manager

Theo Ruefli edited this page Jul 24, 2026 · 12 revisions

Game Manager

System Summary

The Game Manager is responsible for controlling the Play State of a level. It initializes gameplay, spawns and configures the player, applies movement presets, activates enemies, tracks gameplay statistics, manages the pause and win screens, and handles level reset and replay functionality.

The manager also serves as the central coordinator for gameplay UI, including the timer, coin counter, pause menu, and level completion screen. It listens for global gameplay events such as player death, coin collection, and level completion to keep the play session synchronized.


Connected Systems

List of connecting/parent/subsystems.

Connecting Systems

Subsystems


Related Controls

Gameplay controls are documented under the Player Controller.

The Game Manager additionally handles the following UI controls:

  • Pause Button — Toggles the pause state.
  • Resume Button — Returns from the pause menu.
  • Reset Button — Reloads the current level.
  • Replay Button — Restarts the level after completion.
  • Editor Button — Returns to the level editor after playtesting.

Bugs

List of known bugs.

  • None currently.

Feature List / Breakdown of Features

  • Player Initialization – Finds the spawned player, applies the selected movement preset, stores the starting position, and connects gameplay signals.
  • Enemy Initialization – Enables enemy processing and applies enemy property resources based on their tile positions.
  • Pause System – Pauses and resumes gameplay while swapping between gameplay UI and the pause menu.
  • Level Reset – Reloads the current playable level and restores all gameplay state.
  • Coin Tracking – Counts collectible coins, tracks collected coins, and updates both gameplay and completion UI.
  • Checkpoint Tracking - Keeps track of the player's current checkpoint if they have one, respawning them there on death.
  • Gameplay Timer – Records elapsed playtesting time and continuously updates the timer display.
  • Win Screen – Stops gameplay upon reaching the goal, displays final completion statistics, and provides replay/editor options.
  • Replay Functionality – Immediately restarts the current level from the win screen.
  • Return to Editor – Exits play mode and restores the editor state after testing.
  • Health Monitoring – Receives player health updates through connected signals for gameplay monitoring and future expansion.

Important Variables

Name the most important variables, their type, and purpose.

Gameplay State

  • enum PlayState { PAUSE, PLAY } – Represents whether gameplay is currently paused or active.
  • var playState : PlayState – Stores the current gameplay state.
  • var goalReached : bool – Prevents pause/reset logic after the level has been completed.

Player

  • var player : CharacterBody2D – Reference to the active player instance.
  • var playerStartingPosition : Vector2 – Stores the player's initial spawn location.
  • **var playerCheckpointPosition : Vector2 = Vector2(-1, -1) = Stores the player's checkpoint spawn position.
  • var playerPreset : Resource – The currently selected movement preset applied during play.

Timer

  • var testingTime : float – Tracks total elapsed playtesting time.
  • var timerRunning : bool – Determines whether the gameplay timer should continue updating.

Coins

  • var coinCount : int – Number of collected coins.
  • var totalCoins : int – Total collectible coins present in the level.

Level References

  • var tileMap : TileMapLayer – Reference used to locate enemies and apply their stored properties.

Important Functions

func start() -> void

Initializes the play session by:

  • Resetting timer and coin values.
  • Counting all collectible coins.
  • Finding the newly spawned player.
  • Applying the selected movement preset.
  • Connecting player health signals.
  • Enabling enemies and loading their saved properties.
  • Starting the gameplay timer.
  • Displaying gameplay UI.

func pause() -> void

Toggles between paused and active gameplay by:

  • Updating SceneTree.paused.
  • Swapping gameplay UI with the pause menu.
  • Ignoring pause requests after level completion.

func full_restart() -> void

  • Fully reloads the playable level, run when entering from the MasterManager or when clicking on the restart button
  • Resets the checkpoint

func reset() -> void

Reloads the playable level by:

  • Clearing completion state.
  • Unpausing the scene.
  • Emitting the global reload signal.
  • Reinitializing gameplay through start().

func level_complete() -> void

Handles successful level completion by:

  • Stopping gameplay.
  • Pausing the scene.
  • Displaying the win screen.
  • Showing final coin and time statistics.
  • Hiding gameplay HUD elements.

func replay_level() -> void

Restarts the completed level and begins a new play session.


func return_to_editor() -> void

Leaves play mode and returns to the editor while restoring the editor's validated state.


func update_timer(label)

Formats and displays the elapsed time in MM:SS format.


func update_coin_counter(label)

Updates a UI label with the current collected coin count out of the total available.


func _on_coin_collected()

Responds to the global coin collection signal by increasing the collected coin count and refreshing the UI.


func collect_checkpoint(newSpawn: Vector2)

Responds to the global checkpoint signal by setting a new checkpoint position for the player.


func print_level_completion_time()

Stops the gameplay timer and prints the final completion time for debugging purposes.


Future Work / Risks

Future Work

  • Add support for tracking deaths and attempts during playtesting.
  • Record best completion times and coin collection statistics.
  • Expand health tracking into gameplay UI.
  • Support additional gameplay statistics for validation and analytics.

Risks

  • None so far.

Miscellaneous Notes

  • The Game Manager is the primary coordinator for playtesting mode.
  • Gameplay statistics (coins and timer) are displayed both during gameplay and on the completion screen.
  • Most gameplay events are driven through the project's global signal system rather than direct node references, keeping gameplay systems loosely coupled.# Game Manager

Clone this wiki locally