Section 4 – draw screen and track the score
So, we know that the ball bounces off the top and bottom of the screen as well as off the paddles. However, if the user misses the ball with the paddle, what happens to the ball? What happens to the player and their score?
In this section of the game, we use the location of the x
coordinates to determine whether the ball is on the screen or it has gone past the paddles and is outside the screen. We use our if
statement to tell the computer what to do. The x axis 0
coordinate is the left-most side of the screen. If the ball's x
value is less than 0
, then the player on the other side (player 2) has scored a point because player 1 failed to block the ball. If you read the lines of code, you will notice that we reset the ball_x
and ball_y
coordinates to the center of the screen so that a new game can start. Copy the next four lines of code to place this logic into the game:
if ball_x <= 0: player2_score += 1 ball_x = int(screen_width...