@@ -151,9 +151,9 @@ impl Game {
151
151
152
152
let buttons = io:: controller_buttons ( ) ;
153
153
154
- if buttons & io:: Left != 0 && self . paddle . x > 1 {
154
+ if buttons & io:: LEFT != 0 && self . paddle . x > 1 {
155
155
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 {
157
157
self . paddle . x += 2 ;
158
158
}
159
159
@@ -189,7 +189,7 @@ impl Game {
189
189
let hit_bottom = dist_bottom < r;
190
190
191
191
if hit_left || hit_right {
192
- self . ball . dx = -self . ball . dx ;
192
+ // self.ball.dx = -self.ball.dx;
193
193
}
194
194
if hit_top || hit_bottom {
195
195
self . ball . dy = -self . ball . dy ;
@@ -214,16 +214,20 @@ impl Game {
214
214
self . ball . dx = -self . ball . dx ;
215
215
apu:: play_sfx ( apu:: Sfx :: Lock ) ;
216
216
}
217
- if self . ball . y == 0 || self . ball . y + BALL_DIAMETER >= HEIGHT {
217
+ if self . ball . y == 0 {
218
218
self . ball . dy = -self . ball . dy ;
219
219
apu:: play_sfx ( apu:: Sfx :: Lock ) ;
220
220
}
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
+ }
221
232
}
222
233
}
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