Editor

Aim with the paddle

Pygame challenges · Bounce, step 3 of 3 · 20 XP

Every hit sends the ball back flat, so the computer always reaches it.

Your task

Write paddle_angle(ball_center, paddle_center, paddle_half). It says where the ball hit the paddle: -1 at one end, 0 in the middle and 1 at the other end, so (ball_center - paddle_center) / paddle_half. A ball that clips the very end can give more than 1, so keep the answer between -1 and 1 with your clamp.

The game multiplies it by 5 to get the ball's new slope: hit with the edge of your paddle to send it steep.

The function is at the top of the program, marked fix this. Press Run to play the game as it is, then Check when your function is ready.

What Check tests

CallShould give
the middle is 0paddle_angle(100, 100, 30)0
halfway down is 0.5paddle_angle(115, 100, 30)0.5
the top end is -1paddle_angle(70, 100, 30)-1
past the end is still 1paddle_angle(140, 100, 30)1