use gamestates and assetloader
This commit is contained in:
57
src/main.rs
57
src/main.rs
@@ -1,7 +1,6 @@
|
||||
mod aim;
|
||||
mod alien;
|
||||
mod backpack;
|
||||
mod billboards;
|
||||
mod camera;
|
||||
mod cash;
|
||||
mod control;
|
||||
@@ -9,6 +8,8 @@ mod cutscene;
|
||||
mod gates;
|
||||
mod heads_ui;
|
||||
mod keys;
|
||||
mod loading_assets;
|
||||
mod loading_map;
|
||||
mod movables;
|
||||
mod npc;
|
||||
mod physics_layers;
|
||||
@@ -16,8 +17,8 @@ mod platforms;
|
||||
mod player;
|
||||
mod shooting;
|
||||
mod sounds;
|
||||
mod squish_animation;
|
||||
mod tb_entities;
|
||||
mod utils;
|
||||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::audio::PlaybackMode;
|
||||
@@ -25,12 +26,13 @@ use bevy::audio::Volume;
|
||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::view::ColorGrading;
|
||||
use bevy::scene::SceneInstanceReady;
|
||||
use bevy_polyline::PolylinePlugin;
|
||||
use bevy_sprite3d::Sprite3dPlugin;
|
||||
use bevy_trenchbroom::prelude::*;
|
||||
use control::controller::CharacterControllerPlugin;
|
||||
use physics_layers::GameLayer;
|
||||
use loading_assets::AudioAssets;
|
||||
use utils::billboards;
|
||||
use utils::squish_animation;
|
||||
|
||||
#[derive(Resource, Reflect, Debug)]
|
||||
#[reflect(Resource)]
|
||||
@@ -42,6 +44,14 @@ struct DebugVisuals {
|
||||
pub cam_follow: bool,
|
||||
}
|
||||
|
||||
#[derive(States, Default, Clone, Eq, PartialEq, Debug, Hash)]
|
||||
enum GameState {
|
||||
#[default]
|
||||
AssetLoading,
|
||||
MapLoading,
|
||||
Playing,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
|
||||
@@ -100,6 +110,10 @@ fn main() {
|
||||
app.add_plugins(sounds::plugin);
|
||||
app.add_plugins(camera::plugin);
|
||||
app.add_plugins(backpack::plugin);
|
||||
app.add_plugins(loading_assets::LoadingPlugin);
|
||||
app.add_plugins(loading_map::plugin);
|
||||
|
||||
app.init_state::<GameState>();
|
||||
|
||||
app.insert_resource(AmbientLight {
|
||||
color: Color::WHITE,
|
||||
@@ -107,41 +121,16 @@ fn main() {
|
||||
});
|
||||
app.insert_resource(ClearColor(Color::BLACK));
|
||||
|
||||
app.add_systems(Startup, (write_trenchbroom_config, music));
|
||||
app.add_systems(PostStartup, setup_scene);
|
||||
app.add_systems(Startup, write_trenchbroom_config);
|
||||
app.add_systems(OnEnter(GameState::Playing), music);
|
||||
app.add_systems(Update, (set_materials_unlit, set_tonemapping, set_shadows));
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
||||
fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
commands
|
||||
.spawn((
|
||||
CollisionLayers::new(LayerMask(GameLayer::Level.to_bits()), LayerMask::ALL),
|
||||
SceneRoot(asset_server.load("maps/map1.map#Scene")),
|
||||
))
|
||||
.observe(|_t: Trigger<SceneInstanceReady>| {
|
||||
//TODO: use for state driven map loading
|
||||
info!("map loaded");
|
||||
});
|
||||
|
||||
fn music(assets: Res<AudioAssets>, mut commands: Commands) {
|
||||
commands.spawn((
|
||||
DirectionalLight {
|
||||
illuminance: light_consts::lux::OVERCAST_DAY,
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
Transform {
|
||||
translation: Vec3::new(0.0, 2.0, 0.0),
|
||||
rotation: Quat::from_rotation_x(-1.7),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
fn music(asset_server: Res<AssetServer>, mut commands: Commands) {
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load("sfx/music/02.ogg")),
|
||||
AudioPlayer::new(assets.music.clone()),
|
||||
PlaybackSettings {
|
||||
mode: PlaybackMode::Loop,
|
||||
volume: Volume::new(0.6),
|
||||
@@ -150,7 +139,7 @@ fn music(asset_server: Res<AssetServer>, mut commands: Commands) {
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load("sfx/ambient/downtown.ogg")),
|
||||
AudioPlayer::new(assets.ambient.clone()),
|
||||
PlaybackSettings {
|
||||
mode: PlaybackMode::Loop,
|
||||
volume: Volume::new(1.),
|
||||
|
||||
Reference in New Issue
Block a user