Repository navigation
Expand file tree
/
Copy pathtk_tetrominoes.ino
More file actions
99 lines (78 loc) · 1.41 KB
/
Copy pathtk_tetrominoes.ino
File metadata and controls
99 lines (78 loc) · 1.41 KB
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
/**
* randomly get a new tetromino
*/
void get_next_tetromino() {
// of course not every tetromino has the same probability being the next one
switch ( random(17) ) {
case 0:
next_tetr_type = 0;
break;
case 1:
case 2:
case 3:
next_tetr_type = 1;
break;
case 4:
case 5:
case 6:
next_tetr_type = 2;
break;
case 7:
case 8:
case 9:
next_tetr_type = 3;
break;
case 10:
case 11:
case 12:
next_tetr_type = 4;
break;
case 13:
case 14:
case 15:
next_tetr_type = 5;
break;
default:
next_tetr_type = 6;
break;
}
}
/**
* throws a tetromino in the bucket
*/
void drop_tetromino() {
// reset positions
tetr_col = 4;
tetr_row = 1;
tetr_rotation = 0;
}
/**
* tetromino movements
*/
bool rotate_tetromino() {
if ( check_collision(ROTATE) )
return false;
tetr_rotation++;
tetr_rotation %= 4;
return true;
}
bool move_tetromino_left() {
if ( check_collision(LEFT) )
return false;
tetr_col--;
return true;
}
bool move_tetromino_right() {
if ( check_collision(RIGHT) )
return false;
tetr_col++;
return true;
}
bool move_tetromino_down() {
if ( check_collision(FALL) ) {
handle_next();
return false;
}
tetr_row++;
return true;
}