From 3aac2039d9343b670223b684e21122f6f29a9f1f Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sun, 3 Mar 2019 18:06:31 -0500 Subject: add proper counterclockwise rotate support --- cetris.c | 14 +++++++++++--- cetris.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cetris.c b/cetris.c index ed7f211..09474a4 100644 --- a/cetris.c +++ b/cetris.c @@ -16,6 +16,7 @@ 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); +void rotate_counterclockwise(struct cetris_game* g); static void init_piece_queue(struct cetris_game* g); static void shuffle_queue(struct cetris_game* g); static void next_piece(struct cetris_game* g); @@ -185,9 +186,12 @@ void rotate_matrix(struct cetris_game* g, int clockwise) { for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { if (g->current.mat[y][x]) { - int new_x = 1 - (y - 2); - int new_y = 2 + (x - 1); - if (g->current.t == I) new_y--; + int new_x = (clockwise) ? 1 - (y - 2) : 1 + (y - 2); + int new_y = (clockwise) ? 2 + (x - 1) : 2 - (x - 1); + if (g->current.t == I) { + if (clockwise) new_y--; + else new_x++; + } m[new_y][new_x] = 1; } } @@ -236,6 +240,10 @@ void rotate_clockwise(struct cetris_game* g) { rotate_matrix(g, 1); } +void rotate_counterclockwise(struct cetris_game* g) { + rotate_matrix(g, 0); +} + int check_new_matrix(struct cetris_game* g, piece_matrix m) { vec2 r; for (int x = 0; x < 4; x++) { diff --git a/cetris.h b/cetris.h index e8c5323..15f5850 100644 --- a/cetris.h +++ b/cetris.h @@ -71,3 +71,4 @@ 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); +void rotate_counterclockwise(struct cetris_game* g); -- cgit v1.2.3-101-g0448