This commit is contained in:
2023-09-18 21:24:51 +02:00
parent 7f1f2cc6ab
commit d12e53472d
3 changed files with 83 additions and 0 deletions

21
src/level.rs Normal file
View File

@@ -0,0 +1,21 @@
use bevy::prelude::*;
// #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
pub enum LevelState {
#[default]
Begin,
InGame,
End,
}
#[derive(Resource)]
struct Level(u32);
pub(super) struct LevelPlugin;
impl Plugin for LevelPlugin {
fn build(&self, app: &mut App) {
// app.add_state::<LevelState>();
}
}

1
src/ui/menu.rs Normal file
View File

@@ -0,0 +1 @@
use bevy::prelude::*;

61
src/ui/status.rs Normal file
View File

@@ -0,0 +1,61 @@
use crate::{Level, Score};
use bevy::prelude::*;
#[derive(Component)]
pub(super) struct StatusText;
pub(super) fn spawn_status_text(mut commands: Commands, asset_server: Res<AssetServer>) {
let font = asset_server.load("fonts/Audiowide-Regular.ttf");
commands.spawn((
StatusText,
TextBundle::from_sections([
TextSection::new(
"Level: ",
TextStyle {
font: font.clone(),
font_size: 32.0,
color: Color::WHITE,
},
),
TextSection::from_style(TextStyle {
font: font.clone(),
font_size: 32.0,
color: Color::WHITE,
}),
TextSection::new(
" Score: ",
TextStyle {
font: font.clone(),
font_size: 32.0,
color: Color::WHITE,
},
),
TextSection::from_style(TextStyle {
font,
font_size: 32.0,
color: Color::WHITE,
}),
])
.with_style(Style {
position_type: PositionType::Absolute,
left: Val::Px(10.0),
bottom: Val::Px(10.0),
..Default::default()
}),
));
}
pub(super) fn update_status_text(
mut query: Query<&mut Text, With<StatusText>>,
score: Res<Score>,
level: Res<Level>,
) {
let score = score.0;
let level = level.0;
for mut text in query.iter_mut() {
text.sections[1].value = format!("{level}");
text.sections[3].value = format!("{score}");
}
}