outfly/src/main.rs
2024-03-17 00:24:47 +01:00

57 lines
1.5 KiB
Rust

mod audio;
mod player;
mod camera;
mod world;
mod settings;
use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode };
use bevy::prelude::*;
fn main() {
App::new()
.add_systems(Startup, (
setup,
settings::setup,
audio::setup,
player::setup,
world::setup,
))
.add_systems(Update, (
handle_input,
player::handle_input,
audio::toggle_bgm,
world::asset_loaded.after(world::load_cubemap_asset),
))
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(camera::CameraControllerPlugin)
.run();
}
fn setup(
//mut commands: Commands,
mut windows: Query<&mut Window, With<PrimaryWindow>>
) {
for mut window in &mut windows {
window.cursor.grab_mode = CursorGrabMode::Locked;
window.cursor.visible = false;
window.mode = WindowMode::Fullscreen;
window.title = "OutFly".to_string();
}
}
fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut settings: Query<&mut settings::Settings>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>
) {
if keyboard_input.pressed(KeyCode::KeyQ) {
app_exit_events.send(bevy::app::AppExit);
}
if keyboard_input.just_pressed(KeyCode::F12) {
let result = settings.get_single_mut();
if result.is_ok() {
result.unwrap().reset()
}
}
}