You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
martian-chess/src/main.rs

72 lines
1.8 KiB
Rust

mod audio;
mod debug;
mod display2d;
mod display3d;
mod game;
mod prelude;
use std::time::Duration;
use bevy::asset::ChangeWatcher;
use crate::prelude::*;
fn main() {
App::new()
.add_state::<GameState>()
.add_systems(Update, state)
.add_systems(Update, loading.run_if(in_state(GameState::Loading)))
.add_plugins((
DefaultPlugins
.set(ImagePlugin::default_nearest())
.set(WindowPlugin {
primary_window: Some(Window {
title: "Martian Chess".into(),
resolution: (640., 480.).into(),
..default()
}),
..default()
})
.set(AssetPlugin {
watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)),
..default()
}),
audio::AudioPlugin,
debug::DebugPlugin,
display2d::Display2dPlugin,
display3d::Display3dPlugin,
game::GamePlugin,
))
.run();
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)]
pub enum GameState {
#[default]
Loading,
Menu,
Display2d,
Display3d,
}
fn loading(
server: Res<AssetServer>,
sprites: Res<Assets<Image>>,
mut next_state: ResMut<NextState<GameState>>,
) {
let items = { sprites.ids() };
let states = server.get_group_load_state(items);
match states {
LoadState::Loaded | LoadState::NotLoaded => next_state.set(GameState::Display2d),
_ => (),
}
}
fn state(state: Option<Res<State<GameState>>>) {
state.map(|s| {
if s.is_added() || s.is_changed() {
info!("Updated state is {:?}", s);
}
});
}