Skip to content

Commit

Permalink
disable game logic in pause state
Browse files Browse the repository at this point in the history
  • Loading branch information
sim82 committed Dec 9, 2023
1 parent 66b5ab8 commit e17ecf3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/droid/ai.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::player::PlayerMarker;
use crate::prelude::*;
use crate::weapon::PROJECTILE_SPEED;
use crate::{droid::WeaponState, weapon::Projectile};
use bevy::{
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)),
);
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/droid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
}
}
8 changes: 6 additions & 2 deletions src/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
}
}
14 changes: 14 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -79,14 +80,27 @@ fn auto_start_system(
next_state.set(GameState::Game);
}
}
fn startup_system(mut rapier_config: ResMut<RapierConfiguration>) {
rapier_config.physics_pipeline_active = false;
}
fn enter_game_state(mut rapier_config: ResMut<RapierConfiguration>) {
rapier_config.physics_pipeline_active = true;
}

fn exit_game_state(mut rapier_config: ResMut<RapierConfiguration>) {
rapier_config.physics_pipeline_active = false;
}

pub struct StatePlugin;

impl Plugin for StatePlugin {
fn build(&self, app: &mut App) {
app.add_state::<GameState>()
.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)),
Expand Down

0 comments on commit e17ecf3

Please sign in to comment.