Ok, now open the second file. The first thing you'll notice is that we've added to functions, loadImageFile and loadSoundFile. Don't sweat these. They're just handy wrappers around a few functions that help us load up files that are located in the data subfolder. Feel free to use these as is in your own prototypes. They work well, and you almost certainly won't need to modify them.

Next, in the main function, we use the loadImageFile function to pull in the background image. Then we use the screen.blit function to blit that image.

Wait, blit? Wazzat? Blitting is like pasting an image onto the screen. Everytime we update graphics on the screen, we "blit" them. Think of this like a Monty-Python clip art animation. Right now, there's just the background, but we'll be pasting a few more things on here later.

The most important change, however, is control! Inside the main loop, you'll see a new loop starting with

for event in pygame.event.get():

An event is just what it sounds like--it's something that happens. It's the controller that makes these things happen. That could be a key-down event, a mouse-movement event, a joystick-button event, a window-closing event, and so on.

The loop here is checking for events. In this case, it checks to see if the user has asked to close the window or if the user has hit the ESC key. If either of those conditions are true, the main loop will quit and the game will end.

Now we're in control!

Copyright Mike Edwards 2006-2009. All content available under the Creative Commons Attribution ShareAlike license, unless otherwise noted.