Final assignment, Pygame

Well we have finally made it to the final assignment. I am really looking forward to what you will create.

Main Requirements:

  • must have an intro screen, that then goes to an instruction screen, that then goes to the main game (see the instructions program we created a few classes ago).
  • Intro screen requirements:
    • Must have a title (in text or graphic) for your game
    • Must have graphics, bitmap or computer drawn
    • Must include a way to move to next screen, and instructions to do so, eg. (hit enter to continue, click here to play)
    • Must display the current high score and the user
    • Must play a short background music when loading (5-10 secs)
  • Instructions screen requirements:
    • Must take in a username
    • Must explain the controls of the game, and how to gain points
    • Must include a way to move to the game screen, and instructions to do so, eg. (hit enter to continue, click here to play)
  • Game requirements:
    • must have a bitmap image sprite
    • must have a computer drawn sprite
    • must have sound effects in the main game
    • must have more than 1 level
    • when the game ends, display a game over message somewhere on the screen, then pause 2 secs before ending.

Ideas for games could be:

  • tic tac toe
  • typing game
  • space invaders
  • maze runner
  • frogger
  • pacman
  • road trip car game

If you are struggling to come up with a game, then modify the bullets code to make a space invaders type of game. You must have the following:

  • change the player to a bitmap sprite spaceship, make sure your image is small enough
  • create different kinds of enemies, some bitmap sprites, some ellipses, change sizes and colors of blocks
  • have the enemies move down the screen, then respawn at the top when they reach the bottom.
  • track if the enemy collides with the spaceship, then the game ends
  • create a new level where the enemies move quicker, and make more of them

Program comments:

I won’t require you to include psuedocode for this assignment, but you will need to include detailed comments in your program. A general guideline is that you provide 1 comment for every 3 lines of code in your program. Your comments should explain what the lines below are doing so that if someone else wanted to modify/add to to your program, they could understand what you are doing.

Due Date:

Your final assignment is due Wed Jun 14. Which is 10 classes to work on this assignment.

Looking at a couple of Pygame examples

OK, so last class, we looked at the bullets example, think of how you could possibly modify this game to your classic space invaders game:

In this example, there is a player who is enclosed by walls. Again, imagine how you could modify this to a maze game, or even a pacman game:

Finally, this is your centipede/snake type game. Think about how you could create a game where there would be more than 1 snake, and you can maybe shoot bullets to fire at another snake:

For Wednesday’s class, think about a possible final game that you would like to create as the end of the unit assignment. Try to be creative. One Wednesday, I will give you requirements of your assignment. If you are stuck for a final assignment, I will give you some parameters for a simple game that you can modify.

Adding Text and getting User input in Pygame

Today we will look at adding text to the pygame screen, and examples of instruction screens. Then we will look at taking user input in pygame. Finally, we will look at a centipede example game, similar to a game that you could extend.

Adding Text, copy and paste the following into your wingIDE:

Adding Instructions, and getting user input, copy and paste the following into your wingIDE:

Chp 13 assignment

Your assignment is to modify the basic sprite program from chapter 13 in the following ways:

  • Make the black rectangles into blue circles/ellipses, keep them the same size.
  • Make the red player, into the spaceship from the graphics tutorial we did.
  • Add a sound to the program whenever the player eats 1 block. Choose a sound possibly from (
  • When the user eats up all the circles, end the game and display a message to the user in the console.

For tips on how to change the program to circles and a bitmap image, in the tutorial under chapter 13.1 there are details on how to do exactly that, it will require you modify parts of the main program as well,

Your assignment is due Fri May 5.

Chp 8-10 Activity lab

Please complete the following chp 8-10 activity by answering the following questions below. Copy and past the code into your wing IDE and try to fix the mistakes. Then, copy and paste your corrected code into a new MS Word or Google Docs document and save it on the server when done.

When done, you can finish off your drawing functions assignment that I assigned last Mon.

  1. Why does using this code in the main loop not work to move the rectangle?
    rect_x = 50
    pygame.draw.rect(screen, WHITE, [rect_x, 50, 50, 50])
    rect_x += 1
  2. If the screen is 400 pixels tall, and the shape is 20 pixels high, at what point should the code check to see if the shape is in contact with the bottom of the screen.
  3. When drawing a starry background, explain why it doesn’t work to put code like this in the main program loop:
    for i in range(50):
    x = random.randrange(0, 400)
    y = random.randrange(0, 400), WHITE, [x, y], 2)
  4. If you have a list of coordinates like the following, what code would be required to print out the array location that holds the number 33?
    stars = [[ 3, 4],
    [33, 94],
    [ 0, 0]]
  5. This code example causes snow to fall:
    # Process each snow flake in the list
    for i in range(len(snow_list)):
    # Get the x and y from the list
    x = snow_list[i][0]
    y = snow_list[i][1]
    # Draw the snow flake, WHITE, [x, y], 2)
    # Move the snow flake down one pixel
    snow_list[i][1] += 1

    So does the example below. Explain why this example works as well.

    # Process each snow flake in the list
    for i in range(len(snow_list)):
    # Draw the snow flake, WHITE, snow_list[i], 2)
    # Move the snow flake down one pixel
    snow_list[i][1] += 1


6. What’s wrong with this code that uses a function to draw a stick figure? Assume the colors are already defined and the rest of the program is ok. What is wrong with the code in the function?

def draw_stick_figure(screen, x, y):
# Head
pygame.draw.ellipse(screen, BLACK, [96,83,10,10], 0)
# Legs
pygame.draw.line(screen, BLACK, [100,100], [105,110], 2)
pygame.draw.line(screen, BLACK, [100,100], [95,110], 2)
# Body
pygame.draw.line(screen, RED, [100,100], [100,90], 2)
# Arms
pygame.draw.line(screen, RED, [100,90], [104,100], 2)
pygame.draw.line(screen, RED, [100,90], [96,100], 2)

7. Show how to grab the mouse coordinates, and then grab just the x coordinate of where the mouse is.

8. When we created a bouncing rectangle, we multiplied the speed times -1 when the rectangle hit the edge of the screen. Explain why that technique won’t work for moving an object with the keyboard.