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 ## Build

View file

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

View file

@ -3,10 +3,8 @@ mod menu;
use bevy::{ use bevy::{
core_pipeline::clear_color::ClearColorConfig, core_pipeline::clear_color::ClearColorConfig,
input::{keyboard::KeyCode, Input},
prelude::*, prelude::*,
render::settings::{WgpuFeatures, WgpuSettings}, render::settings::{WgpuFeatures, WgpuSettings},
sprite::MaterialMesh2dBundle,
}; };
use bevy_fundsp::prelude::*; use bevy_fundsp::prelude::*;
use bevy_hanabi::*; use bevy_hanabi::*;
@ -14,7 +12,6 @@ use bevy_rapier2d::prelude::*;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
enum AppState { enum AppState {
Setup,
Menu, Menu,
Game, Game,
} }
@ -42,7 +39,6 @@ fn setup(
mut commands: Commands, mut commands: Commands,
mut dsp_manager: ResMut<DspManager>, mut dsp_manager: ResMut<DspManager>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut app_state: ResMut<State<AppState>>,
) { ) {
let _font: Handle<Font> = asset_server.load("Cantarell-VF.otf"); let _font: Handle<Font> = asset_server.load("Cantarell-VF.otf");
@ -57,6 +53,4 @@ fn setup(
brightness: 0.6, brightness: 0.6,
}); });
dsp_manager.add_graph(game::sine_wave, 1.0); 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::{ use bevy::{
input::{keyboard::KeyCode, Input}, input::{keyboard::KeyCode, Input},
prelude::*, prelude::*,
sprite::MaterialMesh2dBundle,
}; };
pub struct MenuPlugin; pub struct MenuPlugin;
#[derive(Component)]
struct Menu();
impl Plugin for MenuPlugin { impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_system_set(SystemSet::on_enter(AppState::Menu).with_system(setup)) app.add_system_set(SystemSet::on_enter(AppState::Menu).with_system(setup))
.add_system_set( .add_system_set(SystemSet::on_update(AppState::Menu).with_system(keyboard_input_system))
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>) { fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(Text2dBundle { commands
text: Text::from_section( .spawn_bundle(Text2dBundle {
"Press ENTER", text: Text::from_section(
TextStyle { "Press ENTER",
font: asset_server.get_handle("Cantarell-VF.odt"), TextStyle {
font_size: 64.0, font: asset_server.get_handle("Cantarell-VF.otf"),
color: Color::WHITE, font_size: 64.0,
}, color: Color::WHITE,
) },
.with_alignment(TextAlignment::CENTER), )
..Default::default() .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( fn keyboard_input_system(