@@ -6,6 +6,7 @@ use bevy::{
6
6
} ;
7
7
8
8
/// An implementation of the classic game "Breakout"
9
+ const TIME_STEP : f32 = 1.0 / 60.0 ;
9
10
fn main ( ) {
10
11
App :: build ( )
11
12
. add_plugins ( DefaultPlugins )
@@ -15,7 +16,7 @@ fn main() {
15
16
. add_stage (
16
17
FixedUpdateStage ,
17
18
SystemStage :: parallel ( )
18
- . with_run_criteria ( FixedTimestep :: step ( 1.0 / 60.0 ) )
19
+ . with_run_criteria ( FixedTimestep :: step ( TIME_STEP as f64 ) )
19
20
. with_system ( paddle_movement_system. system ( ) )
20
21
. with_system ( ball_collision_system. system ( ) )
21
22
. with_system ( ball_movement_system. system ( ) ) ,
@@ -62,7 +63,7 @@ fn setup(
62
63
sprite : Sprite :: new ( Vec2 :: new ( 120.0 , 30.0 ) ) ,
63
64
..Default :: default ( )
64
65
} )
65
- . with ( Paddle { speed : 8 .0 } )
66
+ . with ( Paddle { speed : 500 .0 } )
66
67
. with ( Collider :: Paddle )
67
68
// ball
68
69
. spawn ( SpriteBundle {
@@ -72,7 +73,7 @@ fn setup(
72
73
..Default :: default ( )
73
74
} )
74
75
. 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 ( ) ,
76
77
} )
77
78
// scoreboard
78
79
. spawn ( TextBundle {
@@ -194,15 +195,15 @@ fn paddle_movement_system(
194
195
195
196
let translation = & mut transform. translation ;
196
197
// move the paddle horizontally
197
- translation. x += direction * paddle. speed ;
198
+ translation. x += direction * paddle. speed * TIME_STEP ;
198
199
// bound the paddle within the walls
199
200
translation. x = translation. x . min ( 380.0 ) . max ( -380.0 ) ;
200
201
}
201
202
}
202
203
203
204
fn ball_movement_system ( mut ball_query : Query < ( & Ball , & mut Transform ) > ) {
204
205
if let Ok ( ( ball, mut transform) ) = ball_query. single_mut ( ) {
205
- transform. translation += ball. velocity ;
206
+ transform. translation += ball. velocity * TIME_STEP ;
206
207
}
207
208
}
208
209
0 commit comments