diff --git a/src/drops.rs b/src/drops.rs index 6b93ffc..fc919e9 100644 --- a/src/drops.rs +++ b/src/drops.rs @@ -1,13 +1,14 @@ use bevy::{ prelude::*, sprite::{MaterialMesh2dBundle, Mesh2dHandle}, - utils::HashSet, + utils::{Duration, HashSet}, }; use bevy_rand::prelude::*; use bevy_rapier2d::prelude::*; use rand::Rng; use crate::{ + game_state::GameTimer, player::{LifeChangeEvent, Player}, scene::SceneObj, GameState, GameplaySet, METER, @@ -29,6 +30,7 @@ pub fn spawner_plugin(app: &mut App) { .add_event::() .add_event::() .add_systems(OnEnter(GameState::InGame), add_timer.in_set(GameplaySet)) + .add_systems(OnExit(GameState::InGame), cleanup.in_set(GameplaySet)) .add_systems( Update, ( @@ -37,13 +39,65 @@ pub fn spawner_plugin(app: &mut App) { crate_collisions, delete_on_env_coll, player_coll, + update_timer_for_difficulty, ) .in_set(GameplaySet), ); } +fn cleanup( + timer: Query>, + crates: Query>, + mut commands: Commands, +) { + commands.entity(timer.single()).despawn(); + for e in &crates { + commands.entity(e).despawn(); + } +} + fn add_timer(mut commands: Commands) { - commands.spawn(SpawnTimer(Timer::from_seconds(2., TimerMode::Repeating))); + commands.spawn(SpawnTimer(Timer::from_seconds(0.2, TimerMode::Repeating))); +} + +fn update_timer_for_difficulty( + mut spawn_timer: Query<&mut SpawnTimer>, + mut game_timer: Query<&mut GameTimer>, + time: Res