bevyjam/src/main.rs

57 lines
1.5 KiB
Rust
Raw Normal View History

2022-08-24 11:31:17 +02:00
#[cfg(not(target_arch = "wasm32"))]
2022-08-23 17:02:13 +02:00
mod audio;
2022-08-21 19:17:55 +02:00
mod game;
2022-08-23 12:02:58 +02:00
mod levels;
2022-08-21 19:17:55 +02:00
mod menu;
2022-08-23 23:14:32 +08:00
mod particle_effect;
2022-08-21 19:17:55 +02:00
2022-08-24 11:31:17 +02:00
use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*};
2022-08-21 19:17:55 +02:00
use bevy_rapier2d::prelude::*;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
enum AppState {
Menu,
Game,
2022-08-23 12:02:58 +02:00
Win,
2022-08-21 19:17:55 +02:00
}
fn main() {
2022-08-24 11:31:17 +02:00
let (audio_event_sender, audio_event_receiver) =
crossbeam_channel::bounded::<game::AudioMsg>(512);
2022-08-23 17:02:13 +02:00
2022-08-24 11:31:17 +02:00
#[cfg(not(target_arch = "wasm32"))]
2022-08-23 17:02:13 +02:00
std::thread::spawn(move || audio::setup(audio_event_receiver));
2022-08-21 19:17:55 +02:00
App::new()
2022-08-23 17:02:13 +02:00
.insert_resource(audio_event_sender)
2022-08-21 19:17:55 +02:00
.add_state(AppState::Menu)
.add_plugins(DefaultPlugins)
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(64.0))
.add_plugin(RapierDebugRenderPlugin::default())
.add_plugin(menu::MenuPlugin)
.add_plugin(game::GamePlugin)
2022-08-24 13:52:14 +08:00
.add_plugin(particle_effect::ParticleEffectPlugin)
2022-08-23 12:42:56 +02:00
.add_plugin(bevy_inspector_egui::WorldInspectorPlugin::new())
2022-08-21 19:17:55 +02:00
.add_startup_system(setup)
.run();
}
2022-08-23 17:02:13 +02:00
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
2022-08-24 11:31:17 +02:00
#[cfg(not(target_arch = "wasm32"))]
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
#[cfg(target_arch = "wasm32")]
2022-08-23 12:42:56 +02:00
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
commands.insert_resource(font);
2022-08-21 19:17:55 +02:00
commands.spawn_bundle(Camera2dBundle {
camera_2d: Camera2d {
clear_color: ClearColorConfig::Custom(Color::BLACK),
},
..Default::default()
});
commands.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 0.6,
});
}