Level management & win
This commit is contained in:
parent
55ab83588a
commit
214e55d7ac
7 changed files with 355 additions and 151 deletions
74
src/levels.rs
Normal file
74
src/levels.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
mod game_over;
|
||||
mod level0;
|
||||
mod level1;
|
||||
|
||||
use crate::game::*;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_hanabi::*;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
pub fn setup_level(
|
||||
commands: &mut Commands,
|
||||
current_level: &mut ResMut<CurrentLevel>,
|
||||
level_startup_event: &mut EventWriter<LevelStartupEvent>,
|
||||
level_id: LevelId,
|
||||
) {
|
||||
let level_entity = commands
|
||||
.spawn()
|
||||
.insert(Level)
|
||||
.insert(SelectedCharacterId(None))
|
||||
.insert(CharacterIdList(BTreeSet::new()))
|
||||
.id();
|
||||
current_level.0 = Some(level_id);
|
||||
|
||||
level_startup_event.send(LevelStartupEvent(level_entity));
|
||||
}
|
||||
|
||||
pub fn despawn_level(mut commands: Commands, level_query: Query<Entity, With<Level>>) {
|
||||
for entity in level_query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
// This is a bad design, to be refactored some days
|
||||
pub fn post_setup_level(
|
||||
mut commands: Commands,
|
||||
character_meshes: Res<CharacterMeshes>,
|
||||
mut effects: ResMut<Assets<EffectAsset>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
current_level: Res<CurrentLevel>,
|
||||
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
|
||||
mut level_startup_event: EventReader<LevelStartupEvent>,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
for LevelStartupEvent(level_entity) in level_startup_event.iter() {
|
||||
if let Ok((mut selected_character_id, mut character_id_list)) =
|
||||
level_query.get_mut(*level_entity)
|
||||
{
|
||||
if let Some(level_id) = current_level.0 {
|
||||
match level_id.0 {
|
||||
0 => level0::setup(
|
||||
&mut commands,
|
||||
&character_meshes,
|
||||
&mut effects,
|
||||
&mut materials,
|
||||
&mut selected_character_id,
|
||||
&mut character_id_list,
|
||||
),
|
||||
1 => level1::setup(
|
||||
&mut commands,
|
||||
&character_meshes,
|
||||
&mut effects,
|
||||
&mut materials,
|
||||
&mut selected_character_id,
|
||||
&mut character_id_list,
|
||||
),
|
||||
_ => game_over::setup(&mut commands, &asset_server),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue