Program Arcade GamesWith Python And Pygame
Lab 9: Sprite Collecting
This lab practices using Pygame sprites as described in Chapter 14.
- 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 09 - Sprite Collecting” folder and put everything in there.
- Start with the following program:
- Modify it so the player moves with the keyboard rather than the mouse. Take a look at
the move_sprite_keyboard_smooth.py program also available on the example page.
- Out of this file, you will need to grab the Player class and move it to your own program.
- Right now, your player is an instance of Block. You will need to change it so that you create an instance of Player. Note that the constructor for Player takes different parameters than Block.
- Update your event loop so that it responds to keyboard input like this new example does.
- Remove the code that moves the player with the mouse.
- Make the player blue.
- Make sure there is exactly one call to all_sprites_list.update() in your main program loop. This will call the update() method in every sprite.
- Test and make sure it works now.
- Create another list of sprites, one that decreases the player score instead.
- Where you create 50 blocks now, instead of adding them to a list called block_list, add them to a list called good_block_list.
- Make the blocks green.
- Duplicate this code and add 50 more blocks to a new list called bad_block_list.
- Make sure your program only creates one all_sprites_list.
- Make the blocks red.
- Where you check for block collisions in the main loop, update the check so it uses good_block_list.
- Duplicate that code and check against bad_block_list. Decrease the score instead of increasing it.
- Test and make sure it is working.
- (Optional) Use graphics to signify good/bad sprites as shown in the sprite_collect_graphic.py example file. Or find colors of your own choosing.
- Rather than simply use print to display the score on the console, display the score on the graphics window. Go back to the end of Chapter 5 and look up the section on drawing text.
- Add sound effects for when the user hits good blocks, or bad blocks. Here are a couple
- Add a check and make sure the player doesn't slide off the end of the screen. This check should go in the update method of the Player class. There should be four if statement checks, one for each border. If the player's x and y get outside the bounds of the screen, reset the player back inside the screen. Do not modify change_x or change_y. That doesn't work for player-controlled objects. Don't forget to check the right and bottom borders, they are easy to get wrong.
- Download a wav file and have it play a sound if the user tries to slide off the screen. Here's one
sound you can use:
You are not logged in. Log in here and track your progress.
|About||Help Translate||My College||My Twitter|