summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2019-03-03 18:06:31 -0500
committerAndrew Opalach <andrew@akon.city> 2019-03-03 18:06:31 -0500
commit3aac2039d9343b670223b684e21122f6f29a9f1f (patch)
tree632268909920a6251db867d3b71d15f2816c2d85
parent3f57a26963fd6129916cfc177155b455a8cffdc3 (diff)
downloadcetris-3aac2039d9343b670223b684e21122f6f29a9f1f.tar.gz
cetris-3aac2039d9343b670223b684e21122f6f29a9f1f.tar.bz2
cetris-3aac2039d9343b670223b684e21122f6f29a9f1f.zip
add proper counterclockwise rotate support
-rw-r--r--cetris.c14
-rw-r--r--cetris.h1
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);