Book Image

Instant Pygame for Python Game Development How-to

By : Ivan Idris
Book Image

Instant Pygame for Python Game Development How-to

By: Ivan Idris

Overview of this book

<p>Pygame is a library created to make multimedia software documenting easy to design. It adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the Python language. Pygame comes with functions and tools that will help you create a great user experience."Instant Pygame for Python Game Development How-to" is written in a concise and result-oriented format. Leading you through practical recipes, you'll find that this essential reference guide helps you to create visually appealing and thrilling games with a few clicks.This book starts with the basic instructions to install Pygame on different servers. It then goes into creating a sample game and explaining the features of drawing, animating, using fonts and Matplotlib with Pygame. The book then takes you through recipes to get access to some great sound and graphic effects. Giving you the steps to allow you to configure these games on Android and other networks, it ends with a walkthrough of the features of Sprites, OpenGL, and Simulation.</p>
Table of Contents (7 chapters)

Preparing your development environment (Simple)


We will install Python, Pygame, and other software we will need.

Getting ready

Before we install Pygame, we need to have Python installed. On some operating systems Python is already installed. Pygame should be compatible with all Python versions. We will also need the NumPy numerical library. I am the author of two books published by Packt Publishing about NumPy – NumPy Beginner's Guide and NumPy Cookbook. Please refer to these books for more info about NumPy.

How to do it...

  • Installing on Debian and Ubuntu

    Python might be already installed on Debian and Ubuntu, but the development headers are usually not. On Debian and Ubuntu, install python and python-dev with these commands:

    sudo apt-get install python
    sudo apt-get install python-dev
    

    Pygame can be found in the Debian archives http://packages.qa.debian.org/p/pygame.html. We can install NumPy with the following command:

    sudo apt-get install python-numpy
    
  • Installing on Windows

    The Windows Python installer can be found on www.python.org/download. On this website we can also find installers for Mac OS X and source tarballs for Linux, Unix, and Mac OS X.

    From the Pygame website (http://www.pygame.org/download.shtml), we can download the appropriate binary installer for the Python version we are using.

    Download a NumPy installer for Windows from the SourceForge website (http://sourceforge.net/projects/numpy/files/).

  • Installing Python on the Mac

    Python comes preinstalled on Mac OS X. We can also get Python via MacPorts, Fink, or similar projects. We can install for instance the Python 2.6 port by running the following command:

    sudo port install python26
    

    Binary Pygame packages for Mac OS X 10.3 and up can be found on http://www.pygame.org/download.shtml. We can get a NumPy installer from the SourceForge website (http://sourceforge.net/projects/numpy/files/). Download the appropriate .DMG file. Usually the latest one is the best.

  • Installing from source

    Pygame is using the distutils system for compiling and installing. To start installing Pygame with the default options, simply run the following command:

    python setup.py
    

    If you need more information about the available options, type the following command:

    python setup.py help
    

    In order to compile the code, you need to have a compiler for your operating system. Setting this up is beyond the scope of this book. More information about compiling Pygame on Windows can be found on http://pygame.org/wiki/CompileWindows. More information about compiling Pygame on Mac OS X can be found at http://pygame.org/wiki/MacCompile.