Program Arcade Games
With Python And Pygame

Language
English
Russian - Русский
Turkish - Türkçe

Before getting started...

If you already know why you want to learn to program games and just want to learn how to get started, then you can skip over this section down to the next section on how to install the software you need.

Are you here because you want to create your own games? Excellent! Here are some videos of games students have created by the end of this course:

Video: Fall 2012 Game Projects
Video: Spring 2012 Game Projects

As you start to learn to program, you might soon find that it looks like work. We all know we'd rather skip work and go farming for gold in World of Warcraft or Eve Online or some other game, right? So why learn to program? What does a person get out of it?

0.1 Learn to Make Games and Get Paid

fig.money
Figure 0.1: Bags of money

Learn how to make games and get paid? Ok, I won't pay you, but if you learn to program, there are plenty of people that will pay you. Here's how to profit:

  1. Learn to program games.
  2. Have fun making your own games.
  3. Select favorite job offer.
  4. Profit.

Look, no ??? in this plan!

Think about it. You can play games, but anyone can do that. Being great at a video game really isn't much of an accomplishment in life if you think about it. Or you can learn to create games. People care about that.

While you may be studing how to program games, tell your parents and co-workers you are studying computer science. It sounds better.

0.1.1 Why Study Computer Science?

Back to money. According to the National Association of Colleges and Employers (NACE), Computer Engineering is the best-paid degree, Computer Science is third best paying degree, and Information Science is the 10th. Most of the other degrees are also in technology-related and involve software:

Top-Paid Bachelor's Degrees
Major Average Salary Offer
Computer Engineering $70,400
Chemical Engineering $66,400
Computer Science $64,400
Aerospace Engineering $64,000
Mechanical Engineering $62,900
Electrical/Electronics & Communications Engineering $62,300
Civil Engineering $57,600
Finance $57,300
Construction Science $56,600
Information Sciences & Systems $56,100

(Data is from the NACE January 2013 Salary Survey.)

Computer engineers work at integrating computer programs with hardware. In today's engineering market, most of those engineering jobs will need to know some computer programming.

What is Information Science? This is a degree for people who like computers and technology but never really liked programming. This book aims to make sure that isn't you. Programming is fun, and who wants to settle for only 10th in the list of best-paying degrees?

While learning to program games, you can be studying towards one of the best paying four-year degrees you can get. And let's be honest, those engineering degrees usually take five years. Computer science is a great bet for a career.

Not only are computer science graduates getting high-paying offers, they are the most likely to get an offer when applying. According to NACE more than 56 percent of majors get an offer when applying. This is because there are few students going into a field that is in high-demand. To get an idea how Science Technology Engineering and Math (STEM) jobs compare to the students, see Figure 0.2 and Figure 0.3.

fig.code_graphics1
Figure 0.2: STEM/Computer Science Graduates vs. Jobs. Source: code.org
fig.code_graphics2
Figure 0.3: Computer Science Job Outlook. Source: code.org

What about a two-year school to learn programming? After all, two year schools offer a cheaper alternative to four year colleges. Way cheaper. But I'll offer the following data as a caution about choosing a two year school:

Average salary by education level
Vocational/Tech School$59,729
Some College$72,197
College Graduate (4-Year)$81,539
Master's Degree$98,911
Doctoral Degree$112,772

According to Dice.com's survey data, people in a technology career who graduate from a two-year school averaged $21,000 less than people who went to a four-year school. In fact, they did worse than dropouts from four-year colleges! So go to a four-year school and skip the two-year school entirely. (Data is according to the 2011-2012 Dice Technical Salary Survey. Note that the salary listed is not the average starting salary. The numbers represent the average salary of all workers, no matter how experienced.) Of course, I think Simpson College has the best Computer Science department in the midwest:
http://simpson.edu/computer-science

0.1.2 Get The Most From This Class

You can't be a great basketball player without practice.

Looking to make your time here worthwhile? Answer the chapter questions! Don't skip them. They are necessary to understand the material.

Do the labs! This is even more important. Learning by only reading the material is about as useful as trying to become an expert basketball player only by reading a book.

Practice! You might see other people that don't have to practice. It isn't fair. Or, you might be smarter than other people, and they start doing better than you because they work at it and you don't. That's not fair either. That's life. Get used to it. Practice.

Are you taking this as a class? Great! Did you know you can save time and copy the answers and labs from the Internet? You can also buy yourself a gym membership and send someone else to work out for you. It makes about as much sense.

Seriously, what on earth are you thinking copying from someone else? If you aren't going to do the work drop out now and start filling out McDonald's applications.

If reading isn't your learning style, most of the information is available through videos. You can skip the text entirely and just watch the videos by checking out the YouTube playlist:
http://www.youtube.com/playlist?list=PL1D91F4E6E79E73E1
You can't learn without doing the work though. Do the reading. Ask questions. Do the labs. Ask questions. Do the worksheets. Ask questions. Listen to the videos. And ask your teacher questions.

0.1.3 Send Feedback

This is the text I use with the Simpson College class:
Computer Science 150 Fundamentals of Computing I
There is a print version and an on-line version. The on-line version is at:
http://ProgramArcadeGames.com
The goal of the text, website, worksheets, labs, and videos is to teach basic computer science concepts and get students programming their own games as soon as possible.

Want to keep this resource free?
Drop me a note!

If you are using it for self-study or for another class, please drop me a note. The more people that use this resource, the more effort I'll put into improving it.

I've heard from a few high schools that use this material. If you are a student at one of these high schools, and liked this material, consider checking out Simpson College. We'd love the chance to be able to work with you. Contact myself or admissions for more information.

If you notice any errors or omissions in the book, please send me an e-mail. I'd like this to be the best resource possible.

Dr. Paul Vincent Craven
Department Head, Computer Science Department
Simpson College, Indianola, Iowa, USA
paul.craven@simpson.edu

0.2 Installing and Starting Python

To get started, two programs need to be installed, Python and Pygame. Python is the computer language we will program in, and Pygame is a library of commands that will help make writing games easier.

0.2.1 Windows Installation

Video: Installing Python and Pygame

If you are working with a computer that already has Python and Pygame set up on it, you can skip this step. But if you want to set up Python and Pygame on your own Windows computer, don't worry. It is very easy.

  1. Run the Python installer downloaded from:
    http://ProgramArcadeGames.com/python-3.3.1.msi
  2. Run the Pygame installer downloaded from:
    http://ProgramArcadeGames.com/pygame-1.9.2a0.win32-py3.3.msi

Once everything has been installed, start Python up by selecting the Integrated Development Environment (IDLE) as shown in Figure 0.4

fig.starting_python_idle
Figure 0.4: Starting Python

The original files provided here come from the Python download page at:
http://www.python.org/download/
...and the Pygame file originally comes from:
https://bitbucket.org/pygame/pygame/downloads

0.2.2 Mac Installation

Python and Pygame run on the Mac. I've never created a tutorial on it. Given the headaches that former students have gone through to get Pygame to work on the Mac, I recommend running Python/Pygame under Windows emulation instead.

0.2.3 Unix Installation

Unix distributions may come with a Pygame package, or the ability to easily get one. If you want to compile from source, this is what I've used on Linux Mint:

 
# Load required packages
sudo apt-get install mercurial libsdl1.2-dev libsmpeg-dev 
sudo apt-get install libasound2-doc libglib2.0-doc python-dev 
sudo apt-get install libsdl-ttf2.0-dev  libsdl-image1.2-dev  
sudo apt-get install libsdl-mixer1.2-dev libportmidi-dev 
sudo apt-get install libavformat-dev libswscale-dev

# Use mercurial to clone current code
hg clone https://bitbucket.org/pygame/pygame

# Build and install
cd pygame
sudo python setup.py

0.2.4 Optional Wing IDE

The biggest risk on UNIX platforms is that your default Python version might be in the 2.x series, and that code won't work with the code examples here in the book. Make sure you have and are using Python 3.3.x.

While not necessary, I also highly recommend installing and using “Wing IDE 101” at:
http://wingware.com/downloads/wingide-101/
The Wing IDE is a free version of a commercial development environment for Python. For this class, there is no need for all the bells-and-whistles the commercial version comes with, but they are nice. You will see that I often used this editor while recording the videos.

0.3 Viewing File Extensions

Video: How to show file extensions

It is a great idea to change your windows configuration to show file extensions. A file usually has the a name like Book report.docx where the .docx tells the computer it is a Microsoft Word compatible document. By default Windows hides the .docx extension if there is a program installed to handle it. If you are programming, this hiding part of the file name can be annoying.

For Windows 7, to show file extensions, open up your computer's control panel. Find the selection for “Folder Options.” Click the “View” tab, and then unselect the option for “Hide extensions for known file types.”

For Windows 8, bring up a file explorer by hitting the Winodws-E key. Then click the “view” tab and make sure “File name extensions” has been checked.


You are not logged in. Log in here and track your progress.