astraea/src/end_state.rs

65 lines
1.6 KiB
Rust
Raw Normal View History

2024-10-06 15:36:10 +02:00
use bevy::prelude::*;
2024-10-07 17:57:44 +02:00
2024-10-06 15:41:41 +02:00
use crate::GameState;
use crate::GameOver;
2024-10-07 17:57:44 +02:00
use crate::GameData;
2024-10-06 15:36:10 +02:00
2024-10-06 15:41:41 +02:00
pub fn setup(
2024-10-06 15:36:10 +02:00
mut commands: Commands,
_asset_server: Res<AssetServer>,
2024-10-07 17:57:44 +02:00
game_data: Res<GameData>,
2024-10-06 15:36:10 +02:00
) {
2024-10-07 17:57:44 +02:00
let container_node = NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
..default()
};
2024-10-06 15:36:10 +02:00
2024-10-07 17:57:44 +02:00
let container = commands.spawn(container_node).id();
2024-10-06 15:36:10 +02:00
2024-10-07 17:57:44 +02:00
let top_text_style = TextStyle {
font_size: 50.0,
color: Color::WHITE,
// font: asset_server.load("fonts/FiraSans-Bold.ttf"),
..default()
};
2024-10-06 15:36:10 +02:00
2024-10-07 17:57:44 +02:00
let bottom_text_style = TextStyle {
font_size: 30.0,
color: Color::WHITE,
// font: asset_server.load("fonts/FiraSans-Regular.ttf"),
..default()
};
2024-10-06 15:36:10 +02:00
2024-10-07 17:57:44 +02:00
let top_text_node = TextBundle::from_section(
"Game Over",
top_text_style,
);
2024-10-06 15:36:10 +02:00
2024-10-07 17:57:44 +02:00
let bottom_text_node = TextBundle::from_section(
format!("final score : {}", game_data.score),
bottom_text_style,
);
2024-10-06 15:36:10 +02:00
2024-10-07 17:57:44 +02:00
let top_text = commands.spawn((top_text_node, GameOver)).id();
let bottom_text = commands.spawn((bottom_text_node, GameOver)).id();
2024-10-06 15:36:10 +02:00
2024-10-07 17:57:44 +02:00
commands.entity(container).push_children(&[top_text, bottom_text]);
2024-10-06 15:36:10 +02:00
}
2024-10-06 15:46:32 +02:00
pub fn player_interact(
2024-10-06 15:36:10 +02:00
keys: Res<ButtonInput<KeyCode>>,
mut game_state: ResMut<NextState<GameState>>
) {
if keys.just_pressed(KeyCode::Space) {
info!("start space");
game_state.set(GameState::Start);
}
}