diff --git a/examples/games/alien_cake_addict.rs b/examples/games/alien_cake_addict.rs index 5ca9ec71b9426..013d71fd6b6f7 100644 --- a/examples/games/alien_cake_addict.rs +++ b/examples/games/alien_cake_addict.rs @@ -2,7 +2,7 @@ use std::f32::consts::PI; -use bevy::{ecs::schedule::SystemSet, prelude::*, time::FixedTimestep}; +use bevy::{ecs::schedule::SystemSet, prelude::*}; use rand::Rng; #[derive(Clone, Eq, PartialEq, Debug, Hash)] @@ -11,9 +11,13 @@ enum GameState { GameOver, } +#[derive(Resource)] +struct BonusSpawnTimer(Timer); + fn main() { App::new() .init_resource::() + .insert_resource(BonusSpawnTimer(Timer::from_seconds(5.0, true))) .add_plugins(DefaultPlugins) .add_state(GameState::Playing) .add_startup_system(setup_cameras) @@ -23,17 +27,13 @@ fn main() { .with_system(move_player) .with_system(focus_camera) .with_system(rotate_bonus) - .with_system(scoreboard_system), + .with_system(scoreboard_system) + .with_system(spawn_bonus), ) .add_system_set(SystemSet::on_exit(GameState::Playing).with_system(teardown)) .add_system_set(SystemSet::on_enter(GameState::GameOver).with_system(display_score)) .add_system_set(SystemSet::on_update(GameState::GameOver).with_system(gameover_keyboard)) .add_system_set(SystemSet::on_exit(GameState::GameOver).with_system(teardown)) - .add_system_set( - SystemSet::new() - .with_run_criteria(FixedTimestep::step(5.0)) - .with_system(spawn_bonus), - ) .add_system(bevy::window::close_on_esc) .run(); } @@ -291,13 +291,17 @@ fn focus_camera( // despawn the bonus if there is one, then spawn a new one at a random location fn spawn_bonus( + time: Res