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

PenguinTutor YouTube Channel

Raspberry Pi Pico - space game

In this project I have ported graphical game that I created in Pygame Zero to the Raspberry Pi Pico with a Pimoroni Pico Explorer.

Raspberry Pi Pico Space Game - created in micropython

See an explanation and demonstration in the video below:

It’s a simple space game where a spacecraft flies through an asteroid field. You can fire the asteroids out of the way. This is based on a game that I created for my book: Beginning Game Programming with Pygame Zero.

Note that Pimoroni have updated their graphics library. See the following for more details: Raspberry Pi Pico Display tank game.

Pico Explorer Base

Raspberry Pi Pico Explorer Board (used for game programming)

The Pico Explorer Base is a board with space for a Raspberry Pi Pico (with pins headers soldered protoducing into the reverse side) along with some breakout connectors, a small breadboard and an IPS LCD display with 4 buttons.

Pico Sprite and Vector Based Game Programming

To create the sprites then I've implemented a simplified version of the Pygame Zero Actor class. This creates a sprite (known as an actor) from a bitmap image. The sprite has a draw method which shows the sprite on the screen. It can be moved around the screen using x and y co-ordinates and can be rotated to face a different direction. I've already provided more information on creating sprites on the Raspberry Pi Pico.

For the Asteroids I used vector based images. These use the shape commands included in the Pimoroni display libraries. This uses circles for the asteroids and individual pixels for the shots. To understand these in more details see my guide to vector based images on the Pico based on the Tank Game I made previously.

Download code for Micropython Pico game

Download the source code below:

Summary

This has shown that it is possible to create a full game using micropython along with object oriented programming. It does however have limitations in terms of performance due to the capability of the Pico.

If you do want to get the best performance for game programming then you may want to look at using C or perhaps reducing the object-oriented hierarchy. This would be a trade off between easy to program and understand versus performance.

Another thing that this can be used for would be creating an interface to an electronics project where you wanted a graphical display. This would not necessarily need the same performance as a game would so may be a better fit. This would be similar to something I’ve done previously in my pygame Zero for makers which I created as a workshop.

Future projects

For the latest updates please:
Subscribe to the PenguinTutor YouTube Channel
and
Follow @penguintutor on Twitter

Previous Raspberry Pi Pico Tank Game
Raspberry Pi Pico Tank Game
Next PGZ Animation library
PGZ Animation library