@@ -34,8 +34,11 @@ const PADDLE_Z: f32 = Z_BACK;
3434const PADDLE_SPRITE_NUM : usize = 0 ;
3535
3636const BALL_RADIUS : f32 = 2.0 ;
37- const BALL_VELOCITY_X : f32 = 25 .0;
37+ const BALL_VELOCITY_X : f32 = 30 .0;
3838const BALL_VELOCITY_Y : f32 = 15.0 ;
39+ const BALL_ACCELERATION : f32 = 0.2 ;
40+ const MAX_BALL_VELOCITY_X : f32 = BALL_VELOCITY_X * 2.0 ;
41+ const MAX_BALL_VELOCITY_Y : f32 = BALL_VELOCITY_Y * 2.0 ;
3942pub const BALL_Z : f32 = Z_BACK ;
4043const BALL_SPRITE_NUM : usize = 1 ;
4144
@@ -88,6 +91,7 @@ pub enum BallState {
8891
8992pub struct Ball {
9093 pub velocity : [ f32 ; 2 ] ,
94+ pub acceleration : f32 ,
9195 pub radius : f32 ,
9296 pub state : BallState ,
9397 pub waiting_time : f32 ,
@@ -99,6 +103,11 @@ impl Ball {
99103 self . waiting_time = 2.0 ;
100104 self . velocity = [ BALL_VELOCITY_X , BALL_VELOCITY_Y ]
101105 }
106+ pub fn accelerate ( & mut self ) {
107+ let velocity_x = ( self . velocity [ 0 ] + ( self . velocity [ 0 ] * self . acceleration ) ) . min ( MAX_BALL_VELOCITY_X ) ;
108+ let velocity_y = ( self . velocity [ 1 ] + ( self . velocity [ 1 ] * self . acceleration ) ) . min ( MAX_BALL_VELOCITY_Y ) ;
109+ self . velocity = [ velocity_x, velocity_y]
110+ }
102111}
103112
104113impl Component for Ball {
@@ -172,6 +181,7 @@ fn initialise_ball(world: &mut World, sprite_sheet_handle: Handle<SpriteSheet>)
172181 . with ( Ball {
173182 radius : BALL_RADIUS ,
174183 velocity : [ BALL_VELOCITY_X , BALL_VELOCITY_Y ] ,
184+ acceleration : BALL_ACCELERATION ,
175185 state : BallState :: Waiting ,
176186 waiting_time : 2.0 ,
177187 } )
0 commit comments