summary refs log tree commit diff
diff options
context:
space:
mode:
authorturnipgod2025-03-03 16:53:31 -0500
committerturnipgod2025-03-03 16:53:31 -0500
commita92899722ff9ef080fb9f6614020003ae9d918da (patch)
treeb6f2e77fec24435d16751992c4446d7ce1a385b7
parentea048d60ebb07e8d6c729ef25e7321e1b564f8ce (diff)
minor hold/queue bugfixes
-rw-r--r--src/main.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index e9eacbc..82e9e90 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,10 +35,7 @@ struct {
 } current_piece;
 
 struct Color matrix[MATRIX_WIDTH][MATRIX_HEIGHT];
-int piece_queue[TETROMINO_COUNT*2] = {
-    0, 1, 2, 3, 4, 5, 6,
-    0, 1, 2, 3, 4, 5, 6
-};
+int piece_queue[TETROMINO_COUNT*2];
 int current_bag = 0;
 int current_piece_index = 0;
 int hold = 7;
@@ -145,6 +142,9 @@ void render_matrix(void)
 void shuffle_bag(int *bag)
 {
     for (int i = 0; i < TETROMINO_COUNT; i++) {
+        bag[i] = i;
+    }
+    for (int i = 0; i < TETROMINO_COUNT; i++) {
         int r = i + rand() / (RAND_MAX / (TETROMINO_COUNT - i) + 1);
         int t = bag[r];
         bag[r] = bag[i];
@@ -196,9 +196,9 @@ void handle_hold(void)
     if (IsKeyDown(KEY_SPACE) && !held) {
         if (hold == 7) {
             hold = current_piece.type;
+            current_piece.type = piece_queue[current_piece_index];
             current_piece_index++;
             current_piece_index = current_piece_index % 14;
-            current_piece.type = current_piece_index;
         } else {
             int temp = current_piece.type;
             current_piece.type = hold;