cyber_rider/src/ui.rs
Joe Ardent bd96c52f3a Update to Bevy 0.8. Not showing the cyberbike for some reason.
Physics is still probably fucked.
2022-08-13 15:30:37 -07:00

51 lines
1.4 KiB
Rust

use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use crate::bike::CyberBikeBody;
#[derive(Component)]
struct UpText;
fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
//commands.spawn_bundle(UiCameraBundle::default());
commands
.spawn_bundle(TextBundle {
style: Style {
align_self: AlignSelf::FlexEnd,
..Default::default()
},
// Use `Text` directly
text: Text {
// Construct a `Vec` of `TextSection`s
sections: vec![TextSection {
value: "".to_string(),
style: TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 40.0,
color: Color::GOLD,
},
}],
..Default::default()
},
..Default::default()
})
.insert(UpText);
}
fn update_ui(
state_query: Query<&Velocity, With<CyberBikeBody>>,
mut text_query: Query<&mut Text, With<UpText>>,
) {
let mut text = text_query.single_mut();
let state = state_query.single();
text.sections[0].value = format!("spd: {:.2}", state.linvel.length());
}
pub struct CyberUIPlugin;
impl Plugin for CyberUIPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(setup_ui).add_system(update_ui);
}
}