43 lines
951 B
Rust
43 lines
951 B
Rust
|
use crate::AppState;
|
||
|
|
||
|
use bevy::{
|
||
|
input::{keyboard::KeyCode, Input},
|
||
|
prelude::*,
|
||
|
sprite::MaterialMesh2dBundle,
|
||
|
};
|
||
|
|
||
|
pub struct MenuPlugin;
|
||
|
|
||
|
impl Plugin for MenuPlugin {
|
||
|
fn build(&self, app: &mut App) {
|
||
|
app.add_system_set(SystemSet::on_enter(AppState::Menu).with_system(setup))
|
||
|
.add_system_set(
|
||
|
SystemSet::on_update(AppState::Menu).with_system(keyboard_input_system),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||
|
commands.spawn_bundle(Text2dBundle {
|
||
|
text: Text::from_section(
|
||
|
"Press ENTER",
|
||
|
TextStyle {
|
||
|
font: asset_server.get_handle("Cantarell-VF.odt"),
|
||
|
font_size: 64.0,
|
||
|
color: Color::WHITE,
|
||
|
},
|
||
|
)
|
||
|
.with_alignment(TextAlignment::CENTER),
|
||
|
..Default::default()
|
||
|
});
|
||
|
}
|
||
|
|
||
|
fn keyboard_input_system(
|
||
|
keyboard_input: Res<Input<KeyCode>>,
|
||
|
mut app_state: ResMut<State<AppState>>,
|
||
|
) {
|
||
|
if keyboard_input.just_pressed(KeyCode::Return) {
|
||
|
app_state.replace(AppState::Game).unwrap()
|
||
|
}
|
||
|
}
|