Program Arcade GamesWith Python And Pygame
Lab 10: Sprite Moving
This lab practices uses Pygame sprites as described in Chapter 14, and separates the classes into different files as described in Chapter 15.
- Start in an empty directory and put all of the lab-related files in this directory.
- Start with a copy of the program you wrote for Lab 9: Sprite Collecting.
- 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.
- Make sure the blocks don't wiggle outside the screen.
- Test and make sure it works.
- 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.
Copyright © 2013
English version by Paul Vincent Craven
Russian version by Vladimir Slav
Turkish version by Güray Yildirim
English version by Paul Vincent Craven
Russian version by Vladimir Slav
Turkish version by Güray Yildirim