Skip to content

Commit c02bf1c

Browse files
committed
make physics systems dependent on TIME_STEP
1 parent fb19e10 commit c02bf1c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

examples/game/breakout.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use bevy::{
66
};
77

88
/// An implementation of the classic game "Breakout"
9+
const TIME_STEP: f32 = 1.0 / 60.0;
910
fn main() {
1011
App::build()
1112
.add_plugins(DefaultPlugins)
@@ -15,7 +16,7 @@ fn main() {
1516
.add_stage(
1617
FixedUpdateStage,
1718
SystemStage::parallel()
18-
.with_run_criteria(FixedTimestep::step(1.0 / 60.0))
19+
.with_run_criteria(FixedTimestep::step(TIME_STEP as f64))
1920
.with_system(paddle_movement_system.system())
2021
.with_system(ball_collision_system.system())
2122
.with_system(ball_movement_system.system()),
@@ -62,7 +63,7 @@ fn setup(
6263
sprite: Sprite::new(Vec2::new(120.0, 30.0)),
6364
..Default::default()
6465
})
65-
.with(Paddle { speed: 8.0 })
66+
.with(Paddle { speed: 500.0 })
6667
.with(Collider::Paddle)
6768
// ball
6869
.spawn(SpriteBundle {
@@ -72,7 +73,7 @@ fn setup(
7273
..Default::default()
7374
})
7475
.with(Ball {
75-
velocity: 6.0 * Vec3::new(0.5, -0.5, 0.0).normalize(),
76+
velocity: 400.0 * Vec3::new(0.5, -0.5, 0.0).normalize(),
7677
})
7778
// scoreboard
7879
.spawn(TextBundle {
@@ -194,15 +195,15 @@ fn paddle_movement_system(
194195

195196
let translation = &mut transform.translation;
196197
// move the paddle horizontally
197-
translation.x += direction * paddle.speed;
198+
translation.x += direction * paddle.speed * TIME_STEP;
198199
// bound the paddle within the walls
199200
translation.x = translation.x.min(380.0).max(-380.0);
200201
}
201202
}
202203

203204
fn ball_movement_system(mut ball_query: Query<(&Ball, &mut Transform)>) {
204205
if let Ok((ball, mut transform)) = ball_query.single_mut() {
205-
transform.translation += ball.velocity;
206+
transform.translation += ball.velocity * TIME_STEP;
206207
}
207208
}
208209

0 commit comments

Comments
 (0)