Program Arcade GamesWith Python And Pygame
Lab 10: Sprite Moving
- Make sure this program is created in its own directory. If you are starting from the template I have at BitBucket, then make sure you start in the “Lab 10 - Sprite Moving” folder and put everything in there.
- Start with a copy of the program you wrote for Lab 9: Sprite Collecting. Copy those files into the directory for this lab.
- Move the Block class into a new file.
- Make sure your program runs like before. Adjust import statements as needed.
- Define a GoodBlock class in a new file, and inherit from your Block class. (Define the class, don't create an instance of it. Your for loop that creates the instances does not move.)
- Add a new update method. Make the good block randomly move up, down, left or right each update. (Change self.rect.x and self.rect.y randomly each time the update function is called. Not to a completely new number, but add a random number from -3 to 3 or so. Remember that random.randrange(-3,3) does not generate a random number from -3 to 3.)
- Change your for loop so that it creates instances of the GoodBlock class and not your old regular Block class.
- Call update on the list of all the sprites you have. Do this in the main program loop so the blocks keep moving, not just once at the start of the program.
- Test and make sure it works.
- It is ok if the sprites move off the screen, but a common mistake results in the sprites all moving up and to the left off the screen. If that happens go back four steps and check your random range.
- Create a BadBlock class in a new file and inherit from the Block class.
- Make an update function and have the bad block sprites move down the screen, similar to what was done at the end of Chapter 14. Extra kudos if you make a bouncing rectangle.
- Test, make sure it works.
- Double check to make sure each class is in its own file.
You are not logged in. Log in here and track your progress.
|About||Help Translate||My College||My Twitter|