Home  
           
LectureOne
           
LectureTwo
           
LectureThree
           
LectureFour
           
LectureFiveOne
           
LectureFive
           
LectureSix

Python game programming - LectureOne

Welcome to Lecture One

What is this course going to teach you?

  • How to make games with python. Libraries we are going to use include:
    • pygame,
    • pyopengl.
    We're going to start with showing you how to set up your python environment. In lecture two we'll move on to showing you the basics of python and pygame. Afterwards we'll build up to making some 2d, and 3d games. Space travel, monkey bashing, ball and block positioning will also be covered.

Who is teaching the course.

  • This course is being done by two people. Geoff Howland and Rene Dudfield.

Introduction to python.

Why python for games?

  • Pythons benefits include clear syntax, fast development, available on multiple platforms, quality free implementations, and open source code. Clear syntax is useful so you can understand what things do, so you can change things quickly. Python allows doesn't require many of the things which other computer languages do. Eg you do not need to type ';' at the end of every line. You do not need brackets for many things. The authors of python try very hard to make sure that python code written remains clear and understandable. Fast development with python is achieved by a few things. No compile times, lower amounts of typing you need to do. You don't need a lengthy compile before you can see your changes. There are even ways where you can change the program whilst it is running! This allows you to tweak your game quicker than compiled languages will allow.

    An open source implementation is pretty important too. The executable to big? Remove parts of python. Recompile it in ways which make your particular game faster. Make all sorts of changes. You don't have too do these things. But if you need to, it's good to have the option.

Python, and python gaming websites.

Installing your python programming environment.

  • Time to get into the programming.

Windows installation.

Linux/debian installation.

  • apt-get install python pygame

Test your python installation.

  • Run python. In windows, go to the start bar find python, and select the IDLE(Python GUI) option. In linux, type python at the command line.

    Now you should see a prompt like >>> This is the interactive interpreter, you'll be able to type into here python code, and see it run. Fun. Now type in:

    import pygame
    print dir(pygame)
    print dir()
    
    That should print a bunch of stuff. The import command tells python to load that module. The print command is used to print stuff. duh. The dir command is really cool. It shows you what stuff is inside the pygame module. Now type:
    help(pygame.Rect)
    
    That shows you documentation on a particular object/

    function/ variable. Try out help on a few other things inside of the pygame module. eg help(pygame.sprite) Check out the documentation for python, and pygame at these places.

    It's good to know where to look for info when you get stuck, or need to know more details.

Running the chimp

  • From the windows command prompt:
    set PATH=%PATH%;c:\Python24\
    cd "\Program Files\Pygame-Docs\examples"
    python chimp.py
    
    Note, the examples directory might be somewhere else. Depending on where you unzipped it to. You may want to put the set line in your autoexec.bat so that you don't need to type it in every time you run python from the command line. In debian linux you do something similar:
    cd /usr/share/doc/python2.4-pygame/examples/
    python chimp.py
    
    Now try running some of the other examples in that directory.

Next

LectureTwo

If you enjoyed this lecture, please consider leaving a tip.