1 of 16

Making Games with Python: Pygame Zero

2 of 16

What are we making today?

3 of 16

4 of 16

5 of 16

Like its predecessor, Pygame, but modernised, and simplified.

6 of 16

Unix is made of lots of small programs… all wired together

7 of 16

pip install pgzero

pip3 install pgzero

💡 If you haven’t got pip or pip3 (you should) then https://pip.pypa.io/en/stable/installation/

Before we start… python2 and python3 ways to install PyGameZero

Also… what even is python?

other package managers exist, conda, poetry, npm, brew,

8 of 16

A Warning From The Future

just learn 2 lines of code!!!

9 of 16

Four Ways To Code With PyGame Zero

Make a copy of this template. It contains images, font, and sounds folders with files already created. The main.py is the one that runs. The space_invaders.py is completed code.

Note: Sounds won't work.

Terminal / Powershell

Visual Studio Code

(VS Code)

an IDE

(Integrated Development Environment)

Repl.it (online)

A great IDE for beginners with a pgzero built-in mode

10 of 16

Get the example files are here:

sessions_games.zip includes 3 example games.py files and the images,sounds and font used in the games for this session.

Also get some documentation open.

11 of 16

import pgzrun

WIDTH = 800

HEIGHT = 600

text = "Hello World!"

def draw():

screen.clear()

screen.fill((50, 40, 70))

screen.draw.text(text, (20, 20), fontsize=40, color="lime")

pgzrun.go()

12 of 16

Let’s look at intro.py

A more fleshed out version of a game that has…

  • Images
  • A sound
  • Movement
  • Handles mouse-clicks

13 of 16

Let’s look at space_invaders.py

14 of 16

Next Steps … better games, tutorials.

An excellent few game tutorials (with graphics packs to download too)

I like this tutorial as it goes through each step AND gives you graphics to work with.

15 of 16

More Learning Resources

Go try tutorials or find game examples and tweak them, subvert them to learn how it works and build your coding skills.

16 of 16

Other ways to make games, previous Digital Wednesdays…