Programming Space Invaders


Consider the beginnings of a simplistic space invaders game like the one shown to the right. You can touch the spaceship to shoot. You can move the spaceship left-to-right by clicking the buttons. For now, don't worry about the targets or scoring points.

Sketch, on paper, the event handlers for this app

Be sure and answer the following questions:
  • How do you get the bullet to move smoothly up the canvas?
  • How do you get the bullet to appear only when it is shot?
  • How do you get the bullet to appear in the right place (right above the shooter)

Instructor Demo

Incremental development: code a little, test a little

iteration 1: shoot the bullet up on Touch event
iteration 2: have the bullet appear only on touch
iteration 3: make the bullet disappear when reaches top
iteration 4: move the spaceship
iteration 5: make the bullet appear at nose of spaceship

multiple bullets?
hitting objects?


Back and forth video
Shooter game video (and chapter 17 available from that page)

David Wolber,
Feb 23, 2012, 9:19 AM