Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Book: Beginning Game Programming with Pygame Zero

Programming in Pygame Zero on the Raspberry Pi

This is my second professionally published book, published by Apress.

Beginning Game Programming with Pygame Zero on a Raspberry Pi

The is a fun way to learn computer programming by creating computer games. This is designed as a book to give you all the skills you need to start programming your own games, from designing the game, creating the graphics, designing sound effects and programming using Pygame Zero.

See below for more videos demonstrating some of the games

Here is a quick introduction to the main focus for each of the chapters.

Chapter 1 - Creating Computer Games

An introduction to the methodology around programming, creating computer games and the Raspberry Pi.

Chapter 2 - Getting Started with Python

A quick introduction to Python. Designed for those with programming experience from a language other than Python, or as a quick refresher for those that have done some programming in Python before. It introduces the first game which is a text based quiz. This is the only console based game with the rest being designed using Pygame Zero.

Chapter 3 - Pygame Zero

Compass Game created in Pygame Zero

An introduction into what Pygame Zero is, along with an introduction to using the Mu editor with Pygame Zero. Create a first graphical game "Compass Game" and learn about how sprites (Actors) can be animated. Learn how to detect collisions in Pygame Zero.

Chapter 4 - Game Design

This chapter goes outside of purely programming to investigate what makes a game enjoyable. It gives ideas of what to think about when designing a game. The code then looks at making the compass game more enjoyable through a more appropriate timer and adding obstacles.

Chapter 5 - Graphic Design

Designing a car for game programming in Inkscape

To create graphical games then you need to know about how to create the graphics and how to incorporate them into the game. This chapter looks at how you can create graphics using 2D and 3D tools before exporting them for inclusion in a 2D game.

Chapter 6 - Colors*

Understand how colors are represented in a computer and how they are used in Pygame Zero. This creates a color changing bouncing ball animation and a color changing which introduces how to handle mouse events in Pygame Zero.

Chapter 7 - Tank Game Zero

Creating a tank using vector images for Pygame Zero game programming

Create a tank based game using Vector Graphics based around basic shapes. Also learn about creating a shell tragectory and how to introduce gravity into a game.

Chapter 8 - Sound

How to record or make sounds and music for use in games. How to use these to create sound effects or to play background music during the game. This chapter introduces a piano / keyboard style game designed for use with the Raspberry Pi touch screen.

Chapter 9 - Object Oriented Programming

Learn about object oriented programming with Python as a way to make code easier to understand. This creates a matching pairs memory game which you can play against the clock to try and find as many pairs as you can.

Chapter 10 - Artificial Intelligence

Using artificial intelligence for a competitor in a Battleship computer game

How to create computer players with an appropriate level of "intelligence". This looks at the memory game and looks at different techniques that can be used to provide a computer competitor instead of the timer. Also creates a new Battleship game using appropriate artificial intelligence to make the game challenging.

Chapter 11 - Improvements and Debugging

Learn additional techniques in Pygame and Pygame Zero. Look at how to create games for the Raspberry Pi Picade and a quick introduction to joysticks / game controllers. Some tips and trips for debugging, including Rubber Duck Debugging.

After following through the book you should have learnt enough skills to adapt the games or create your own games using Pygame Zero.

Space Shooter game created in Pygame Zero

Pygame Zero videos to accompany the book

Getting started with Pygame Zero

This video provides an introduction to getting started with Pygame Zero, including creating a first window and creating an animated character on the screen.

Creating Vector Images for Computer Games in Pygame Zero

How to create vector images in Pygame Zero. Vector images are created from shapes. This uses rectangles, elipses and polygons to create a tank used in a tank battle game. Two tanks then battle it out creating a trajectory for the shells to try and hit their opponent.

Using Object Oriented Programming (OOP) for Computer Game Programming with Python Pygame Zero

Object Orinented Programming is a useful technique for creating any computer programs. This video shows how those techniques can be applied in Python and Pygame Zero to create a matching pairs memory game.

Creating an Artificial Intelligence (AI) Opponent for Computer Games in Pygame Zero

For many games the enjoyment is in playing against a computer opponent which has the right level of ability. It needs to be difficult enough to provide a challenge without being so difficult you always lose. This looks at some techniques of creating an opponent using simple AI.

This isn't complex machine learning which is often associated with AI as that would most likely make most games too difficult to beat. Instead this looks at how the human plays to look at ways that the computer can mimick the same sort of behaviour.

Part 1 uses the same matching pairs memory as the previous video on object-oriented programming, but creating a computer opponent with different levels of difficulty.

Part 2 looks at how you people play the classic Battleship Game to create a computer opponent that provides a good level of difficulty.

For more information on how to play Pygame Zero games using a USB game controller or joystick see the guide: Using a gamepad or joystick on a Raspberry Pi with Python Pygame Zero

Space Shooter Game

The final game is a Space Shooter game. It combines many of the techniques already learned to create a playable game. The video below gives an explanation for some of the additional features used to create the game.

Video overview of the games in the book

The final video provides an overview showing some of the games that are designed in the book.

Buy the book

You can buy the book direct from Apress. Or from other book sellers. If ordering from an independant seller then quote ISBN 978-1-4842-5649-7.

If you do order through Amazon then please leave a review and let me know what you think. It's very useful to have feedback when working on future books.

Other books

Notes:

* Note the American spelling of color rather than the Britsh English spelling colour which is what I normally use on this website. I live in the United Kingdom and so use British English on my website. The book is however published by an American publisher so has been written using American English for most of the spellings. The code is exactly the same (many programming languages are created using American English, although in some cases Python can be either British or American spellings). Other than a few words spelt differently in the text this is suitable for anyone speaking any variant of English.

Future projects

I've always working on new projects
To find out about the updates please:
Subscribe to the PenguinTutor YouTube Channel
and
Follow @penguintutor on Twitter

Previous Books on Linux, RPi and Electronics
Books on Linux, RPi and Electronics
Next Learn Electronics with Raspberry Pi Book
Learn Electronics with Raspberry Pi Book