Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How do you score a point in pygame?


Asked by Damari Barajas on Dec 10, 2021 FAQ



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:
And,
You probably recognize that displaying a score requires some text, which you want Pygame to draw on the screen. If you think it through, you might realize that it's not very different from rendering a player or loot or a platform on screen. Technically, you could use graphics of numbers and have Pygame display those.
In addition, The game features simple 2D graphics. It consists of two paddles used to return a bouncing ball back and forth across the screen. The score is kept by the numbers at the top of the screen. In this tutorial we are going to recreate a game of Pong using Python and the Pygame library.
Next,
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 initialising 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.
Likewise,
The draw_lives function has five arguments: the display surface, the x and y coordinates to display the lives, the number of lives, and the life_player_image we just created. For the number of lives in total, which is 3, lines 4 – 7 handle the location of each image and blitting them to screen.