broken
This commit is contained in:
parent
74673e072c
commit
440ec86cc7
70
src/end_state.rs
Normal file
70
src/end_state.rs
Normal file
|
@ -0,0 +1,70 @@
|
|||
use bevy::prelude::*;
|
||||
use core::Player;
|
||||
use core::GameState;
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
_asset_server: Res<AssetServer>,
|
||||
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
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
};
|
||||
|
||||
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
|
||||
color: Color::WHITE,
|
||||
// font: asset_server.load("fonts/FiraSans-Bold.ttf"), // Load font if needed
|
||||
..default()
|
||||
};
|
||||
|
||||
// TextStyle for the bottom text (smaller font)
|
||||
let bottom_text_style = TextStyle {
|
||||
font_size: 30.0, // Smaller font size
|
||||
color: Color::WHITE,
|
||||
// font: asset_server.load("fonts/FiraSans-Regular.ttf"), // Load font if needed
|
||||
..default()
|
||||
};
|
||||
|
||||
// TextBundle for the top text
|
||||
let top_text_node = TextBundle::from_section(
|
||||
"Game Over", // Text for the top section
|
||||
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
|
||||
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();
|
||||
|
||||
commands.entity(container).push_children(&[top_text, bottom_text]);
|
||||
}
|
||||
}
|
||||
|
||||
fn buttons(
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut game_state: ResMut<NextState<GameState>>
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::Space) {
|
||||
info!("start space");
|
||||
game_state.set(GameState::Start);
|
||||
}
|
||||
}
|
0
src/game_state.rs
Normal file
0
src/game_state.rs
Normal file
71
src/main.rs
71
src/main.rs
|
@ -9,6 +9,8 @@ use std::f64::consts::PI;
|
|||
use rand::seq::SliceRandom;
|
||||
use rand::RngCore;
|
||||
|
||||
mod end_state;
|
||||
|
||||
const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15);
|
||||
const WRONG_BUTTON: Color = Color::srgb(0.50, 0.15, 0.15);
|
||||
const RIGHT_BUTTON: Color = Color::srgb(0.15, 0.50, 0.15);
|
||||
|
@ -124,78 +126,13 @@ fn main() {
|
|||
.add_systems(Update, game_buttons.run_if(in_state(GameState::Game)))
|
||||
.add_systems(Update, label_update.run_if(in_state(GameState::Game)))
|
||||
.add_systems(OnExit(GameState::Game), despawn_screen::<MainGame>)
|
||||
.add_systems(OnEnter(GameState::End), end_setup)
|
||||
.add_systems(Update, end_buttons.run_if(in_state(GameState::End)))
|
||||
.add_systems(OnEnter(GameState::End), end_state::setup)
|
||||
.add_systems(Update, end_state::buttons.run_if(in_state(GameState::End)))
|
||||
.add_systems(OnExit(GameState::End), despawn_screen::<GameOver>)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn end_setup(
|
||||
mut commands: Commands,
|
||||
_asset_server: Res<AssetServer>,
|
||||
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
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
};
|
||||
|
||||
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
|
||||
color: Color::WHITE,
|
||||
// font: asset_server.load("fonts/FiraSans-Bold.ttf"), // Load font if needed
|
||||
..default()
|
||||
};
|
||||
|
||||
// TextStyle for the bottom text (smaller font)
|
||||
let bottom_text_style = TextStyle {
|
||||
font_size: 30.0, // Smaller font size
|
||||
color: Color::WHITE,
|
||||
// font: asset_server.load("fonts/FiraSans-Regular.ttf"), // Load font if needed
|
||||
..default()
|
||||
};
|
||||
|
||||
// TextBundle for the top text
|
||||
let top_text_node = TextBundle::from_section(
|
||||
"Game Over", // Text for the top section
|
||||
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
|
||||
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();
|
||||
|
||||
commands.entity(container).push_children(&[top_text, bottom_text]);
|
||||
}
|
||||
}
|
||||
|
||||
fn end_buttons(
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut game_state: ResMut<NextState<GameState>>
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::Space) {
|
||||
info!("start space");
|
||||
game_state.set(GameState::Start);
|
||||
}
|
||||
}
|
||||
|
||||
fn start_ui_setup(mut commands: Commands, _asset_server: Res<AssetServer>) {
|
||||
// Create a container node that places its children (text areas) in a vertical column and centers them
|
||||
|
|
0
src/start_state.rs
Normal file
0
src/start_state.rs
Normal file
Loading…
Reference in a new issue