Remove lost characters
This commit is contained in:
parent
d03308136e
commit
da1a8351ff
1 changed files with 24 additions and 3 deletions
27
src/game.rs
27
src/game.rs
|
@ -25,6 +25,7 @@ pub struct GamePlugin;
|
|||
impl Plugin for GamePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<LevelStartupEvent>()
|
||||
.add_event::<ChangeCharacterEvent>()
|
||||
.init_resource::<CharacterMeshes>()
|
||||
.insert_resource(CurrentLevel(None))
|
||||
.init_resource::<CharacterList>()
|
||||
|
@ -41,7 +42,8 @@ impl Plugin for GamePlugin {
|
|||
.with_system(player_movement_system)
|
||||
.with_system(level_keyboard_system)
|
||||
.with_system(camera_system)
|
||||
.with_system(character_particle_effect_system),
|
||||
.with_system(character_particle_effect_system)
|
||||
.with_system(kill_character_system),
|
||||
)
|
||||
.add_system_set(
|
||||
SystemSet::on_update(AppState::Win)
|
||||
|
@ -65,6 +67,8 @@ impl Plugin for GamePlugin {
|
|||
|
||||
pub struct LevelStartupEvent;
|
||||
|
||||
pub struct ChangeCharacterEvent;
|
||||
|
||||
// Resources
|
||||
|
||||
pub struct CurrentLevel(pub Option<LevelId>);
|
||||
|
@ -435,14 +439,14 @@ fn collision_event_system(
|
|||
|
||||
fn change_character_system(
|
||||
mut commands: Commands,
|
||||
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
characters: Query<(Entity, &CharacterColor, Option<&Player>)>,
|
||||
character_list: Res<CharacterList>,
|
||||
audio_assets: Res<audio_system::AudioAssets>,
|
||||
audio: Res<Audio>,
|
||||
change_character_event: EventReader<ChangeCharacterEvent>,
|
||||
) {
|
||||
if !keyboard_input.just_pressed(KeyCode::Tab) {
|
||||
if !keyboard_input.just_pressed(KeyCode::Tab) && change_character_event.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -623,3 +627,20 @@ fn level_keyboard_system(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn kill_character_system(
|
||||
mut commands: Commands,
|
||||
character_query: Query<(Entity, &Transform, Option<&Player>), With<CharacterColor>>,
|
||||
mut character_list: ResMut<CharacterList>,
|
||||
mut change_character_event: EventWriter<ChangeCharacterEvent>,
|
||||
) {
|
||||
for (entity, transform, player) in character_query.iter() {
|
||||
if transform.translation.y < -512. {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
character_list.0.remove(&entity);
|
||||
if player.is_some() {
|
||||
change_character_event.send(ChangeCharacterEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue