-
Notifications
You must be signed in to change notification settings - Fork 0
/
tetris.h
85 lines (74 loc) · 1.36 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
#ifndef __TETRIS_H__
#define __TETRIS_H__
#include "display.h"
#include "keyboard.h"
const int8_t tetrominoes[5][2][4] = {
{
{1,1,1,1},
{0,0,0,0}
},
{
{1,0,0,0},
{1,1,1,0}
},
{
{1,1,0,0},
{1,1,0,0},
},
{
{0,1,1,0},
{1,1,0,0}
},
{
{0,1,0,0},
{1,1,1,0}
}
};
const int8_t matricies[4][3][3]={
{
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
},
{
{0,-1,2},
{1,0,0},
{0,0,1},
},
{
{-1,0,2 },
{0,-1,2},
{0,0,1}
},
{
{0,1,0},
{-1,0,2},
{0,0,1}
},
};
class Tetris
{
private:
Display *display;
Keyboard *keyboard;
int figure = -1;
int x = 5;
int y = 0;
int rotate = 0;
unsigned long ts = millis();
unsigned long prev_turn;
unsigned long speed_ = 5000;
int next_tetromino();
void put_on_board();
void delete_from_board();
void check_lines();
void check_line(int y0);
void traverse_tetronomino(void (*callback)(int,int, void*), void *arg);
bool check_place(int x, int y, int rotate);
void put_on_board( boolean val);
void game_over();
public:
Tetris(Display *display, Keyboard *keyboard);
void turn();
};
#endif