diff --git a/examples/games/breakout.rs b/examples/games/breakout.rs index d74822872f6a31..206da2fe4aa50c 100644 --- a/examples/games/breakout.rs +++ b/examples/games/breakout.rs @@ -6,9 +6,6 @@ use bevy::{ sprite::MaterialMesh2dBundle, }; -// Defines the amount of time that should elapse between each physics step. -const TIME_STEP: f32 = 1.0 / 60.0; - // These constants are defined in `Transform` units. // Using the default 2D camera they correspond 1:1 with screen pixels. const PADDLE_SIZE: Vec3 = Vec3::new(120.0, 20.0, 0.0); @@ -70,7 +67,7 @@ fn main() { .in_schedule(CoreSchedule::FixedUpdate), ) // Configure how frequently our gameplay systems are run - .insert_resource(FixedTime::new_from_secs(TIME_STEP)) + .insert_resource(FixedTime::new_from_secs(1.0 / 60.0)) .add_system(update_scoreboard) .add_system(bevy::window::close_on_esc) .run(); @@ -315,6 +312,7 @@ fn setup( fn move_paddle( keyboard_input: Res>, mut query: Query<&mut Transform, With>, + time_step: Res, ) { let mut paddle_transform = query.single_mut(); let mut direction = 0.0; @@ -328,7 +326,8 @@ fn move_paddle( } // Calculate the new horizontal paddle position based on player input - let new_paddle_position = paddle_transform.translation.x + direction * PADDLE_SPEED * TIME_STEP; + let new_paddle_position = + paddle_transform.translation.x + direction * PADDLE_SPEED * time_step.period.as_secs_f32(); // Update the paddle position, // making sure it doesn't cause the paddle to leave the arena @@ -338,10 +337,10 @@ fn move_paddle( paddle_transform.translation.x = new_paddle_position.clamp(left_bound, right_bound); } -fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>) { +fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>, time_step: Res) { for (mut transform, velocity) in &mut query { - transform.translation.x += velocity.x * TIME_STEP; - transform.translation.y += velocity.y * TIME_STEP; + transform.translation.x += velocity.x * time_step.period.as_secs_f32(); + transform.translation.y += velocity.y * time_step.period.as_secs_f32(); } }