Space Invaders

Game Assets and Code Template

I have created a ZIP archive which contains:

  • Images for three different invaders types (two frames per invader so we can animate), a ufo, our ship etc.
  • Sound effects for both invaders and ship firing a rocket and when they are hit.
  • A nice reto space invaders font.
  • The starting point for our game

Download the ZIP archive and copy contents in your coderdojo_tramore directory.

Session 1 (Saturday 13 June)

The game design follows the usual design:

  • Use lists whenever we need multiple copies of any object, e.g., invaders, ship_rockets, blocks etc.
  • Use a boolean flag isAlive to track which objects should be removed from the game.
  • Other than the default update and draw functions, we have function setup_level to constrct a level.

We got as far as:

  • Setup HUD - showing score, game title, and level.
  • Create the ship and get it to respond to user input - direction and fire. To fire we needed to
    • create a new rocket and set its position to match the ship.
    • set rocket.isAlive to be True.
    • append rocket to the ship_rockets list.
    • in function update we added code to
      • update position of each rocket in ship_rockets.
      • remove any rockets that go outside the screen bounds.
    • in function draw added code to draw each rocket in ship_rockets.
  • In function update we added code to control how fast the ship can fire rockets.
  • Create the space invaders.
    • Move invaders side to side and down.
  • Implement invader rockets.
  • Implement the defense blocks.

At end of this session, we got something like space_invaders.py

Session 2 (Saturday 20 June)

Our starting point is last's week end point. If you don't have that code you can download my copy: space_invaders.py. Note that you first need to download and extract the ZIP archive containg the game assets.

Our plan for this session is to:

  • Collision detection - what collisions are we interested in and what should happen when thet occur?
    • ship rockets hit a block - In easy mode the ship rockets could pass through so that they can hit invaders. In intermediate mode any ship rockets that hit a block are distroyed but block is unaffected. In extreme mode any ship rockets that hit a bluck are distroyed but also the block is damaged.
    • invader rockets hit a block - the rocket is distroyed and the blick is damaged.
    • invader rockets hit the ship - two options ship is damaged or game over.
    • ship rockets hit an invader - invader is toast. Fewer invaders, so they speed up.
  • UFOs, we need UFOs.
  • Balancing the game - what parameters can we tweek to make the game hard enough?, what can we vary to make it interesting?
  • Multiple levels
  • Animations - we won't go crazy here, it is space invaders after all. However, there are some effect that will be nice to try out.