![](https://csdnimg.cn/release/download_crawler_static/11396013/bg10.jpg)
Contents in Detail xix
Installing Pygame on OS X .................................... 239
Installing Pygame on Windows................................. 240
Starting the Game Project ........................................... 240
Creating a Pygame Window and Responding to User Input ............. 241
Setting the Background Color .................................. 242
Creating a Settings Class ..................................... 243
Adding the Ship Image............................................. 244
Creating the Ship Class ...................................... 245
Drawing the Ship to the Screen................................. 246
Refactoring: the game_functions Module................................. 247
The check_events() Function ................................... 247
The update_screen() Function .................................. 248
Exercise 12-1: Blue Sky ...................................... 249
Exercise 12-2: Game Character ................................ 249
Piloting the Ship.................................................. 249
Responding to a Keypress .................................... 249
Allowing Continuous Movement ................................ 250
Moving Both Left and Right.................................... 252
Adjusting the Ship’s Speed.................................... 253
Limiting the Ship’s Range ..................................... 255
Refactoring check_events() .................................... 255
A Quick Recap .................................................. 256
alien_invasion.py .......................................... 256
settings.py ............................................... 256
game_functions.py ......................................... 256
ship.py ................................................. 257
Exercise 12-3: Rocket ....................................... 257
Exercise 12-4: Keys......................................... 257
Shooting Bullets .................................................. 257
Adding the Bullet Settings..................................... 257
Creating the Bullet Class ..................................... 258
Storing Bullets in a Group .................................... 259
Firing Bullets.............................................. 260
Deleting Old Bullets......................................... 261
Limiting the Number of Bullets.................................. 262
Creating the update_bullets() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Creating the fire_bullet() Function ............................... 264
Exercise 12-5: Sideways Shooter ............................... 264
Summary ...................................................... 264
13
ALIENS! 265
Reviewing Your Project ............................................ 266
Creating the First Alien ............................................. 266
Creating the Alien Class ..................................... 267
Creating an Instance of the Alien ............................... 268
Making the Alien Appear Onscreen ............................. 268
Building the Alien Fleet ............................................. 269
Determining How Many Aliens Fit in a Row ........................ 269
Creating Rows of Aliens...................................... 270
Creating the Fleet .......................................... 271