Chapter 1. Instant Pygame for Python Game Development How-to

Welcome to Pygame for Python Game Development How-to. This book is for developers who want to create games with Pygame quickly and easily and get familiar with the important aspects of it. The typical things you would learn are as follows:

  • Pygame basics
  • Sprites
  • OpenGL

Pygame is part of the Python framework, originally written by Pete Shinners, that as its name suggests can be used to create video games. Pygame is free and open source since 2004 and licensed under the GPL license, which means that you are allowed to basically make any type of game. Pygame is built on top of the Simple DirectMedia Layer (SDL). SDL is a C framework that gives access to graphics, sound, keyboard, and other input devices on various operating systems including Linux, Mac OS X, and Windows.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset