Now that you’ve taken control of firing bullets and moving the ship, see if you can pick out a specific alien and target that alien. You can see if your code is having the desired effect by setting a really low value such as 1% you shouldn’t see many bullets fired at all with this setting. That is, write code so that when a bullet can be fired, the ship will only fire 50% of the time, or 20% of the time. See if you can use the random module to make the ship’s firing more spaced out. Sometimes it’s helpful to add a little randomness to the ship’s firing pattern. The ship should fire continuously whenever possible throughout the entire game. Continue this pattern until the game ends. ![]() Then make it turn around and sweep left across the entire screen. Make the ship move all the way to the right until it hits the edge of the screen. Now that you’ve automated firing, try to automate the ship’s movement. All of the code necessary to automate the game can be written in a single ai_player.py file. You can solve this challenge without making any changes to the code that was already written for the Alien Invasion project. It won’t be a great strategy because it will only clear the middle columns, but it will play automatically. You should be able to run ai_player.py, sit back, and watch your player shoot down aliens. Your program should make the ship fire whenever possible. Write a program called ai_player.py that creates an instance of the AlienInvasion class. In a larger project like this, it’s really nice to be able to experiment with your code, and then go back to a known working state of your project when things stop working. Note: If you aren’t familiar with Git or a comparable version control system, you might want to work through Appendix D before trying these challenges. I’ve had a lot of fun writing my own game mods related to this challenge, so if you make something interesting please share it! Also, this can be a fairly complex challenge to get started on, so there’s a guide that can help you if you’re not sure how to approach the overall challenge. You can see how to add sounds to your game here, if you’d like to do that before trying these challenges. The automated player is a lot more interesting to watch if your game has sound effects. In this investigation, you’ll start out by writing a program that takes control of the Alien Invasion game, and then implements successively more effective strategies to reach a high score in the game. This site uses Just the Docs, a documentation theme for Jekyll.Ĭhallenges - Automated Alien Invasion Player Pygame - Adding Sound and Automating Game Play.Role of self and ai_game in code that creates the ship.Installing the Platform.sh CLI on Windows.
0 Comments
Leave a Reply. |