Adding Sound and Automating Game Play in Alien Invasion

Did you enjoy the Alien Invasion project? Did you know you can add sound to the game in about 15 lines of code? Did you know it’s possible to write a separate program that plays the game automatically for you?

Challenges - Automated Alien Invasion Player

If you want to try this before reading how to do it, here’s a set of challenges that helps you add increasing sophistication to your automated player:

  • AI Player 1: Automated Player
  • AI Player 2: Sweeping Strategy
  • AI Player 3: Randomized Shooting
  • AI Player 4: Targeting Specific Aliens
  • AI Player 5: Sweeping and Targeting
  • AI Player 6: Optimized Strategies
  • AI Player 7: Scoring Accuracy

Guide: Adding Sound and Automating Game Play

Even though it doesn’t take a lot of code to make an automated player, it’s not obvious how to approach the problem. This guide shows you how to automate game play in a series of steps:

  • Adding sound to the game
  • Taking control of the game, and making the ship fire automatically
  • Making the ship move
  • Speeding up the game when you’re developing automated strategies
  • Adding randomness to the firing pattern
  • Changing strategies as the game progresses
  • Targeting a specific alien

If you want to see this in action, take a look at a 30-second clip of the game being played automatically.

Wishing you well, and please send questions

This has been a hard time for just about all of us. I sincerely hope that you and your loved ones are safe, and continue to be safe. I can’t offer much, but if you are stuck at home and have questions about Python that aren’t getting answered, please don’t hesitate to write. I generally only answer questions directly related to the book, but if you have a non-book question and I can answer it, I’ll be happy to share what I know.

In the Works

I’m working on a number of different resources, and I’ll share them as they’re each ready:

  • A section highlighting projects that readers have made, based on what they’ve learned from PCC
  • A section where readers share their stories about trying to find a programming-related job
  • A cheat sheet for using Git to manage your projects
  • Solutions for Chapters 12-14, and Chapters 18-20


If you have questions or comments about these new sections or anything related to Python Crash Course, feel free to reply to this email. Thanks!