-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtetris.h
169 lines (140 loc) · 2.73 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef TETRIS_H
#define TETRIS_H
#include "screen.h"
#include "rng.h"
#include "time.h"
#include "blocks.h"
#include "input.h"
#include "text.h"
///// TYPES & CONSTANTS /////
#define LEVEL_MAX 20
typedef UINT8 tile;
typedef struct game_state {
/**
* \brief
* The framebuffer to draw the game in.
*/
LFB * const lfb;
/**
* \brief
* The random number generator used to get new tetrominos.
*/
RNG * const rng;
/**
* \brief
* Service to read keystrokes.
*/
input_manager_t * const input_manager;
/**
* \brief
* The timer used to pause between frames.
*/
timer timer;
/**
* \brief
* A reference to the next tetromino that the player will get.
*/
tetromino_template const * next_tetromino;
/**
* \brief
* The tetromino that the player is controlling.
*/
tetromino current_tetromino;
/**
* \brief
* The grid of tiles that are frozen.
*/
tile grid[GRID_HEIGHT * GRID_WIDTH];
/**
* \brief
* Number of frames that have elapsed.
*/
UINT32 frame_number;
/**
* \brief
* The absolute position in pixels where the grid begins on screen.
*/
vec2 const grid_origin;
/**
* \brief
* The size of the grid in tiles.
*/
vec2 const grid_size;
/**
* \brief
* The size of a tile in pixels.
*/
vec2 const tile_size;
/**
* \brief
* The frame number when the last tick occurred.
*/
UINT32 last_tick;
/**
* \brief
* The number of rows eliminated by the player.
*/
UINT32 eliminated_rows;
/**
* \brief
* Player score.
*/
UINT32 score;
/**
* \brief
* Score values to add for different numbers of lines cleared.
*/
score_delta const score_table[5];
/**
* \brief
* The current level.
* This is an index into the `levels` array.
*/
UINT8 level;
/**
* \brief
* This is all the difficulty levels, expressed as tick periods.
*/
UINT8 const levels[LEVEL_MAX];
/**
* \brief
* Settings for rendering text.
*/
bt_renderer_info const renderer_info;
} game_state;
/**
* \brief
* Indicates that the grid tile is empty.
*/
extern tile const EMPTY, NONEMPTY;
/**
* \brief
* The color for "dead" tiles in the grid.
*/
extern bgr const DEAD_COLOR;
/**
* \brief
* The color for components of active tetrominoes.
*/
extern bgr const TETRO_COLOR;
///// FUNCTIONS /////
/**
* \brief
* Constructs an initial state for the game.
*
* Returns whether the initialization succeeded in the out-parameter
* `ok`. The return value is undefined if `*ok` isn't true.
*/
game_state
make_initial_state(
int * const ok,
LFB * const lfb,
RNG * const rng,
input_manager_t * const input_manager);
/**
* \brief
* Runs the game loop.
*/
int
game(game_state * const s);
#endif