raylibstarter 0.1.0
game::core::Game Class Referencefinal

The entry point into the game. The constructor is used to specify the basic settings such as the size of the drawing area in pixels. Finally, a first game scene can be started via the Run() method. More...

#include <game.h>

Collaboration diagram for game::core::Game:

Public Member Functions

 Game ()=delete
 
 Game (int stage_width, int stage_height, bool full_screen, int target_fps, int window_flags, int exit_key, bool mouse, bool audio, const char *project_name)
 Constructor. More...
 
 Game (const game::core::Game &game)=delete
 
Gameoperator= (const Game &)=delete
 
 ~Game ()
 
void Run (const std::string &scene_name, std::unique_ptr< game::core::Scene > scene) const
 Starts the first game scene. More...
 

Private Member Functions

void UpdateMousePosition () const
 Update virtual mouse position. This becomes necessary because the Raylib function GetMousePosition can no longer work correctly due to the scaling of the graphics output. More...
 
void DrawRenderTexture () const
 Draws the correctly scaled and, if necessary, letterboxed graphic on the screen. More...
 

Static Private Member Functions

static Vector2 ClampValue (Vector2 value, Vector2 MIN, Vector2 MAX)
 Clamp Vector2 value with MIN and MAX and return a new vector2. Required for virtual mouse, to clamp inside virtual game size. More...
 

Private Attributes

int stage_width_
 Width of the game scene (unscaled). Fixed for the entire run time of the game. More...
 
int stage_height_
 Height of the game scene (unscaled). Fixed for the entire run time of the game. More...
 
bool audio_
 Defines whether the audio device is initialized. More...
 
bool mouse_
 Defines if the mouse support should be activated. More...
 
RenderTexture2D render_target_ = { }
 Temporary render target, which will later be output correctly scaled on the screen. More...
 

Detailed Description

The entry point into the game. The constructor is used to specify the basic settings such as the size of the drawing area in pixels. Finally, a first game scene can be started via the Run() method.

Definition at line 15 of file game.h.

Constructor & Destructor Documentation

◆ Game() [1/3]

game::core::Game::Game ( )
delete

◆ Game() [2/3]

game::core::Game::Game ( int  stage_width,
int  stage_height,
bool  full_screen,
int  target_fps,
int  window_flags,
int  exit_key,
bool  mouse,
bool  audio,
const char *  project_name 
)

Constructor.

Create a new Game instance

Parameters
stage_widthWidth of the game scene (unscaled). Fixed for the entire run time of the game.
stage_heightHeight of the game scene (unscaled). Fixed for the entire run time of the game.
full_screenStart in full screen or window mode.
target_fpsTarget fps, usually 60 fps.
window_flagsRaylib window flags, preffered: GAME_CONFIG_FLAGS FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT | FLAG_MSAA_4X_HINT
exit_keyGame exit key. E.g. KEY_ESCAPE. Set it to KEY_NULL if the game app should not stop directly by pressing a key.
mouseIf true, the mouse position is available in game::core::Store::mouse_position. Please do not use the Raylib function GetMousePosition() which will not wok because of the scaling and letterboxing system.
audioIf true, Raylib will initialize the audio device.
project_nameProject name to be displayed as window title in Window mode.

Definition at line 10 of file game.cpp.

◆ Game() [3/3]

game::core::Game::Game ( const game::core::Game game)
delete

◆ ~Game()

game::core::Game::~Game ( )

Definition at line 35 of file game.cpp.

Member Function Documentation

◆ ClampValue()

Vector2 game::core::Game::ClampValue ( Vector2  value,
Vector2  MIN,
Vector2  MAX 
)
staticprivate

Clamp Vector2 value with MIN and MAX and return a new vector2. Required for virtual mouse, to clamp inside virtual game size.

Definition at line 83 of file game.cpp.

◆ DrawRenderTexture()

void game::core::Game::DrawRenderTexture ( ) const
private

Draws the correctly scaled and, if necessary, letterboxed graphic on the screen.

Definition at line 105 of file game.cpp.

◆ operator=()

Game & game::core::Game::operator= ( const Game )
delete

◆ Run()

void game::core::Game::Run ( const std::string &  scene_name,
std::unique_ptr< game::core::Scene scene 
) const

Starts the first game scene.

The method creates the main stage object of the game, which is accessible under game::core::Store::stage and transfers the scene object to the stage.

The method also implements the main game loop. In this, the contents of the current game scene are drawn via the stage object game::core::Store::stage.

Furthermore, the method increments the global game counter game::core::Store::ticks and updates the mouse pointer coordinates in game::core::Store::mouse_position if mouse support was enabled when instantiating the game object.

The method is also responsible for correctly scaling the displayed scene and inserting letterboxes if necessary to preserve the aspect ratio.

Definition at line 51 of file game.cpp.

◆ UpdateMousePosition()

void game::core::Game::UpdateMousePosition ( ) const
private

Update virtual mouse position. This becomes necessary because the Raylib function GetMousePosition can no longer work correctly due to the scaling of the graphics output.

Definition at line 94 of file game.cpp.

Member Data Documentation

◆ audio_

bool game::core::Game::audio_
private

Defines whether the audio device is initialized.

Definition at line 65 of file game.h.

◆ mouse_

bool game::core::Game::mouse_
private

Defines if the mouse support should be activated.

Definition at line 67 of file game.h.

◆ render_target_

RenderTexture2D game::core::Game::render_target_ = { }
private

Temporary render target, which will later be output correctly scaled on the screen.

Definition at line 70 of file game.h.

◆ stage_height_

int game::core::Game::stage_height_
private

Height of the game scene (unscaled). Fixed for the entire run time of the game.

Definition at line 63 of file game.h.

◆ stage_width_

int game::core::Game::stage_width_
private

Width of the game scene (unscaled). Fixed for the entire run time of the game.

Definition at line 61 of file game.h.


The documentation for this class was generated from the following files: