diff options
| -rw-r--r-- | cetris.c | 25 | ||||
| -rw-r--r-- | cetris.h | 2 | ||||
| -rw-r--r-- | ncurses_ui.c | 15 |
3 files changed, 27 insertions, 15 deletions
@@ -297,28 +297,33 @@ void set_constants(struct cetris_game* g) { }
}
+void reset_slot(slot* s) {
+ s->occupied = 0;
+ s->constant = 0;
+ s->remove_tick = 0;
+}
+
void wipe_board(struct cetris_game* g) {
int lines_cleared = 0;
for (int y = 0; y < BOARD_Y; y++) {
int clear_line = 1;
for (int x = 0; x < BOARD_X; x++) {
- if (!g->board[x][y].constant) g->board[x][y].occupied = 0;
- if (!g->board[x][y].occupied) clear_line = 0;
+ if (!g->board[x][y].constant) reset_slot(&g->board[x][y]);
+ if (g->board[x][y].remove_tick && g->board[x][y].remove_tick <= g->tick) {
+ reset_slot(&g->board[x][y]);
+ for (int s = y - 1; s >= 0; s--) {
+ g->board[x][s + 1] = g->board[x][s];
+ }
+ }
+ if (!g->board[x][y].occupied || g->board[x][y].remove_tick > 0) clear_line = 0;
}
if (clear_line) {
lines_cleared++;
for (int x = 0; x < BOARD_X; x++) {
- g->board[x][y].occupied = 0;
- g->board[x][y].constant = 0;
- }
-
- for (int s = y - 1; s >= 0; s--) {
- for (int x = 0; x < BOARD_X; x++) {
- g->board[x][s + 1] = g->board[x][s];
- }
+ g->board[x][y].remove_tick = g->tick + CETRIS_LINE_CLEAR_DELAY;
}
}
}
@@ -4,6 +4,7 @@ #define CETRIS_HZ 60
#define CETRIS_DAS_DELAY 11
#define CETRIS_DAS_PERIOD 5
+#define CETRIS_LINE_CLEAR_DELAY 40
typedef struct {
int x;
@@ -25,6 +26,7 @@ struct tetrimino { typedef struct {
int occupied;
int constant;
+ int remove_tick;
} slot;
enum movements {
diff --git a/ncurses_ui.c b/ncurses_ui.c index 2a8a2b3..0f5af4e 100644 --- a/ncurses_ui.c +++ b/ncurses_ui.c @@ -37,9 +37,7 @@ void curses_init() { noecho();
keypad(stdscr, TRUE);
curs_set(0);
- timeout(1000 / 60);
-
- //resize_term(20, 50);
+ timeout(1000 / CETRIS_HZ);
start_color();
init_pair(0, COLOR_MAGENTA, COLOR_BLACK);
@@ -53,8 +51,15 @@ void draw_board(struct cetris_game* g) { mvaddstr(0, 0, PLAY_FIELD_STR);
for (int x = 0; x < BOARD_X; x++) {
for (int y = 0; y < BOARD_Y; y++) {
- if (g->board[x][y].occupied)
- mvaddstr(y + 1, x * 2 + X_OFFSET, BLOCK);
+ if (g->board[x][y].occupied) {
+ if (g->board[x][y].remove_tick > 0) {
+ if (g->tick % 2 == 0) {
+ mvaddstr(y + 1, x * 2 + X_OFFSET, BLOCK);
+ }
+ } else {
+ mvaddstr(y + 1, x * 2 + X_OFFSET, BLOCK);
+ }
+ }
}
}
}
|