Python: let’s make a game (Pygame zero)

Making a game with pygame zero


Pygame zero is a very interesting project that allows to use the pygame module in an easy way, so that you can concentrate on the logic of the game, instead of a long learning process that may discourage the users from creating a game. It’s a good tool to introduce to computer logic, I think, through games, but it is also very powerful, as you will check by yourself, looking at the examples of games made with Pygame zero.


In this video I will tell you how to start making a game with pygame zero. First you have to install the modules and then with a couple of line you can see something moving on the screen. Really nice way to start learning how to make a videogame.

How to install pgzero

To install pygame zero or pgzero, in the cmd (windows button + r and then ‘cmd’) write:

This way you will install also pygame and other modules that pgzero uses.

To run the code you have to write:

where is the name of the file you created.

Run the code from Sublime or IDLE

If you want to start the program from an IDE (or from sublimeRepl) you have to import pgzrun as the first line of code and write at the last line of code pgzrun.go() like in the following example.

There it is… a circle!

Pygame zero: how to make a window (previous post about this topic)

Move that circle

We could make that circle move… using pygame too, why not? Here’s the code where we can move the circle moving the mouse… just a couple of lines and the use of

  • pygame.mouse.get_pos()
    • to get x and y position of the mouse
    • and the use them to move the center of the circle making it follow the mouse
  • pygame.mouse.set_visible(False)
    • to hide the mouse curso (if you want)

Remember you have to import pygame.


Video nr. 1: make an alien move

Let’s start making a sprite move on the screen


Video nr. 2: recap

Let’s recap what we’ve done.

Video nr. 3: adding interaction

When we click on the alien we will get a +1, when we click on the ‘space’ we get a -1.


Video nr. 4: adding animation

We add a an animation when we hit the alien.


Video nr. 5: perfecting the animation

Here we make a better animation using the clock…


Pygame zero: another example

The repository of Pygame zero

If you want to take a look at the code and to many examples of pygame zero go and download the repository here:

An entire videogame with pythonista on the ipad

You may be interested in making a game with python on the Ipad. Go check this series of posts and videos I made recently (2019).

Pythonista games

More… on Python games on ipad

My Playlist n.1 on Youtube about Pythonista game on the Ipad

My Playlist n.2 on Youtube about Pythonista game on the Ipad (in progress)

My playlist on last pygame videos