diff options
| author | 2019-03-03 15:28:49 -0500 | |
|---|---|---|
| committer | 2019-03-03 15:28:49 -0500 | |
| commit | 35af4c16593dc7a8458cec5ee552710717bf211f (patch) | |
| tree | 0dae947c3530e2b4db9a09d14eb1e17519e5e29b | |
| parent | 83e606f60411d9964d2b100c07c5661738e53a44 (diff) | |
| download | cetris-35af4c16593dc7a8458cec5ee552710717bf211f.tar.gz cetris-35af4c16593dc7a8458cec5ee552710717bf211f.tar.bz2 cetris-35af4c16593dc7a8458cec5ee552710717bf211f.zip | |
fix issue in das and add hard drop
| -rw-r--r-- | cetris.c | 22 | ||||
| -rw-r--r-- | cetris.h | 1 | ||||
| -rw-r--r-- | ncurses_ui.c | 10 |
3 files changed, 27 insertions, 6 deletions
@@ -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);
@@ -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);
|