O'Reilly logo

Adventures in Python by Craig Richardson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9781118951798-c06f000

WHEN YOU’RE PLAYING computer games on your PC, one of the ways you can give the game commands is via the keyboard. You use different keys to give different commands—for example, you usually use the W, A, S and D keys to move the player around the game.

In this adventure you’ll learn how to use the keyboard with PyGame. You’ll also make a game in which, for the first time, you’ll move a player around the window. Okay—your player is just a dot on the screen at this stage, but it’s a good start! As the program develops throughout the adventure, you’ll add extra features like a ball that your player can “kick,” a goal and a points system.

The gameplay and graphics in this game are very simple, so during the adventure you may want to add more features to the game, like better graphics. Try using some of the things you learned in Adventure 5 to add that little bit extra to the game. You can also come back to the game and improve it after you’ve learned more in later adventures. You’ll be learning lots in the sound adventure in Adventure 9, for example, so you can add sound to the game once you know how to do that.

Using Keyboard Input

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required