summary refs log tree commit diff
diff options
context:
space:
mode:
authorturnipgod2025-03-04 15:35:13 -0500
committerturnipgod2025-03-04 15:35:13 -0500
commit5e08a05586a62e7da5acf07a2ea511fff948b142 (patch)
treebab0223a045099b237735d23926cc50083ac938d
parent6e15ecd3943acf82bd4fccfbe79cc28445deb2bc (diff)
game over conditions
-rw-r--r--src/main.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index e3503a6..268c53e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,7 +24,8 @@ enum Phases {
     //ITERATE,
     //ANIMATE,
     //ELIMINATE,
-    //COMPLETE
+    //COMPLETE,
+    GAME_OVER,
 } game_phase;
 
 enum InputResult {
@@ -48,6 +49,7 @@ int current_bag = 0;
 int current_piece_index = 0;
 int hold = 7;
 int held = 0;
+int game_over = 0;
 double phase_time;
 double fall_tick;
 
@@ -231,7 +233,13 @@ void generation_phase(void)
     current_piece.pos_y = 20;
     held = 0;
     phase_time = 0.0;
-    game_phase = FALL;
+
+    // blockout lose condition
+    if (is_overlap(0, 0)) {
+        game_phase = GAME_OVER;
+    } else {
+        game_phase = FALL;
+    }
 }
 
 int rotate_piece(int dir)
@@ -430,8 +438,29 @@ void clear_line(int line)
     }
 }
 
+int check_lockout(void)
+{
+    int fully_above = 1;
+    for (int i = 0; i < tetrominos[current_piece.type].size; i++) {
+        for (int j = 0; j < tetrominos[current_piece.type].size; j++) {
+            if (tetrominos[current_piece.type].directions[current_piece.rotation][j][i] == 1) {
+                if (current_piece.pos_y + j - 1 < 20) {
+                    fully_above = 0;
+                }
+            }
+        }
+    }
+    return fully_above;
+}
+
 void pattern_phase(void)
 {
+    if (check_lockout()) {
+        phase_time = 0.0;
+        game_phase = GAME_OVER;
+        return;
+    }
+
     move_piece_to_matrix();
     for (int y = 0; y < MATRIX_HEIGHT; y++) {
         int line_full = 1;
@@ -464,6 +493,9 @@ void game_logic(void)
         case PATTERN:
             pattern_phase();
             break;
+        case GAME_OVER:
+            game_over = 1;
+            break;
     }
 }
 
@@ -489,7 +521,7 @@ int main(void)
     shuffle_bag(&(piece_queue[7]));
     phase_time = 0.0;
     game_phase = GENERATION;
-    while (!WindowShouldClose()) {
+    while (!WindowShouldClose() && !game_over) {
         game_logic();
         BeginDrawing();
         ClearBackground(WHITE);