Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1

Hour 19. Game Programming


What You’ll Learn in This Hour:
Why you might want to program games
Different Python game interfaces
How to set up and use the PyGame library
How to handle action in a game
How to create a simple game script

In this hour, you will learn about creating games using Python. You will learn game scripting basics,
how to create a game screen, how to add text, how to add images, and even how to animate those
game images. In the process, you’ll learn about the PyGame library.


Understanding Game Programming


Why should you learn to program games? The simple answer is that you will become a stronger script
writer in Python. Game programming is different from other programming in that it stretches both the
programmer and the computer.


Think about computers built specifically for gaming. They tend to have the fastest CPUs, larger
memory chips, and the best video cards. This is because games can be large consumers of a computer
system’s resources.


For a game developer, getting a designed game from paper to Python script can be a big challenge.
Game scripts use all the various aspects of a scripting language, such as user input, file input/output,
mathematical manipulation, various graphical interfaces, and so on. Also, developing a game forces
you to be creative and a good problem solver.


By the Way: Developer Versus Designer
In creating a marketable game, a game developer is the person who writes the code. A
game designer, on the other hand, determines the game’s appearance, rules, and goals.
For the purposes of this hour, you can be both the game designer and the developer.

In essence, understanding game development can help make you a well-rounded script writer. Game
writing is commonly used to instruct beginners as well as to polish old-timers. As you learn to write
Python scripts on a Raspberry Pi, game development will help you solidify Python concepts.


Learning About Game Frameworks and Libraries


Several game frameworks and libraries are available in Python. Table 19.1 lists a few of them.

Free download pdf