Tufts OpenCourseware
Search
Author: Ming Y Chow

Tufts OpenCourseWare
Introduction to Game Development
M. Chow
Spring 2012

 

Lab 2: The Battle for Ram Aras, Part I

This lab is worth 10 points

Objectives

In this lab, you will practice:

  1. Using Pygame
  2. Implementing two Python modules that are game sprites
  3. Loading images with exception handling
  4. Using an event queue to handle keyboard events

Overview

For the next two weeks, we will develop a small game titled The Battle for Ram Aras using Pygame. This is a 2D space shooter game where the goal is to save the planet Ram Aras from invaders. This week, we will implement the star of the game: a laser-shooting battlecruiser.

Instructions

You will implement two sprites for the game as Python / Pygame modules: the battlecruiser (Battlecruiser.py) and the laser (Laser.py).

Download the assets (images) for the game: assets.zip. You will be using this set of assets for the next lab as well.

Specifications and Controls

  • Both the Battlecruiser and Laser Python classes shall be subclasses of pygame.sprite.Sprite
  • The Battlecruiser sprite shall use the asset battlecruiser.gif
  • The Laser sprite shall use the asset laser.gif
  • Both sprite classes shall load the asset with exception handling
  • Both sprite classes shall have a class constructor
  • Both sprite classes shall have and maintain the following member variables:
    1. x
    2. y
    3. dx
    4. dy
    5. screen (a copy of the drawing surface)
    6. image
    7. image_w (image width)
    8. image_h (image height)
    9. rect (a "moving collision box")
    10. active (a boolean)
  • Both sprite classes shall have a method named update
  • Both sprite classes shall have a method named draw
  • You are free to use additional member variables for each of the sprite classes (e.g., perhaps firing speed and cooldown for the battlecruiser)
  • Both sprite classes shall run using 50 frames-per-second
  • The controls for the battlecruiser:
    • LEFT ARROW: Moves the battlecruiser to the left of the screen (in the x-direction)
    • RIGHT ARROW: Moves the battlecruiser to the right of the screen (in the x-direction)
    • UP ARROW: Moves the battlecruiser up the screen (in the y-direction)
    • DOWN ARROW: Moves the battlecruiser down the screen (in the y-direction)
    • SPACE BAR: Fires a laser. Important: the battlecruiser can fire multiple lasers. That is, more than one laser can be drawn on one frame!
    • ESC: Quit
  • Running the laser module via python Laser.py shall launch a 800x600 window with a black background, with a barrage of lasers randomly going from down the screen to up.
  • Running the battlecruiser module via python Battlecruiser.py shall launch a 800x600 window with a black background, allowing you to control the battlecruiser with the controls as noted above.

Submitting the Lab

Hints

  • It would be wise to maintain a list of fired lasers in the battlecruiser class!