The Game logic - SC-SGS/surviving-sarntal GitHub Wiki

This page aims to explain the core functionality of the game.

Goal of the game

The aim of the game is to achieve the highest possible score by surviving as long as possible in the Sarntal.

The game loop

The game loop is the central control unit of our program. It contains all the logic needed to run the actual gameplay. It can be found in the class Game and runs as long as the window is open and the Hiker is still alive.

The game loop is structured into three phases:

  1. handling and processing the input from the player (handled in InputHandler.cpp and EventProcessor.cpp) (detailed information on how the input is handled)
  2. processing the queued events -> adapting the game state and game entities based on the player's input and in-game dynamics (handled in PhysicsEngine.cpp) (detailed information on how the physics engine is composed)
  3. rendering the game/ drawing the current game state on the screen (processed in Render.cpp) (Renderer)

gameLoop

At the start of the game loop, input from the player, be it via keyboard or gamepad, is registered and passed to the physics engine. The physics engine progresses the simulation in one or more constant time steps between frames, thereby processing the collected input events. Finally, the renderer draws the new frame representing the updated world state.

Due to the sequential nature of input receipt, input processing, simulating a physics step, and rendering the resulting new state of the world, the game loop is also inherently sequential. For very large games or powerful frameworks such as the aforementioned Unity framework, a parallelisation becomes inevitable, but in our game, this structure suffices. Merely the terrain generation is extracted from the spawning phase of the physics engine in order to guarantee a smooth transition between biomes during gameplay.

End of the game

As soon as the hiker gets killed (zero health points or falls behind the kill bar), an end screen is displayed.

⚠️ **GitHub.com Fallback** ⚠️