From 824cb998ffde0315595ce0639ceb87b42e37567e Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Wed, 19 Nov 2025 22:15:11 -0800 Subject: [PATCH] Recognize fail state for a level Triggers when shapes are deactivated above the line --- src/bin/tetris/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/bin/tetris/main.rs b/src/bin/tetris/main.rs index 1ef3fff..ff15a06 100644 --- a/src/bin/tetris/main.rs +++ b/src/bin/tetris/main.rs @@ -81,6 +81,7 @@ fn main() { damage_on_clear_line.run_if(any_component_removed::), damage_over_time.run_if(on_timer(Duration::from_secs(5))), check_level_goal.run_if(resource_changed::), + check_level_fail.run_if(any_component_removed::), ), ) // UI systems @@ -1056,7 +1057,7 @@ fn add_piece(mut commands: Commands, mut shapes: ResMut) { commands .spawn(( GridPosition { - y: Y_MAX - shape_layout.height(), + y: Y_MAX, ..default() }, shape_layout, @@ -1437,3 +1438,16 @@ fn check_level_goal( } } } + +fn check_level_fail( + query: Query<&GridPosition, (With, Without, Without)>, + mut next: ResMut>, +) { + // Check all blocks that are unassigned + query.iter().for_each(|gp| { + // If any block is above the top line, the game is over + if gp.y >= Y_MAX { + next.set(GameState::GameOver); + } + }); +}