From 35af4c16593dc7a8458cec5ee552710717bf211f Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sun, 3 Mar 2019 15:28:49 -0500 Subject: fix issue in das and add hard drop --- cetris.c | 22 ++++++++++++++++++++-- cetris.h | 1 + ncurses_ui.c | 10 ++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cetris.c b/cetris.c index 9825023..3b4bfd6 100644 --- a/cetris.c +++ b/cetris.c @@ -14,6 +14,7 @@ void update_game_tick(struct cetris_game* g); void move_down(struct cetris_game* g); void move_left(struct cetris_game* g); void move_right(struct cetris_game* g); +void move_hard_drop(struct cetris_game* g); void rotate_clockwise(struct cetris_game* g); static void init_piece_queue(struct cetris_game* g); static void suffle_queue(struct cetris_game* g); @@ -91,7 +92,6 @@ void move_current(struct cetris_game* g, vec2 offset) { g->current.pos.x -= offset.x; if (check == -1) { - set_constants(g); next_piece(g); } @@ -99,6 +99,21 @@ void move_current(struct cetris_game* g, vec2 offset) { } } +void move_hard_drop(struct cetris_game* g) { + int drop = 0; + while (!drop) { + g->current.pos.y++; + int check = check_new_matrix(g, g->current.mat); + if (check <= 0) { + g->current.pos.y--; + drop = 1; + } + } + + wipe_board(g); + next_piece(g); +} + void move_down(struct cetris_game* g) { if (g->move_queue_pos >= g->move_queue_count - 1) { g->move_queue[g->move_queue_count] = DOWN; @@ -236,7 +251,6 @@ void update_game_tick(struct cetris_game* g) { } } else { clear_move_queue(g); - g->move_queue[g->move_queue_pos] = current_move; } } @@ -262,6 +276,10 @@ void update_game_tick(struct cetris_game* g) { } void next_piece(struct cetris_game* g) { + clear_move_queue(g); + + set_constants(g); + if (g->current_index == 6) { g->current_index = 0; suffle_queue(g); diff --git a/cetris.h b/cetris.h index 9d40ccf..2f7631b 100644 --- a/cetris.h +++ b/cetris.h @@ -59,4 +59,5 @@ void update_game_tick(struct cetris_game* g); void move_down(struct cetris_game* g); void move_left(struct cetris_game* g); void move_right(struct cetris_game* g); +void move_hard_drop(struct cetris_game* g); void rotate_clockwise(struct cetris_game* g); diff --git a/ncurses_ui.c b/ncurses_ui.c index cb0df04..2a8a2b3 100644 --- a/ncurses_ui.c +++ b/ncurses_ui.c @@ -70,14 +70,16 @@ int main(void) { c = getch(); switch (c) { case 'q': endwin(); exit(1); - case 'a': + case KEY_LEFT: move_left(&game); break; - case 'd': + case KEY_RIGHT: move_right(&game); break; - case 's': + case KEY_DOWN: move_down(&game); break; - case 'w': + case KEY_UP: rotate_clockwise(&game); break; + case ' ': + move_hard_drop(&game); } update_game_tick(&game); draw_board(&game); -- cgit v1.2.3-101-g0448