fix: menu, character despawn

This commit is contained in:
Pascal Engélibert 2022-08-21 19:53:08 +02:00
parent d109225da6
commit a52a3b84c8
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
4 changed files with 44 additions and 25 deletions

View file

@ -1,4 +1,18 @@
# Bavyjam
# Bevyjam
## TODO
* name
* scene management
* stream audio (with HexoSynthDSP)
* character fusion
* color filters
* level design
* win
* menu GUI
* (?) can jump only from a surface (no mid-air jump)
* (?) multiplayer
* make WASM build work again (replace hanabi)
## Build

View file

@ -1,7 +1,8 @@
#![allow(clippy::precedence)]
use crate::AppState;
use bevy::{
ecs::world::EntityMut,
input::{keyboard::KeyCode, Input},
prelude::{shape::Quad, *},
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
@ -237,7 +238,7 @@ fn collision_event_system(
mut commands: Commands,
current_level: Res<CurrentLevel>,
mut collision_events: EventReader<CollisionEvent>,
mut character_query: Query<&CharacterId>,
character_query: Query<&CharacterId>,
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
) {
if let Some(level_entity) = current_level.0 {
@ -253,6 +254,7 @@ fn collision_event_system(
if selected_character_id.0 == Some(*c2_id) {
selected_character_id.0 = Some(*c1_id);
}
commands.entity(*e2).despawn_recursive();
}
}
}

View file

@ -3,10 +3,8 @@ mod menu;
use bevy::{
core_pipeline::clear_color::ClearColorConfig,
input::{keyboard::KeyCode, Input},
prelude::*,
render::settings::{WgpuFeatures, WgpuSettings},
sprite::MaterialMesh2dBundle,
};
use bevy_fundsp::prelude::*;
use bevy_hanabi::*;
@ -14,7 +12,6 @@ use bevy_rapier2d::prelude::*;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
enum AppState {
Setup,
Menu,
Game,
}
@ -42,7 +39,6 @@ fn setup(
mut commands: Commands,
mut dsp_manager: ResMut<DspManager>,
asset_server: Res<AssetServer>,
mut app_state: ResMut<State<AppState>>,
) {
let _font: Handle<Font> = asset_server.load("Cantarell-VF.otf");
@ -57,6 +53,4 @@ fn setup(
brightness: 0.6,
});
dsp_manager.add_graph(game::sine_wave, 1.0);
//app_state.replace(AppState::Menu).unwrap();
}

View file

@ -3,33 +3,42 @@ use crate::AppState;
use bevy::{
input::{keyboard::KeyCode, Input},
prelude::*,
sprite::MaterialMesh2dBundle,
};
pub struct MenuPlugin;
#[derive(Component)]
struct Menu();
impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) {
app.add_system_set(SystemSet::on_enter(AppState::Menu).with_system(setup))
.add_system_set(
SystemSet::on_update(AppState::Menu).with_system(keyboard_input_system),
);
.add_system_set(SystemSet::on_update(AppState::Menu).with_system(keyboard_input_system))
.add_system_set(SystemSet::on_exit(AppState::Menu).with_system(despawn));
}
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(Text2dBundle {
text: Text::from_section(
"Press ENTER",
TextStyle {
font: asset_server.get_handle("Cantarell-VF.odt"),
font_size: 64.0,
color: Color::WHITE,
},
)
.with_alignment(TextAlignment::CENTER),
..Default::default()
});
commands
.spawn_bundle(Text2dBundle {
text: Text::from_section(
"Press ENTER",
TextStyle {
font: asset_server.get_handle("Cantarell-VF.otf"),
font_size: 64.0,
color: Color::WHITE,
},
)
.with_alignment(TextAlignment::CENTER),
..Default::default()
})
.insert(Menu());
}
fn despawn(mut commands: Commands, menu_query: Query<Entity, With<Menu>>) {
for entity in menu_query.iter() {
commands.entity(entity).despawn_recursive();
}
}
fn keyboard_input_system(