Hello!
I've finished the pong tutorial from the official documentation over the weekend and it was a good exercise! I got the game working and all, but there was one thing I didn't quite understand, and it's how the direction.y
is being calculated. Here is the code from the tutorial:
# Flip, change direction and increase speed when touching pads
if ((left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)):
direction.x = -direction.x
direction.y = randf()*2.0 - 1
direction = direction.normalized()
ball_speed *= 1.1
I'm assuming randf()
generates a random float number between 0 and 1, but why is there the *2.0-1
part? And how is the result of that being translated into a direction? Shouldn't it be a number between 1-360, representing angle degrees?