Newer
Older
use bevy::math::uvec2;
use bevy::prelude::*;
use iyes_loopless::prelude::AppLooplessStateExt;
use iyes_loopless::state::NextState;
use crate::assets::AssetHandles;
use crate::world::generators::blobular::Blobular;
use crate::world::generators::drunkard_corridor::DrunkardGenerator;
use crate::world::level_map::LevelMapBundle;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
pub fn spawn_player(mut commands: Commands) {
commands.spawn_bundle(LevelMapBundle::generate::<DrunkardGenerator>(150, 150));
}
#[derive(Component)]
pub struct FpsText;
pub fn spawn_fps_overlay(mut commands: Commands, assets: Res<AssetHandles>) {
commands
.spawn_bundle(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
position: UiRect::new(Val::Px(20.0), Val::Auto, Val::Px(20.0), Val::Auto),
flex_direction: FlexDirection::Row,
..Default::default()
},
color: Color::rgba(0.0, 0.0, 0.0, 0.0).into(),
..Default::default()
})
.with_children(|child_builder| {
child_builder.spawn_bundle(TextBundle {
text: Text::from_section(
"FPS: ",
TextStyle {
font_size: 20.0,
font: assets.font("main"),
color: Color::WHITE,
},
),
..Default::default()
});
child_builder
.spawn_bundle(TextBundle {
text: Text::from_section(
"000",
TextStyle {
font_size: 20.0,
font: assets.font("main"),
color: Color::YELLOW,
},
),
..Default::default()
})
.insert(FpsText);
});
}
pub fn update_fps_text(time: Res<Time>, mut text_query: Query<&mut Text, With<FpsText>>) {
let fps = format!("{:03.0}", 1.0 / time.delta_seconds());
for mut text in &mut text_query {
text.sections[0].value = fps.clone();
}
}
pub fn skip_menu(mut commands: Commands) {
commands.insert_resource(NextState(AppState::InGame));
}
pub struct DebugPlugin;
impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) {
app.add_enter_system(AppState::Menu, skip_menu)
.add_enter_system(AppState::Menu, spawn_fps_overlay)
.add_enter_system(AppState::InGame, spawn_player)
.add_system(update_fps_text);