12
A S h i p t h A t F i r e S B u l l e t S
Let’s
build a game called Alien Invasion!
We’ll use Pygame, a collection of fun, power
ful Python modules that manage graphics,
animation,
and even sound, making it easier
for you to build sophisticated games. With Pygame
handling tasks like
drawing images to the screen, you
can focus on the higherlevel logic of game dynamics.
In this chapter, you’ll set up Pygame, and then
create a rocket ship that
moves right and left and fires bullets in response to player input. In the next
two chapters, you’ll create
a fleet of aliens to destroy, and then continue to
refine the game by setting limits on the number of ships you can use and
adding a scoreboard.
While
building this game, you’ll also learn how to manage large pro
jects that span multiple files. We’ll refactor a lot of code and manage file
contents to organize the project and make the code efficient.
228
Chapter 12
Making games is an ideal way to have fun while learning a language. It’s
deeply satisfying to play a game you wrote, and
writing a simple game will
help you comprehend how professionals develop games. As you work through
this chapter, enter and run the code to identify how each code block contrib
utes to overall gameplay. Experiment with different values and settings to bet
ter understand how to refine interactions in your games.
N o t e
Alien Invasion
spans a number of different files, so make a new alien_invasion
folder on your system. Be sure to save all files for the project to this folder so your
import
statements will work correctly.
Also, if you feel comfortable using version control, you might want to use it for this
project. If you haven’t used version control before, see Appendix D for an overview.
Do'stlaringiz bilan baham: