From 3c235f5ca9515bdf31a1b50b1e6b992098f8287e Mon Sep 17 00:00:00 2001 From: Henauxg <19689618+Henauxg@users.noreply.github.com> Date: Tue, 11 Jul 2023 19:00:13 +0200 Subject: [example:breakout] Update to bevy 0.11 --- examples/breakout/breakout.rs | 41 +++++++++++++++++++++++++---------------- examples/breakout/client.rs | 38 ++++++++++++++++---------------------- examples/breakout/server.rs | 1 - 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/examples/breakout/breakout.rs b/examples/breakout/breakout.rs index 0ac79ed..5a51756 100644 --- a/examples/breakout/breakout.rs +++ b/examples/breakout/breakout.rs @@ -65,7 +65,7 @@ pub enum GameSystems { #[derive(Component, Deref, DerefMut)] struct Velocity(Vec2); -#[derive(Default)] +#[derive(Default, Event)] struct CollisionEvent; #[derive(Component)] @@ -118,9 +118,11 @@ fn server_is_listening(server: Res) -> bool { fn main() { let mut app = App::new(); - app.add_plugins(DefaultPlugins) - .add_plugin(QuinnetServerPlugin::default()) - .add_plugin(QuinnetClientPlugin::default()); + app.add_plugins(( + DefaultPlugins, + QuinnetServerPlugin::default(), + QuinnetClientPlugin::default(), + )); app.add_event::(); app.add_state::(); app.insert_resource(ClearColor(BACKGROUND_COLOR)) @@ -131,34 +133,41 @@ fn main() { .insert_resource(client::BricksMapping::default()); // ------ Main menu - app.add_system(bevy::window::close_on_esc) - .add_system(client::setup_main_menu.in_schedule(OnEnter(GameState::MainMenu))) - .add_system(client::handle_menu_buttons.in_set(OnUpdate(GameState::MainMenu))) - .add_system(client::teardown_main_menu.in_schedule(OnExit(GameState::MainMenu))); + app.add_systems(Update, bevy::window::close_on_esc) + .add_systems(OnEnter(GameState::MainMenu), client::setup_main_menu) + .add_systems( + Update, + client::handle_menu_buttons.run_if(in_state(GameState::MainMenu)), + ) + .add_systems(OnExit(GameState::MainMenu), client::teardown_main_menu); // ------ Hosting a server on a client app.add_systems( - (server::start_listening, client::start_connection) - .in_schedule(OnEnter(GameState::HostingLobby)), + OnEnter(GameState::HostingLobby), + (server::start_listening, client::start_connection), ) .add_systems( + Update, ( server::handle_client_messages, server::handle_server_events, client::handle_server_messages, ) - .in_set(OnUpdate(GameState::HostingLobby)), + .run_if(in_state(GameState::HostingLobby)), ); // ------ or just Joining as a client - app.add_system(client::start_connection.in_schedule(OnEnter(GameState::JoiningLobby))) - .add_system(client::handle_server_messages.in_set(OnUpdate(GameState::JoiningLobby))); + app.add_systems(OnEnter(GameState::JoiningLobby), client::start_connection) + .add_systems( + Update, + client::handle_server_messages.run_if(in_state(GameState::JoiningLobby)), + ); // ------ Running the game. // ------ Every app is a client - app.add_system(client::setup_breakout.in_schedule(OnEnter(GameState::Running))); - app.edit_schedule(CoreSchedule::FixedUpdate, |schedule| { + app.add_systems(OnEnter(GameState::Running), client::setup_breakout); + app.edit_schedule(FixedUpdate, |schedule| { schedule.configure_set(GameSystems::ClientSystems.run_if(in_state(GameState::Running))); schedule.add_systems( ( @@ -173,7 +182,7 @@ fn main() { }); // ------ But hosting apps are also a server - app.edit_schedule(CoreSchedule::FixedUpdate, |schedule| { + app.edit_schedule(FixedUpdate, |schedule| { schedule.configure_set( GameSystems::HostSystems .run_if(in_state(GameState::Running)) diff --git a/examples/breakout/client.rs b/examples/breakout/client.rs index e418757..88aeedc 100644 --- a/examples/breakout/client.rs +++ b/examples/breakout/client.rs @@ -2,16 +2,15 @@ use std::collections::HashMap; use bevy::{ prelude::{ - default, AssetServer, Audio, BuildChildren, Bundle, Button, ButtonBundle, Camera2dBundle, - Changed, Color, Commands, Component, DespawnRecursiveExt, Entity, EventReader, EventWriter, - Input, KeyCode, Local, NextState, PlaybackSettings, Query, Res, ResMut, Resource, - TextBundle, Transform, Vec2, Vec3, With, Without, + default, AssetServer, AudioBundle, BuildChildren, Bundle, Button, ButtonBundle, + Camera2dBundle, Changed, Color, Commands, Component, DespawnRecursiveExt, Entity, + EventReader, EventWriter, Input, KeyCode, Local, NextState, PlaybackSettings, Query, Res, + ResMut, Resource, TextBundle, Transform, Vec2, Vec3, With, Without, }, sprite::{Sprite, SpriteBundle}, text::{Text, TextSection, TextStyle}, ui::{ - AlignItems, BackgroundColor, Interaction, JustifyContent, PositionType, Size, Style, - UiRect, Val, + AlignItems, BackgroundColor, Interaction, JustifyContent, PositionType, Style, UiRect, Val, }, }; use bevy_quinnet::{ @@ -89,7 +88,6 @@ pub(crate) enum MenuItem { // This bundle is a collection of the components that define a "wall" in our game #[derive(Bundle)] struct WallBundle { - #[bundle] sprite_bundle: SpriteBundle, } pub(crate) fn start_connection(mut client: ResMut) { @@ -324,21 +322,19 @@ pub(crate) fn update_scoreboard( } pub(crate) fn play_collision_sound( + mut commands: Commands, mut collision_events: EventReader, - audio: Res