diff --git a/src/end_state.rs b/src/end_state.rs index 4d43fb1..aa505f0 100644 --- a/src/end_state.rs +++ b/src/end_state.rs @@ -9,14 +9,13 @@ pub fn setup( mut player_query: Query<&mut Player> ) { if let Ok(player) = player_query.get_single_mut() { - // Create a container node that places its children (text areas) in a vertical column and centers them let container_node = NodeBundle { style: Style { - width: Val::Percent(100.0), // Full width of the screen - height: Val::Percent(100.0), // Full height of the screen - flex_direction: FlexDirection::Column, // Arrange children in a column (vertical) - justify_content: JustifyContent::Center, // Center vertically - align_items: AlignItems::Center, // Center horizontally + width: Val::Percent(100.0), + height: Val::Percent(100.0), + flex_direction: FlexDirection::Column, + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, ..default() }, ..default() @@ -24,35 +23,30 @@ pub fn setup( let container = commands.spawn(container_node).id(); - // TextStyle for the top text (larger font) let top_text_style = TextStyle { - font_size: 50.0, // Larger font size + font_size: 50.0, color: Color::WHITE, - // font: asset_server.load("fonts/FiraSans-Bold.ttf"), // Load font if needed + // font: asset_server.load("fonts/FiraSans-Bold.ttf"), ..default() }; - // TextStyle for the bottom text (smaller font) let bottom_text_style = TextStyle { - font_size: 30.0, // Smaller font size + font_size: 30.0, color: Color::WHITE, - // font: asset_server.load("fonts/FiraSans-Regular.ttf"), // Load font if needed + // font: asset_server.load("fonts/FiraSans-Regular.ttf"), ..default() }; - // TextBundle for the top text let top_text_node = TextBundle::from_section( - "Game Over", // Text for the top section + "Game Over", top_text_style, ); - // TextBundle for the bottom text let bottom_text_node = TextBundle::from_section( - format!("final score : {}", player.score), // Text for the bottom section + format!("final score : {}", player.score), bottom_text_style, ); - // Spawn the text nodes and add them as children to the container let top_text = commands.spawn((top_text_node, GameOver)).id(); let bottom_text = commands.spawn((bottom_text_node, GameOver)).id(); diff --git a/src/game_state.rs b/src/game_state.rs index bc82407..5e5dc74 100644 --- a/src/game_state.rs +++ b/src/game_state.rs @@ -30,35 +30,31 @@ pub struct ScoreLabel; pub struct HintLabel; pub fn setup(mut commands: Commands, _asset_server: Res) { - // Create a container node that places its children (buttons) at the bottom of the screen let container_node = NodeBundle { style: Style { - width: Val::Percent(100.0), // Full width of the screen - height: Val::Percent(100.0), // Full height of the screen - flex_direction: FlexDirection::Row, // Arrange children in a row (horizontal) - justify_content: JustifyContent::Center, // Center horizontally - align_items: AlignItems::FlexEnd, // Place at the bottom of the screen - padding: UiRect::all(Val::Px(10.0)), // Optional padding + width: Val::Percent(100.0), + height: Val::Percent(100.0), + flex_direction: FlexDirection::Row, + justify_content: JustifyContent::Center, + align_items: AlignItems::FlexEnd, + padding: UiRect::all(Val::Px(10.0)), ..default() }, ..default() }; - // Button style (same for all buttons) let button_style = Style { width: Val::Px(150.0), height: Val::Px(65.0), - margin: UiRect::all(Val::Px(10.0)), // Add margin between buttons - justify_content: JustifyContent::Center, // Center text horizontally - align_items: AlignItems::Center, // Center text vertically + margin: UiRect::all(Val::Px(10.0)), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, border: UiRect::all(Val::Px(5.0)), ..default() }; - // Create the container for the buttons let container = commands.spawn(container_node).id(); - // Function to create buttons with different text for _i in 1..=4 { let button_node = ButtonBundle { style: button_style.clone(), @@ -77,7 +73,6 @@ pub fn setup(mut commands: Commands, _asset_server: Res) { }, ); - // Spawn the button and its text as children of the container let button = commands.spawn((button_node, MainGame)).id(); let button_text = commands.spawn((button_text_node, AnswerButton, MainGame)).id(); @@ -85,12 +80,11 @@ pub fn setup(mut commands: Commands, _asset_server: Res) { commands.entity(container).push_children(&[button]); } - // Label style for top corners let label_style = Style { - position_type: PositionType::Absolute, // Absolute positioning - width: Val::Auto, // Auto width to fit text - height: Val::Auto, // Auto height to fit text - margin: UiRect::all(Val::Px(10.0)), // Margin around the text + position_type: PositionType::Absolute, + width: Val::Auto, + height: Val::Auto, + margin: UiRect::all(Val::Px(10.0)), ..default() }; @@ -103,7 +97,7 @@ pub fn setup(mut commands: Commands, _asset_server: Res) { ..label_style.clone() }, text: Text::from_section( - "* * *", // Text content + "* * *", TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 30.0, @@ -123,7 +117,7 @@ pub fn setup(mut commands: Commands, _asset_server: Res) { ..label_style.clone() }, text: Text::from_section( - "0", // Text content + "0", TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 30.0, @@ -134,14 +128,13 @@ pub fn setup(mut commands: Commands, _asset_server: Res) { ..default() }; - // Centered container for the "Hint" label let centered_container_node = NodeBundle { style: Style { position_type: PositionType::Absolute, - width: Val::Percent(100.0), // Full width - top: Val::Px(20.0), // Positioned at the top - justify_content: JustifyContent::Center, // Center horizontally - align_items: AlignItems::Center, // Center vertically + width: Val::Percent(100.0), + top: Val::Px(20.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, ..default() }, ..default() @@ -158,11 +151,9 @@ pub fn setup(mut commands: Commands, _asset_server: Res) { }, ); - // Spawn the top left and top right labels commands.spawn((top_left_label_node, MainGame, HealthLabel)); commands.spawn((top_right_label_node, MainGame, ScoreLabel)); - // Create a parent container and then spawn the hint label inside it let centered_container = commands.spawn(centered_container_node).id(); let hint_label = commands.spawn((hint_label_node, MainGame, HintLabel)).id(); @@ -173,10 +164,10 @@ pub fn setup(mut commands: Commands, _asset_server: Res) { pub fn player_interact( keys: Res>, - mut player_query: Query<(&mut Player, &mut Transform)>, // Query to get Player and Transform - sky: Res, // Res to access the Sky resource + mut player_query: Query<(&mut Player, &mut Transform)>, + sky: Res, text_query: Query<&mut Text, With>, - button_query: Query<(&mut BackgroundColor, &mut BorderColor), With