outfly/src/main.rs

57 lines
1.5 KiB
Rust
Raw Normal View History

2024-03-16 19:53:57 +00:00
mod audio;
2024-03-16 20:22:59 +00:00
mod player;
mod camera;
2024-03-16 20:44:51 +00:00
mod world;
2024-03-16 21:20:23 +00:00
mod settings;
2024-03-16 19:53:57 +00:00
use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode };
2024-03-16 20:44:51 +00:00
use bevy::prelude::*;
2024-03-16 14:00:31 +00:00
fn main() {
2024-03-16 14:00:31 +00:00
App::new()
2024-03-16 19:53:57 +00:00
.add_systems(Startup, (
setup,
settings::setup,
audio::setup,
player::setup,
world::setup,
2024-03-16 19:53:57 +00:00
))
2024-03-16 15:22:44 +00:00
.add_systems(Update, (
handle_input,
player::handle_input,
audio::toggle_bgm,
world::asset_loaded.after(world::load_cubemap_asset),
2024-03-16 15:22:44 +00:00
))
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(camera::CameraControllerPlugin)
2024-03-16 14:00:31 +00:00
.run();
}
fn setup(
2024-03-16 20:44:51 +00:00
//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;
2024-03-16 23:24:47 +00:00
window.title = "OutFly".to_string();
}
2024-03-16 15:22:44 +00:00
}
2024-03-16 15:12:35 +00:00
fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
2024-03-16 21:20:23 +00:00
mut settings: Query<&mut settings::Settings>,
2024-03-16 15:12:35 +00:00
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>
) {
if keyboard_input.pressed(KeyCode::KeyQ) {
app_exit_events.send(bevy::app::AppExit);
2024-03-16 14:13:00 +00:00
}
2024-03-16 21:20:23 +00:00
if keyboard_input.just_pressed(KeyCode::F12) {
let result = settings.get_single_mut();
if result.is_ok() {
result.unwrap().reset()
}
}
2024-03-16 14:13:00 +00:00
}