-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.cpp
More file actions
executable file
·58 lines (51 loc) · 1.17 KB
/
Copy pathapp.cpp
File metadata and controls
executable file
·58 lines (51 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Created by polarnik on 13.10.2024.
//
#include "app.h"
#include <stdexcept>
#include "constants.h"
#include "States/main_screen.h"
void App::Init() {
window_.Init(BreakClone::kDefaultWindowWidth,
BreakClone::kDefaultWindowHeight,
"Breakout");
try {
game_state_ = std::make_unique<MainScreen>(this);
} catch (const std::exception& e) {
throw std::runtime_error("Failed to initialize game state");
}
}
void App::Run() {
if (!game_state_) {
throw std::runtime_error("Game state not initialized");
}
while (!window_.ShouldClose()) {
HandleInput();
Logic();
Render();
}
window_.Close();
}
void App::Logic() {
if (game_state_) {
game_state_->Logic();
}
}
void App::Render() {
BeginDrawing();
if (game_state_) {
game_state_->Render();
}
EndDrawing();
}
void App::HandleInput() {
if (game_state_) {
game_state_->HandleInput();
}
}
void App::ChangeState(std::unique_ptr<GameState> state) {
if (!state) {
throw std::invalid_argument("New game state cannot be null");
}
game_state_ = std::move(state);
}