www.NewsDownload.co.uk Page 32

Raspberry Pi Python Asteroids Game

2016-11-09 18:00 By Jason Birch

Open Source Python Game for the Raspberry Pi. An example of how to write a game using classes in Python scripting language.

VIDEO
The video here demonstrates the project which this article describes.

The article breaks the project down into several stages:

  • Background
  • Configuring the OS
  • Source Code

Reference:

Background
This Python game has been created to provide coding comparisons between various programming languages and platforms. Examples of the same source code on Windows, Linux, Android, using C++, JavaScript, Java, DirectX, can be found on this site here: Coding a Technology

The JavaScript example can be played in the web page.



Configuring the OS
I have tried this game on the Raspberry Pi OS Raspbian.

When playing the game, press 'Enter' to start a new game. Use the cursor keys to rotate left and right. Left 'Ctrl' key to shoot, left 'Alt' key to thrust and 'Space bar' to hyper space. Press the 'Esc' key to exit the game.

Install the game by typing the at the command line:

# Get the game source code.
cd ~
wget https://github.com/BirchJD/AsteroidsPi/archive/master.zip
unzip master.zip

# Start the game.
cd ~/AsteroidsPi-master
./Asteroids.py

Source Code


Download the source code here.

The Github repository can be found here.


The application for the project consists of the following files:

GNU-GeneralPublicLicense.txt
   - User license agreement.
Asteroids.py
   - The main application script.
AstroShip.py
   - The players ship object, which can rotate,
     thrust, shoot and hyperspace.
AstroShot.py
   - An object representing a shot, the same
     object is used for the player ship
     shooting and the UFO shooting.
AstroRock.py
   - The object used to represent a rock of any
     size in the game.
AstroUFO.py
   - UFO enemy object, which can shoot.
Common.py
   - Values and functions shared common to
     many areas of the program. 
Text.py
   - Line drawing text to the display.
Number.py
   - Line drawing numbers to the display.


The application then has one directory of support files:

Sounds
   - Directory containing the audio files for
     the game.


Loading...