-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tetris.h
67 lines (67 loc) · 2.17 KB
/
Tetris.h
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
#include <SDL2/SDL.h>
#include <array>
#include <cstdint>
#include <vector>
#include <string>
#include "Renderer.h"
#include "Tetromino.h"
#ifndef _TETRIS_H
#define _TETRIS_H
struct Tetris {
static const int32_t TETRIS_PLAYFIELD_WIDTH = 10;
static const int32_t TETRIS_PLAYFIELD_HEIGHT = 20;
std::array<std::array<int32_t, TETRIS_PLAYFIELD_WIDTH>,
TETRIS_PLAYFIELD_HEIGHT>
playfield = {{
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
}};
Renderer renderer{};
std::array<int32_t, 7> sequence;
Tetromino current_tetromino;
const int32_t LINE_CLEAR_LEVELUP_AMOUNT = 10;
const int32_t MAX_LEVELS = 15;
int32_t sequence_index = 0;
int32_t level = 0;
int32_t lines_cleared = 0;
const double ROTATE_SPEED = .15;
const double SOFT_MOVE_SPEED = .15;
const double LOCK_DELAY = .5;
bool left = false;
bool right = false;
bool down = false;
bool up = false;
bool space = false;
void hard_drop();
void rotate();
bool check_left();
bool check_right();
bool check_down();
bool check_collision();
bool check_fill();
void lock();
void check_line_clear();
void generate_sequence();
void text_dump(const std::string& msg) const;
void loop();
Tetris();
};
#endif