Example 3: Gaming With Pygame - Raspberry Pi User Manual

Hide thumbs Also See for Raspberry Pi:
Table of Contents

Advertisement

162
R A S P B E R R Y P I
U S E R G U I D E 
Save the program as
, and run it by choosing Run Module from the Run
calculator.py
menu in IDLE or by typing
at the terminal . Enter your user name
python calculator.py
when prompted, and then provide the numbers that you want to calculate (see Figure 11-5)
until you get bored and type anything other than 1 to exit the program .
Figure 11-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 .

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents