Computer science 313 - software development for games


Computer Science Software Development for Games Assignment: Sprites and Libraries

Overview - Create a short obstacle-avoidance, collection style game. You will integrate all the things you've practiced so far into a single cohesive whole. There will be sound, graphics, player movement, points, a title screen, a credits screen, and collision detection (handled by pygame Sprites).

Role: Sound / Art Engineer

Find appropriate sounds and graphics for the game.

Assure that licenses are being followed (credit screen, licenses included somewhere, etc).

Create a Music class that includes the following methods:

  • play_once(String id) - Plays a previously loaded song referenced by id
  • play_repeat(String id) - Plays a previously loaded song referenced by id on repeat
  • stop_repeat(String id) - Stops a previously playing song referenced by id
  • init(String level) - Loads all sounds and music for a specified level

Create an Art class that includes the following methods:

  • init(String level) - Loads all graphics associated with a level (Note: It may be a good idea to clear out any old level graphics as well)
  • get_image(String id) - Retrieve an image referenced by id

Create an TitleLevel class

  • Simple scene giving the title of your game and the authors. Indicate that the player should press one key to see the credits and one key to start the game.
  • Note: There should only be one copy of the "pygame template" code.
  • This might mean that you need to create a parent class called Level and decide what pieces are duplicated between the TitleLevel, CreditsLevel, and main game. Remember, DRY (Don't Repeat Yourself!)

Create an CreditsLevel class

  • Simple scene giving the title of your game and the authors. Indicate that the player should press one key to see the credits and one key to start the game.

Each of these classes should be in a separate file!

Role: Gameplay Engineer

This role is based heavily on lab 13 and 14 in the book (you'll notice a large portion of the text taken word for word) Just because this role has more text doesn't make it more or less difficult. The instructions are just broken down into smaller pieces than the other roles.

Start with the program.

Update the comments at the beginning to reflect that it is now your program, not the author's.

Modify it so the player moves with the keyboard rather than the mouse.

Out of this file, you will need to grab the Player class and move it to your own program. Do not get rid of the Block class. You will have both the Block and Player class in your 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 both good sprites and bad sprites

Good Sprites

  • 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.
  • Where you check for block collisions in the main loop, update the check so it uses good_block_list.

Bad Sprites

  • 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.
  • Don't recreate the list right before you add bad blocks or the player.
  • Make the blocks red.
  • Duplicate that code and check against bad_block_list. Decrease the score instead of increasing it.
  • Test and make sure it is working.

Adding Flair

  • Call the Art/Sound Engineer's code to use graphics to signify good/bad sprites. If the Engineer isn't done yet, just use rectangles.
  • Make sure you replace the "blue block" player with an image from the Art Engineer
  • 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.
  • Call the Art/Sound Engineer's code to add sound effects when the user hits good blocks, or bad blocks. If the Engineer isn't done yet, just output some text to the console.
  • 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.
  • Also play a sound using the Art/Sound Engineer's code if the user tries to slide off the screen.
  • Check to make sure the bump sound doesn't continually play when the user is at the edge of the screen. If it does, the program is checking the edge incorrectly.

Creating Libraries

  • Next, you'll want to create libraries out of your code.
  • Move the Block class into a new file. Many people get confused between the name of the library file, the name of the class, and the variable that points to the instance of the object. Library files should be all lower case. I'd recommend calling your new file that you put the Block class into block_library.py.
  • Make sure your program runs like before. Adjust import statements as needed. Remember that you prepend the library name to the class, not the variable that points to the instance of the class. For example: my_dog = dog_library.Dog() and NOT dog_library.my_dog = Dog() because Dog is what is in the library, not my_dog.
  • Define a GoodBlock class in a new file, and inherit from your Block class. I'd recommend using the file name goodblock_library.py to keep with the pattern we set up before. Remember, 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. (You probably don't need a new __init__ 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.
  • Double check, make sure GoodBlock inherits from the Block class. If done correctly, GoodBlock won't need an __init__ method because it will get this method from Block.
  • 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. Reset the block to the top when it falls off the screen. You may instead use a different type of movement. Take a look at the examples in the book for some ideas.
  • Test, make sure it works.
  • Double check to make sure each class is in its own file.
  • Again, make sure you only have one copy of the "pygame template" code. This may require you to create a class called GameLevel and a separate Main that controls Level swapping.
  • If you have extra time, you can look at the sprite examples section on the website and see how to get sprites to bounce or move in circles.

Role: File Management Engineer (Only in three person groups)

In a three-person group, rather than hard-coding the image and art location information into the classes, it should be stored in a file. The File Management Engineer's job is to create a File class in charge of loading these files from disk for use by the art and sound engineer.

A comma separated example might be:

objects.txt

player,Mario.png,0

good_block,mushroom.png,2

really_good_block,star.png,5

bad_block,goomba.png,-2

The third element is the number of points associated with collecting the item. This feature must be included in a three-person team.

You can also use JSON, YAML, pickle, or any other file format you feel is appropriate. I'm open to creativity and learning new things here.

They are also in charge of the contents of the files. There should also be a file for sounds in the game.

Note: The book does not talk about loading and saving files in Python.

Attachment:- Assignment File.rar

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Computer science 313 - software development for games
Reference No:- TGS02657609

Expected delivery within 24 Hours