8using namespace std::string_literals;
11 int exit_key,
bool mouse,
bool audio,
const char *project_name)
12 : stage_width_(stage_width), stage_height_(stage_height), audio_(audio), mouse_(mouse) {
13 SetConfigFlags(window_flags);
14 InitWindow(stage_width, stage_height, project_name);
15 SetWindowMinSize(stage_width / 2, stage_height / 2);
16 SetTargetFPS(target_fps);
21 SetTextureFilter(this->
render_target_.texture, TEXTURE_FILTER_BILINEAR);
36 TraceLog(LOG_INFO,
"game::core::Game destructor called");
45 UnloadRenderTexture(this->render_target_);
56 while (!WindowShouldClose())
59 this->UpdateMousePosition();
66 ClearBackground(BLACK);
69 BeginTextureMode(this->render_target_);
75 this->DrawRenderTexture();
84 Vector2 result = value;
86 result.x = (result.x >
MAX.x) ?
MAX.x : result.x;
87 result.x = (result.x <
MIN.x) ?
MIN.x : result.x;
88 result.y = (result.y >
MAX.y) ?
MAX.y : result.y;
89 result.y = (result.y <
MIN.y) ?
MIN.y : result.y;
96 float scale =
MIN((
float) GetScreenWidth() / this->stage_width_, (
float) GetScreenHeight() / this->stage_height_);
99 Vector2 mouse = GetMousePosition();
100 Store::mouse_position.x = (mouse.x - (
static_cast<float>(GetScreenWidth()) - (
static_cast<float>(this->stage_width_) * scale)) * 0.5f) / scale;
101 Store::mouse_position.y = (mouse.y - (
static_cast<float>(GetScreenHeight()) - (
static_cast<float>(this->stage_height_) * scale)) * 0.5f) / scale;
107 float scale =
MIN((
float) GetScreenWidth() / this->stage_width_, (
float) GetScreenHeight() / this->stage_height_);
110 DrawTexturePro(this->render_target_.texture,
111 {0.0f, 0.0f, static_cast<float>(this->render_target_.texture.width), static_cast<float>(-this->render_target_.texture.height)},
112 {(static_cast<float>(GetScreenWidth()) - (static_cast<float>(this->stage_width_) * scale)) * 0.5f,
113 (static_cast<float>(GetScreenHeight()) - (static_cast<float>(this->stage_height_) * scale)) * 0.5f,
114 static_cast<float>(this->stage_width_) * scale, static_cast<float>(this->stage_height_) * scale},
115 {0.0f, 0.0f}, 0.0f, WHITE
RenderTexture2D render_target_
Temporary render target, which will later be output correctly scaled on the screen.
int stage_width_
Width of the game scene (unscaled). Fixed for the entire run time of the game.
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,...
void Run(const std::string &scene_name, std::unique_ptr< game::core::Scene > scene) const
Starts the first game scene.
void UpdateMousePosition() const
Update virtual mouse position. This becomes necessary because the Raylib function GetMousePosition ca...
void DrawRenderTexture() const
Draws the correctly scaled and, if necessary, letterboxed graphic on the screen.
int stage_height_
Height of the game scene (unscaled). Fixed for the entire run time of the game.
static long long int ticks
Global game counter. Can be used e.g. for the calculation of animation times.
static std::unique_ptr< game::core::Stage > stage
The Stage object is responsible for the scene change and for updating and drawing the scene contents.
static Vector2 mouse_position
The virtual mouse position.