Pong Tutorial using Pygame – Adding a Scoring System

pong-gameThis tutorial is the third tutorial in a series of five Pygame tutorials:

The final stage of our tutorial focuses on adding a scoring system to our Pong game. Player A will score a point if the ball bounces against the right hand side edge of the screen while player B will score a point if the ball bounces against the left hand side edge of the screen. Both scores will be displayed at the top of the screen.

The final code for the main.py is provided below. We made three changes to the code as follows:

  • On lines 43 to 45 we are initialisaing both player scores to 0.
  • On lines 72 to 77 the code detects when one the player scores point.
  • On lines 96 to 101 how the scores are displayed on screen.
main.pypaddle.pyball.py
Share Button
Tagged with: