@@ -151,9 +151,9 @@ impl Game {
151151
152152 let buttons = io:: controller_buttons ( ) ;
153153
154- if buttons & io:: Left != 0 && self . paddle . x > 1 {
154+ if buttons & io:: LEFT != 0 && self . paddle . x > 1 {
155155 self . paddle . x -= 2 ;
156- } else if buttons & io:: Right != 0 {
156+ } else if buttons & io:: RIGHT != 0 && self . paddle . x + self . paddle . width * 8 < 0xe0 {
157157 self . paddle . x += 2 ;
158158 }
159159
@@ -189,7 +189,7 @@ impl Game {
189189 let hit_bottom = dist_bottom < r;
190190
191191 if hit_left || hit_right {
192- self . ball . dx = -self . ball . dx ;
192+ // self.ball.dx = -self.ball.dx;
193193 }
194194 if hit_top || hit_bottom {
195195 self . ball . dy = -self . ball . dy ;
@@ -214,16 +214,20 @@ impl Game {
214214 self . ball . dx = -self . ball . dx ;
215215 apu:: play_sfx ( apu:: Sfx :: Lock ) ;
216216 }
217- if self . ball . y == 0 || self . ball . y + BALL_DIAMETER >= HEIGHT {
217+ if self . ball . y == 0 {
218218 self . ball . dy = -self . ball . dy ;
219219 apu:: play_sfx ( apu:: Sfx :: Lock ) ;
220220 }
221+ // paddle collision
222+ if self . ball . y + BALL_DIAMETER >= self . paddle . y {
223+ if self . ball . x > self . paddle . x && self . ball . x + BALL_DIAMETER < self . paddle . x + ( self . paddle . width * 8 ) {
224+ self . ball . dy = -self . ball . dy ;
225+ apu:: play_sfx ( apu:: Sfx :: Lock ) ;
226+ } else {
227+ self . ball . dx = 0 ;
228+ self . ball . dy = 0 ;
229+ apu:: play_sfx ( apu:: Sfx :: Topout ) ;
230+ }
231+ }
221232 }
222233}
223-
224-
225- // // Paddle collision
226- // if self.ball.y >= self.paddle.y && self.ball.y <= self.paddle.y + self.paddle.height &&
227- // self.ball.x >= self.paddle.x && self.ball.x <= self.paddle.x + self.paddle.width {
228- // self.ball.dy = -self.ball.dy;
229- // }
0 commit comments