blob: 1c60a98605e470dd86f8fa956bd4a810308fe75d (
plain)
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
|
#pragma once
#include <common/defs.hpp>
#include <games/Game.hpp>
#include <games/tetris/Tetromino.hpp>
#include <games/tetris/Board.hpp>
#include <common/Font.hpp>
#include <common/Arena.hpp>
class Tetris : public Game {
public:
Tetris();
bool Update(std::vector<SDL_Event>& events) override;
private:
void Start();
void UpdateResumeState(SDL_Event& event);
void UpdatePauseState(SDL_Event& event);
uint32_t GetSoftdropCount(float dt);
void HandleTetrominoPlacement();
int32_t ReadHighscore();
void WriteHighscore();
void Draw();
void DrawLineCounter();
void DrawStatistics();
void DrawScore();
void DrawNextTetromino();
void DrawLevel();
void DrawGameOverMenu();
private:
static constexpr Color s_text_color {0.9f, 0.9f, 0.9f, 1.0f};
static constexpr float s_text_z {10.0f};
static constexpr size_t s_frame_strings_capacity {32};
static constexpr char s_tetris_highscore_path[]{"tetris_highscore.txt"};
Font m_font;
Board m_board;
Tetromino m_active_tetromino;
Tetromino::Id m_next_tetromino_id;
int32_t m_tetromino_counters[Tetromino::id_count] {};
int32_t m_score = 0;
int32_t m_line_counter = 0;
int32_t m_starting_level = 0;
int32_t m_level = 0;
int32_t m_softdrop_counter = 0;
int32_t m_highscore = 0;
Arena m_frame_arena {KIBIBYTES(2)};
};
|