Small block game in C
Commit 6ba226e1f90b
tarball3 files changed+43-30
@@ -52,8 +52,6 @@ int main () {
5252
5353
bool paused = false;5454
55
- uint64_t paused_diff;56
-5755
piece current_piece = {};5856
piece next_piece = init_piece((rand() % Z_PIECE) + 1);5957
@@ -68,9 +66,9 @@ int main () {
6866
uint16_t tick_fall = 0;6967
uint16_t tick_blink = 0;7068
uint16_t tick_spin = 0;69
+ uint16_t tick_gray = 0;7170
72
-73
- uint8_t i, j;71
+ uint8_t i;7472
bool is_tetris = false;7573
7674
/* Game Loop */@@ -114,8 +112,8 @@ int main () {
114112
start = current;115113
}116114
117
- /* Take care of the input */118115
116
+ /* Take care of the input */119117
120118
if (is_poll > 0 && polling[0].revents & POLLIN) {121119
@@ -165,6 +163,13 @@ int main () {
165163
}166164
167165
166
+ if (paused)167
+ continue;168
+169
+170
+171
+ /* Dealing with cleared Lines */172
+168173
if (is_tetris) {169174
170175
tick_blink += ticks;@@ -173,7 +178,7 @@ int main () {
173178
174179
tick_blink -= BLINK;175180
176
- draw_board(current_piece, next_piece, (i % 2 == 0) ? NULL : blink, is_piece);181
+ draw_board(current_piece, next_piece, (i % 2 == 0) ? blink : NULL, is_piece);177182
i++;178183
}179184
@@ -205,13 +210,9 @@ int main () {
205210
}206211
207212
208
- if (paused)209
- continue;210
-211213
212214
/* Creates new piece */213215
214
- 215216
if (!is_piece) {216217
current_piece = next_piece;217218
next_piece = init_piece((rand() % Z_PIECE) + 1);@@ -242,8 +243,9 @@ int main () {
242243
243244
244245
/* Piece rotates */245
- 246
- tick_spin += ticks;246
+247
+ if (tick_spin < SPIN)248
+ tick_spin += ticks;247249
248250
if (rotate && current_piece.positions > 1 && tick_spin >= SPIN) {249251
@@ -268,23 +270,6 @@ int main () {
268270
current_piece.y++;269271
270272
271
- uint8_t j, k;272
-273
- for (j = 0; j < FULL_HEIGHT; j++) {274
- for (k = 0; k < FULL_WIDTH; k++) {275
- if (playfield[j][k] != EMPTY) {276
- 277
- if (graying[j][k] < 255) {278
- graying[j][k] += 1;279
- }280
-281
- } else {282
- graying[j][k] = 0;283
- }284
-285
- }286
- }287
-288273
if (tick_fall >= FALL)289274
tick_fall -= FALL;290275
@@ -353,6 +338,33 @@ int main () {
353338
}354339
}355340
341
+ /* Graying out of old pieces */342
+343
+ tick_gray += ticks;344
+345
+ while (tick_gray >= GRAY){346
+ 347
+348
+ uint8_t j, k;349
+350
+ for (j = 0; j < FULL_HEIGHT; j++) {351
+ for (k = 0; k < FULL_WIDTH; k++) {352
+ if (playfield[j][k] != EMPTY) {353
+ 354
+ if (graying[j][k] < 255) {355
+ graying[j][k] += 1;356
+ }357
+358
+ } else {359
+ graying[j][k] = 0;360
+ }361
+362
+ }363
+ }364
+365
+ tick_gray -= GRAY;366
+ }367
+356368
357369
if (draw)358370
draw_board(current_piece, next_piece, NULL, is_piece);@@ -33,7 +33,8 @@
3333
3434
#define FALL 583535
#define BLINK 1236
-#define SPIN 536
+#define SPIN 837
+#define GRAY 103738
3839
3940
typedef enum {Binary file not shown.