Repository navigation
Expand file tree
/
Copy pathr_tetris_draw.ino
More file actions
233 lines (207 loc) · 9.42 KB
/
Copy pathr_tetris_draw.ino
File metadata and controls
233 lines (207 loc) · 9.42 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// --------------------- Tetris objects ---------------------------
// The coordinate system is based on the game that used an LED matrix.
// Top left is (0,0) and scale of the objects matches this screen's draw space of 2500 square.
// If not, it's all parameterized below for ease of changes.
// The bucket is an array of bits, each word is one row of the bucket.
// The col (bit) number is 1 left wall, 2..11 contents, 12 right wall.
// bits 0 and 13 are outside borders so that the drawing edge detector can see the bucket walls.
// The array index is 0 empty top row, 17 bottom.
const int top_pos = 1000;
const int left_pos = -800;
const int bo = 6; // border inset from edge of char
const int tx = 100; // width of a cell
const int ty = 100; // height of a cell
// These are the tetronimo draw lists in order that the code identifies them.
// We don't need to define the duplicates, they're used by reference in the lookup table.
const int tetronI02[] =
{
lin, 0*tx+bo, 0*ty-bo, 4*tx-bo, 0*ty-bo, 0,0, // horizontal bar 1 below
lin, 4*tx-bo, 0*ty-bo, 4*tx-bo, -1*ty+bo, 0,0,
lin, 4*tx-bo, -1*ty+bo, 0*tx+bo, -1*ty+bo, 0,0,
lin, 0*tx+bo, -1*ty+bo, 0*tx+bo, 0*ty-bo, 0,0, 0x80
};
const int tetronI13[] =
{ lin, 2*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // vertical bar 2 right
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, -3*ty+bo, 0,0,
lin, 3*tx-bo, -3*ty+bo, 2*tx+bo, -3*ty+bo, 0,0,
lin, 2*tx+bo, -3*ty+bo, 2*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronO[] =
{ lin, 1*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // square top middle
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, -1*ty+bo, 0,0,
lin, 3*tx-bo, -1*ty+bo, 1*tx+bo, -1*ty+bo, 0,0,
lin, 1*tx+bo, -1*ty+bo, 1*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronZ02[] =
{ lin, 0*tx+bo, 1*ty-bo, 2*tx-bo, 1*ty-bo, 0,0, // z horizontal
lin, 2*tx-bo, 1*ty-bo, 2*tx-bo, 0*ty-bo, 0,0,
lin, 2*tx-bo, 0*ty-bo, 3*tx-bo, 0*ty-bo, 0,0,
lin, 3*tx-bo, 0*ty-bo, 3*tx-bo, -1*ty+bo, 0,0,
lin, 3*tx-bo, -1*ty+bo, 1*tx+bo, -1*ty+bo, 0,0,
lin, 1*tx+bo, -1*ty+bo, 1*tx+bo, 0*ty+bo, 0,0,
lin, 1*tx+bo, 0*ty+bo, 0*tx+bo, 0*ty+bo, 0,0,
lin, 0*tx+bo, 0*ty+bo, 0*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronZ13[] =
{ lin, 2*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // z vertical
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, -1*ty+bo, 0,0,
lin, 3*tx-bo, -1*ty+bo, 2*tx-bo, -1*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 lin, 2*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // L pointing left
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, -1*ty+bo, 0,0,
lin, 3*tx-bo, -1*ty+bo, 0*tx+bo, -1*ty+bo, 0,0,
lin, 0*tx+bo, -1*ty+bo, 0*tx+bo, 0*ty-bo, 0,0,
lin, 0*tx+bo, 0*ty-bo, 2*tx+bo, 0*ty-bo, 0,0,
lin, 2*tx+bo, 0*ty-bo, 2*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronL1[] =
{ lin, 1*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // L pointing down
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, -2*ty+bo, 0,0,
lin, 3*tx-bo, -2*ty+bo, 2*tx+bo, -2*ty+bo, 0,0,
lin, 2*tx+bo, -2*ty+bo, 2*tx+bo, 0*ty+bo, 0,0,
lin, 2*tx+bo, 0*ty+bo, 1*tx+bo, 0*ty+bo, 0,0,
lin, 1*tx+bo, 0*ty+bo, 1*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronL2[] =
{ lin, 0*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // L pointing right
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, 0*ty+bo, 0,0,
lin, 3*tx-bo, 0*ty+bo, 1*tx-bo, 0*ty+bo, 0,0,
lin, 1*tx-bo, 0*ty+bo, 1*tx-bo, -1*ty+bo, 0,0,
lin, 1*tx-bo, -1*ty+bo, 0*tx+bo, -1*ty+bo, 0,0,
lin, 0*tx+bo, -1*ty+bo, 0*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronL3[] =
{ lin, 1*tx+bo, 1*ty-bo, 2*tx-bo, 1*ty-bo, 0,0, // L pointing up
lin, 2*tx-bo, 1*ty-bo, 2*tx-bo, -1*ty-bo, 0,0,
lin, 2*tx-bo, -1*ty-bo, 3*tx-bo, -1*ty-bo, 0,0,
lin, 3*tx-bo, -1*ty-bo, 3*tx-bo, -2*ty+bo, 0,0,
lin, 3*tx-bo, -2*ty+bo, 1*tx+bo, -2*ty+bo, 0,0,
lin, 1*tx+bo, -2*ty+bo, 1*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronG0[] =
{ lin, 1*tx+bo, 1*ty-bo, 2*tx-bo, 1*ty-bo, 0,0, // backwards L pointing right
lin, 2*tx-bo, 1*ty-bo, 2*tx-bo, 0*ty-bo, 0,0,
lin, 2*tx-bo, 0*ty-bo, 4*tx-bo, 0*ty-bo, 0,0,
lin, 4*tx-bo, 0*ty-bo, 4*tx-bo, -1*ty+bo, 0,0,
lin, 4*tx-bo, -1*ty+bo, 1*tx+bo, -1*ty+bo, 0,0,
lin, 1*tx+bo, -1*ty+bo, 1*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronG1[] =
{ lin, 2*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // backwards L pointing up
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, -2*ty+bo, 0,0,
lin, 3*tx-bo, -2*ty+bo, 1*tx+bo, -2*ty+bo, 0,0,
lin, 1*tx+bo, -2*ty+bo, 1*tx+bo, -1*ty-bo, 0,0,
lin, 1*tx+bo, -1*ty-bo, 2*tx+bo, -1*ty-bo, 0,0,
lin, 2*tx+bo, -1*ty-bo, 2*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronG2[] =
{ lin, 1*tx+bo, 1*ty-bo, 4*tx-bo, 1*ty-bo, 0,0, // backwards L pointing left
lin, 4*tx-bo, 1*ty-bo, 4*tx-bo, -1*ty+bo, 0,0,
lin, 4*tx-bo, -1*ty+bo, 3*tx+bo, -1*ty+bo, 0,0,
lin, 3*tx+bo, -1*ty+bo, 3*tx+bo, 0*ty+bo, 0,0,
lin, 3*tx+bo, 0*ty+bo, 1*tx+bo, 0*ty+bo, 0,0,
lin, 1*tx+bo, 0*ty+bo, 1*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronG3[] =
{ lin, 1*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // backwards L pointing down
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, 0*ty+bo, 0,0,
lin, 3*tx-bo, 0*ty+bo, 2*tx-bo, 0*ty+bo, 0,0,
lin, 2*tx-bo, 0*ty+bo, 2*tx-bo, -2*ty+bo, 0,0,
lin, 2*tx-bo, -2*ty+bo, 1*tx+bo, -2*ty+bo, 0,0,
lin, 1*tx+bo, -2*ty+bo, 1*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronT0[] =
{ lin, 2*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // T pointing up
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, 0*ty-bo, 0,0,
lin, 3*tx-bo, 0*ty-bo, 4*tx-bo, 0*ty-bo, 0,0,
lin, 4*tx-bo, 0*ty-bo, 4*tx-bo, -1*ty+bo, 0,0,
lin, 4*tx-bo, -1*ty+bo, 1*tx+bo, -1*ty+bo, 0,0,
lin, 1*tx+bo, -1*ty+bo, 1*tx+bo, 0*ty-bo, 0,0,
lin, 1*tx+bo, 0*ty-bo, 2*tx+bo, 0*ty-bo, 0,0,
lin, 2*tx+bo, 0*ty-bo, 2*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronT1[] =
{ lin, 2*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // T pointing left
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, -2*ty+bo, 0,0,
lin, 3*tx-bo, -2*ty+bo, 2*tx+bo, -2*ty+bo, 0,0,
lin, 2*tx+bo, -2*ty+bo, 2*tx+bo, -1*ty+bo, 0,0,
lin, 2*tx+bo, -1*ty+bo, 1*tx+bo, -1*ty+bo, 0,0,
lin, 1*tx+bo, -1*ty+bo, 1*tx+bo, 0*ty-bo, 0,0,
lin, 1*tx+bo, 0*ty-bo, 2*tx+bo, 0*ty-bo, 0,0,
lin, 2*tx+bo, 0*ty-bo, 2*tx+bo, 1*ty-bo, 0,0, 0x80
};
const int tetronT2[] =
{
lin, 1*tx+bo, 0*ty-bo, 4*tx-bo, 0*ty-bo, 0,0, // T pointing down
lin, 4*tx-bo, 0*ty-bo, 4*tx-bo, -1*ty+bo, 0,0,
lin, 4*tx-bo, -1*ty+bo, 3*tx-bo, -1*ty+bo, 0,0,
lin, 3*tx-bo, -1*ty+bo, 3*tx-bo, -2*ty+bo, 0,0,
lin, 3*tx-bo, -2*ty+bo, 2*tx+bo, -2*ty+bo, 0,0,
lin, 2*tx+bo, -2*ty+bo, 2*tx+bo, -1*ty+bo, 0,0,
lin, 2*tx+bo, -1*ty+bo, 1*tx+bo, -1*ty+bo, 0,0,
lin, 1*tx+bo, -1*ty+bo, 1*tx+bo, 0*ty-bo, 0,0, 0x80
};
const int tetronT3[] =
{
lin, 2*tx+bo, 1*ty-bo, 3*tx-bo, 1*ty-bo, 0,0, // T pointing right
lin, 3*tx-bo, 1*ty-bo, 3*tx-bo, 0*ty-bo, 0,0,
lin, 3*tx-bo, 0*ty-bo, 4*tx-bo, 0*ty-bo, 0,0,
lin, 4*tx-bo, 0*ty-bo, 4*tx-bo, -1*ty+bo, 0,0,
lin, 4*tx-bo, -1*ty+bo, 3*tx-bo, -1*ty+bo, 0,0,
lin, 3*tx-bo, -1*ty+bo, 3*tx-bo, -2*ty+bo, 0,0,
lin, 3*tx-bo, -2*ty+bo, 2*tx+bo, -2*ty+bo, 0,0,
lin, 2*tx+bo, -2*ty+bo, 2*tx+bo, 1*ty-bo, 0,0, 0x80
};
// an array of pointers to the draw lists above
// sorted by [type][rot]
const int * tetronimoList[7][4] =
{
{tetronI02, tetronI13, tetronI02, tetronI13},
{tetronO, tetronO, tetronO, tetronO},
{tetronZ02, tetronZ13, tetronZ02, tetronZ13},
{tetronS02, tetronS13, tetronS02, tetronS13},
{tetronL0, tetronL1, tetronL2, tetronL3},
{tetronG0, tetronG1, tetronG2, tetronG3},
{tetronT0, tetronT1, tetronT2, tetronT3}
};
// DispBlock displays one block of type with rotation rot
// at col, row (upper left corner, units of blocks)
void DispBlock(int type, int rot, int col, int row)
{
int notLast;
ChrXPos = col * tx + left_pos; // transform coordinates from game to screen
ChrYPos = top_pos - row * ty;
TheSeg = tetronimoList[type][rot]; // look up what to draw
notLast = GetSeg(); // get the first segment to draw
while (notLast)
{
DoSeg(); // display segments until last one found
notLast = GetSeg();
}
}