Example 3: Gaming With Pygame - Raspberry Pi A User Manual

Hide thumbs Also See for Raspberry Pi A:
Table of Contents

Advertisement

184
P A R T I I I
P R O G R A M M I N G W I T H T H E R A S P B E R R Y P I
Figure 12-5:
Running
calculator.
py in IDLE
For more short programs that introduce important Python concepts, visit the official Python
Simple Programs wiki page at
.
http://wiki.python.org/moin/SimplePrograms

Example 3: Gaming with pygame

To illustrate the power of Python, this example creates a fully functional arcade game based
on the classic game of Snake or Nibbles. To accomplish this, it uses an external Python library
called pygame.
Originally written by Pete Shinners, pygame is a collection of python modules designed to
add new functionality to the language—functionality specifically designed to make it easy to
write a game in Python. Each pygame module provides a function required by a modern
game, including sound, graphics and even networking support. Although it's possible to
write a game in Python without using pygame, it's a lot easier if you take advantage of the
code already written in the pygame library.
Before you can write a pygame program, you need to install the pygame library. If you're
using the recommended Raspbian distribution, this is as simple as typing the following at
the console or terminal:
sudo apt-get install python-pygame

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Raspberry pi b

Table of Contents