From 358f31e9b0bab69292e191614c3279e2b81b0a95 Mon Sep 17 00:00:00 2001 From: Julia Naomi Date: Sun, 10 Dec 2023 00:06:02 -0600 Subject: [PATCH] harden-by-multiple-areas --- src/global_task/collect_sheep_in_area.rs | 1 + src/global_task/mod.rs | 8 +-- src/global_task/sheep_escape.rs | 75 ++++++++++++--------- src/global_task/wolf_attack.rs | 1 + src/level_ui.rs | 86 ++++++++++++------------ src/lib.rs | 2 +- src/physics.rs | 2 +- src/player.rs | 2 +- src/safe_area.rs | 78 +++++++++++---------- src/sheep.rs | 19 ++---- src/shepherd.rs | 2 +- src/storyteller.rs | 52 ++++++-------- src/sunday.rs | 39 +++++++++++ src/test_level.rs | 2 +- src/torch.rs | 1 - src/wolf.rs | 2 +- 16 files changed, 204 insertions(+), 168 deletions(-) diff --git a/src/global_task/collect_sheep_in_area.rs b/src/global_task/collect_sheep_in_area.rs index e69de29..8b13789 100644 --- a/src/global_task/collect_sheep_in_area.rs +++ b/src/global_task/collect_sheep_in_area.rs @@ -0,0 +1 @@ + diff --git a/src/global_task/mod.rs b/src/global_task/mod.rs index 8f15d5b..128efc5 100644 --- a/src/global_task/mod.rs +++ b/src/global_task/mod.rs @@ -1,5 +1,5 @@ -pub mod sheep_escape; pub mod collect_sheep_in_area; +pub mod sheep_escape; pub mod wolf_attack; use bevy::prelude::*; @@ -8,8 +8,6 @@ pub struct GlobalTaskPlugin; impl Plugin for GlobalTaskPlugin { fn build(&self, app: &mut App) { - app.add_plugins(( - sheep_escape::SheepEscapePlugin, - )); + app.add_plugins((sheep_escape::SheepEscapePlugin,)); } -} \ No newline at end of file +} diff --git a/src/global_task/sheep_escape.rs b/src/global_task/sheep_escape.rs index 4d34d85..99976d8 100644 --- a/src/global_task/sheep_escape.rs +++ b/src/global_task/sheep_escape.rs @@ -1,22 +1,28 @@ use bevy::prelude::*; use rand::Rng; -use crate::{storyteller::{Storyteller, GlobalTask, FailReason}, sunday::{DayState, EpisodeTime}, sheep::{Sheep, IsScared, GoTo, IdleFeeding, Decision}, player::Dog, test_level::LevelSize, GameSet, GameState, level_ui::TaskText}; +use crate::{ + level_ui::TaskText, + player::Dog, + sheep::{Decision, GoTo, IdleFeeding, IsScared, Sheep}, + storyteller::{FailReason, GlobalTask, Storyteller}, + sunday::{DayState, EpisodeTime}, + test_level::LevelSize, + GameSet, GameState, +}; pub struct SheepEscapePlugin; - impl Plugin for SheepEscapePlugin { fn build(&self, app: &mut App) { - app - .add_systems(OnEnter(GlobalTask::SheepEscape), generate_new_wave) - .add_systems(Update, - ( - apply_deferred, - check_wave_finish, - wave_executor, - ).chain().run_if(in_state(GlobalTask::SheepEscape)).in_set(GameSet::Playing)) - + app.add_systems(OnEnter(GlobalTask::SheepEscape), generate_new_wave) + .add_systems( + Update, + (apply_deferred, check_wave_finish, wave_executor) + .chain() + .run_if(in_state(GlobalTask::SheepEscape)) + .in_set(GameSet::Playing), + ) .init_resource::() .init_resource::(); } @@ -37,23 +43,22 @@ pub struct SheepWave { #[derive(Resource, Default)] pub struct SheepWaveStatus { - pub start_count : usize, - pub sheep : Vec + pub start_count: usize, + pub sheep: Vec, } fn check_wave_finish( mut commands: Commands, - escapers : Query, With)>, - sheep : Query<&Sheep>, - mut global_task : ResMut>, - mut sheep_wave_status : ResMut, - mut game_state : ResMut>, - next_wave : Res, - mut info_texts : Query<&mut Text, With>, + escapers: Query, With)>, + sheep: Query<&Sheep>, + mut global_task: ResMut>, + mut sheep_wave_status: ResMut, + mut game_state: ResMut>, + next_wave: Res, + mut info_texts: Query<&mut Text, With>, ) { let loose_limit = (sheep_wave_status.start_count / 2).max(10); if escapers.is_empty() && next_wave.0.is_none() && sheep_wave_status.start_count != 0 { - let mut alived_sheep = 0; for e in &sheep_wave_status.sheep { if sheep.get(*e).is_ok() { @@ -63,7 +68,9 @@ fn check_wave_finish( info!("WAVE FINISHED"); if sheep_wave_status.start_count - alived_sheep > loose_limit { - commands.insert_resource(FailReason::TaskFailed("Half of the runaway sheep were eaten :(".to_string())); + commands.insert_resource(FailReason::TaskFailed( + "Half of the runaway sheep were eaten :(".to_string(), + )); game_state.set(GameState::Finish); global_task.set(GlobalTask::None); } else { @@ -82,22 +89,24 @@ fn check_wave_finish( } } else if sheep_wave_status.start_count != 0 { for mut t in info_texts.iter_mut() { - t.sections[0].value = format!("{} sheep are trying to escape! Stop them! Dont lose more than {}", escapers.iter().count(), loose_limit); + t.sections[0].value = format!( + "{} sheep are trying to escape! Stop them! Dont lose more than {}", + escapers.iter().count(), + loose_limit + ); } } } fn generate_new_wave( - mut commands: Commands, time: Res