forked from slawa19/IKEA-LED-Table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtetrisCommon.ino
107 lines (100 loc) · 2.08 KB
/
tetrisCommon.ino
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
/* LedTable
*
* Written by: Klaas De Craemer, Ing. David Hrbaty
*
* Common code and defines for the Tetris game
*/
//Maximum size of bricks. Individual bricks can still be smaller (eg 3x3)
#define MAX_BRICK_SIZE 4
#define BRICKOFFSET -1 // Y offset for new bricks
#define INIT_SPEED 1000//Initial delay in ms between brick drops
#define SPEED_STEP 100 // Factor for speed increase between levels, default 10
#define LEVELUP 2 //Number of rows before levelup, default 5
// Playing field
struct Field{
uint8_t pix[FIELD_WIDTH][FIELD_HEIGHT+1];//Make field one larger so that collision detection with bottom of field can be done in a uniform way
unsigned int color[FIELD_WIDTH][FIELD_HEIGHT];
};
Field field;
//Structure to represent active brick on screen
struct Brick{
boolean enabled;//Brick is disabled when it has landed
int xpos,ypos;
int yOffset;//Y-offset to use when placing brick at top of field
uint8_t siz;
uint8_t pix[MAX_BRICK_SIZE][MAX_BRICK_SIZE];
unsigned int color;
};
Brick activeBrick;
//Struct to contain the different choices of blocks
struct AbstractBrick{
int yOffset;//Y-offset to use when placing brick at top of field
uint8_t siz;
uint8_t pix[MAX_BRICK_SIZE][MAX_BRICK_SIZE];
};
//Brick "library"
AbstractBrick brickLib[7] = {
{
1,//yoffset when adding brick to field
4,
{ {0,0,0,0},
{0,1,1,0},
{0,1,1,0},
{0,0,0,0}
}
},
{
0,
4,
{ {0,1,0,0},
{0,1,0,0},
{0,1,0,0},
{0,1,0,0}
}
},
{
1,
3,
{ {0,0,0,0},
{1,1,1,0},
{0,0,1,0},
{0,0,0,0}
}
},
{
1,
3,
{ {0,0,1,0},
{1,1,1,0},
{0,0,0,0},
{0,0,0,0}
}
},
{
1,
3,
{ {0,0,0,0},
{1,1,1,0},
{0,1,0,0},
{0,0,0,0}
}
},
{
1,
3,
{ {0,1,1,0},
{1,1,0,0},
{0,0,0,0},
{0,0,0,0}
}
},
{
1,
3,
{ {1,1,0,0},
{0,1,1,0},
{0,0,0,0},
{0,0,0,0}
}
}
};