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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#pragma once
#include "common/math.hpp"
#include <SDL3/SDL.h>
#include <imgui.h>
#include <memory>
#include <vector>
class Game {
public:
enum GameType {
no_game,
minesweeper,
snake,
tetris,
pong
};
enum GameStatus {
game_start,
game_resume,
game_over,
game_pause,
game_exit
};
enum ZLayer {
z_layer1 = 1,
z_layer2,
z_layer3,
z_text
};
using FrameString32 = uint32_t;
static std::unique_ptr<Game> Select(GameType type);
Game() = default;
virtual ~Game() = default;
bool Update(std::vector<SDL_Event>& events);
protected:
GameStatus m_game_status {game_start};
float m_dt_remaining_seconds {0.0f};
uint64_t m_tlast_milliseconds {SDL_GetTicks()};
Color m_clear_color {0.2f, 0.2f, 0.2f, 1.0f};
protected:
virtual void Start() = 0;
virtual void ProcessEvent(SDL_Event& event) = 0;
virtual void FinishUpdate(float dt) = 0;
virtual void Draw() = 0;
virtual void DrawGameStartMenu();
virtual void DrawGameOverMenu();
protected:
static constexpr const char* s_dejavu_sans_filepath = "./fonts/dejavu_ttf/DejaVuSans.ttf";
static constexpr const char* s_dejavu_sans_mono_filepath = "./fonts/dejavu_ttf/DejaVuSansMono.ttf";
static constexpr ImGuiWindowFlags s_imgui_window_flags_menu = ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_AlwaysAutoResize;
static constexpr ImGuiWindowFlags s_imgui_window_flags_default = ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoScrollbar;
private:
void DrawGamePauseMenu();
void ProcessEventDuringPause(SDL_Event& event);
float ProcessDt();
};
|