Introduction to Computer Science
Union College
Spring 2009


The goal of this project is to create an animated image (more specifically, a walking character where the feet are moving) using a list. We will talk in class about the general ideas.

Download, the following program as a starting point: You also need all of these pictures:

These images were created by George W. Clingerman. I got them from his great site of XNA tutorials.

Step 1: In the code I gave you, the variable guy refers to a single (still) picture. We now need it to refer to a list, which contains all of the images that are part of our animation sequence. And the images need to be ordered in the order that we want to show them in.

Change the code where the picture is loaded, such that all pictures are loaded, converted to pygames internal format, and put into a list called guy.

Step 2: Now that we have a list of pictures instead of just a single picture, we need a variable to keep track of which picture we want to show. We can do that by having this variable hold the index of the picture in the list.

Create a variable called cur_idx and set it to 0. Where should this variable be created? In intialize or in run_game? Inside the game loop or outside? Why?

Step 3: Change the command that actually draws the picture, such that it draws the picture from the list that we currently want to show (as indicated by the cur_idx variable.

Now try it out. You should see the same thing as before. Just one still picture of the character. (But it is working with the list now, instead of just one single picture.)

Step 4: Now we need to increase cur_idx by 1 every so often and reset it to 0 every time we reach the end of the list.

At first, increase cur_idx by 1 in every frame (i.e., every pass through the game loop). And get the code right for resetting it to 0 when reaching the end of the list.

Try it. The timing will not be very good, but you should see the feet moving.

Step 5: Now introduce a timer, so that cur_idx only gets changed every X milliseconds. That is: You need a timer/counter variable which adds up the time that is passing. If that timer reaches your threshold, cur_idx get changed.

by Kristina Striegnitz