-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.h
65 lines (59 loc) · 1.5 KB
/
game.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
/* General Settings */
#define NUM_PIECES 7 // number of pieces
#define NUM_BLOCKS 4 // number of blocks in a piece
#define NUM_ROTATIONS 4 // number of rotations per piece
#define BOARD_WIDTH 10 // number of tiles wide
#define BOARD_HEIGHT 20 // number of tiles high
#define START_ROW 0
#define START_COL 60
#define PREV_ROW 20
#define PREV_COL 0
#define PPI 8 // "pixels per inch"
#define EMPTY_CELL 0
#define INIT_SPEED 30
/* Tetromino Piece Definitions */
#define TETROMINO_I 0
#define TETROMINO_L 1
#define TETROMINO_J 2
#define TETROMINO_O 3
#define TETROMINO_S 4
#define TETROMINO_T 5
#define TETROMINO_Z 6
/* Game states */
#define TITLE 0
#define NORMAL 1
#define GAMEOVER 2
/* Struture representing a tetromino */
typedef struct {
/**
* X goes left to right.
* Y goes top to bottom.
* The size of the array is 4x4, specified in the NUM_BLOCKS constant.
*/
u16 color;
int cells[NUM_BLOCKS][NUM_BLOCKS];
int rotation;
int x;
int y;
int size;
int type;
} TETROMINO;
/* External variables */
extern int state;
extern const int PIECES[NUM_PIECES][NUM_ROTATIONS][NUM_BLOCKS][2];
extern u16 board[BOARD_HEIGHT][BOARD_WIDTH];
extern TETROMINO nextBlock;
extern TETROMINO currentBlock;
void refresh();
void reset();
void startGame();
void endGame();
void setBlock(int type, TETROMINO *block, int rotation);
void moveBlock(int dx, int dy);
void drawBlock();
void drawPreview();
void blockMoved();
void redraw(int r, int c);
TETROMINO makeBlock();
void rotateBlock(int clockwise);
int collides(TETROMINO newBlock);