To build our game, we will use the Pygame library, which provides a set of readymade functionality that we can use to build Pong and its animations.
Today, we will be using Replit to build the Pong game.
If you would like a recap on how to use Replit, check out our Python basics tutorial.
Now, let’s go through some of the code that has been provided to you in the
Libraries and import statements
Look at the top of the code. You will see the following line:
This statement allows us to import all of the animation and object-drawing functionality provided by the
pygame library. A library is a place where related functionality is grouped together for use in the Python language. For example, the
pygame library provides a way to draw a rectangle on screen, which we can use to draw the boundaries, the ball, and the paddles used in Pong game.
The gray line that starts with a
# is called a comment. These are notes in the code that help to explain what the code does in normal English. Comments are ignored by the computer; developers use comments to communicate with each another, especially when several developers are working on the same code. Comments also allow someone who is looking at the code to get a high-level overview of what is happening without having to read all of the code.
main.py we use comments throughout to indicate where changes to the code are required.