outfly/src/main.rs

80 lines
2.1 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
2024-03-16 22:04:58 +00:00
use bevy::a11y::AccessibilityPlugin;
use bevy::audio::AudioPlugin;
use bevy::input::InputPlugin;
use bevy::log::LogPlugin;
2024-03-16 20:44:51 +00:00
use bevy::prelude::*;
2024-03-16 22:04:58 +00:00
use bevy::render::RenderPlugin;
use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode};
use bevy::scene::ScenePlugin;
use bevy::core_pipeline::CorePipelinePlugin;
use bevy::pbr::PbrPlugin;
use bevy::winit::WinitPlugin;
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, (
2024-03-16 22:04:58 +00:00
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, (
2024-03-16 22:04:58 +00:00
handle_input,
player::handle_input,
audio::toggle_bgm,
world::asset_loaded.after(world::load_cubemap_asset),
))
.add_plugins((
LogPlugin::default(),
MinimalPlugins,
TransformPlugin,
InputPlugin,
WindowPlugin::default(),
AccessibilityPlugin,
AssetPlugin::default(),
ScenePlugin::default(),
WinitPlugin::default(),
RenderPlugin::default(),
ImagePlugin::default_nearest(),
CorePipelinePlugin::default(),
PbrPlugin::default(),
AudioPlugin::default(),
2024-03-16 15:22:44 +00:00
))
.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 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
}