From e17ecf3a851219791e150493e812275cd8e7a486 Mon Sep 17 00:00:00 2001 From: "Simon A. Berger" Date: Sat, 9 Dec 2023 13:09:37 +0100 Subject: [PATCH] disable game logic in pause state --- src/droid/ai.rs | 10 +++++++--- src/droid/mod.rs | 12 +++++++++--- src/ship.rs | 8 ++++++-- src/state.rs | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/droid/ai.rs b/src/droid/ai.rs index 909e8a4..1e3825c 100644 --- a/src/droid/ai.rs +++ b/src/droid/ai.rs @@ -1,4 +1,5 @@ use crate::player::PlayerMarker; +use crate::prelude::*; use crate::weapon::PROJECTILE_SPEED; use crate::{droid::WeaponState, weapon::Projectile}; use bevy::{ @@ -346,7 +347,8 @@ impl Plugin for AiPlugin { ( assault_predict_system, incomping_projectile_evaluation_system, - ), + ) + .run_if(in_state(GameState::Game)), ); // app // // .add_system(movement_update_system) @@ -373,7 +375,8 @@ impl Plugin for AiPlugin { actions::evade_enemy_action_system.in_set(BigBrainSet::Actions), actions::evade_projectile_action_system.in_set(BigBrainSet::Actions), actions::roam_action_system.in_set(BigBrainSet::Actions), - ), + ) + .run_if(in_state(GameState::Game)), ); app.add_systems( PreUpdate, @@ -382,7 +385,8 @@ impl Plugin for AiPlugin { scorers::projectile_incoming_score_system.in_set(BigBrainSet::Scorers), scorers::enemy_close_system.in_set(BigBrainSet::Scorers), scorers::idle_boredom_score_system.in_set(BigBrainSet::Scorers), - ), + ) + .run_if(in_state(GameState::Game)), ); } } diff --git a/src/droid/mod.rs b/src/droid/mod.rs index eb82300..94d0ef1 100644 --- a/src/droid/mod.rs +++ b/src/droid/mod.rs @@ -263,8 +263,14 @@ impl Plugin for DroidPlugin { fn build(&self, app: &mut App) { app // .add_system(droid_stop_system) - .add_systems(Update, droid_apply_direction_system) //.after(droid_stop_system)) - .add_systems(Update, droid_attack_system) - .add_systems(Update, droid_overload_system); + .add_systems( + Update, + ( + droid_apply_direction_system, //.after(droid_stop_system)) + droid_attack_system, + droid_overload_system, + ) + .run_if(in_state(GameState::Game)), + ); } } diff --git a/src/ship.rs b/src/ship.rs index ef00686..b419243 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -409,8 +409,12 @@ impl Plugin for ShipPlugin { ship_thruster_system.after(ship_brake_maneuver_system), ship_attack_system, ship_thruster_particle_system.after(ship_thruster_system), - ), + ) + .run_if(in_state(GameState::Game)), ) - .add_systems(PostUpdate, ship_attach_thruster_particle_spawner_system); + .add_systems( + PostUpdate, + ship_attach_thruster_particle_spawner_system.run_if(in_state(GameState::Game)), + ); } } diff --git a/src/state.rs b/src/state.rs index 5f28792..5fd8c4a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy_rapier2d::plugin::RapierConfiguration; // if true, GameState::None will automatically switch through to GameState::Game // can be used for restarting game. @@ -79,6 +80,16 @@ fn auto_start_system( next_state.set(GameState::Game); } } +fn startup_system(mut rapier_config: ResMut) { + rapier_config.physics_pipeline_active = false; +} +fn enter_game_state(mut rapier_config: ResMut) { + rapier_config.physics_pipeline_active = true; +} + +fn exit_game_state(mut rapier_config: ResMut) { + rapier_config.physics_pipeline_active = false; +} pub struct StatePlugin; @@ -86,7 +97,10 @@ impl Plugin for StatePlugin { fn build(&self, app: &mut App) { app.add_state::() .insert_resource(AutoStart(false)) + .add_systems(Startup, startup_system) .add_systems(PreUpdate, auto_start_system) + .add_systems(OnEnter(GameState::Game), enter_game_state) + .add_systems(OnExit(GameState::Game), exit_game_state) .add_systems( Last, game_despawn_reaper_system.run_if(in_state(GameState::Game)),