Hardware Reference
In-Depth Information
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
Search WWH ::




Custom Search