Hit Test

It doesn't make much of a game if we can't move the paddle!

Add code to the movie as follows:

stage.addEventListener(KeyboardEvent.KEY_DOWN, doKeyDown);
function doKeyDown(e:KeyboardEvent):void {
  var amount:int=1; //amount to move by
  if(e.shiftKey) amount=5; //make it 5 if shift is down 
  switch(e.keyCode) {
	 case Keyboard.LEFT: case 65: paddle.x-=amount; break; //left arrow  or letter A
	 case Keyboard.RIGHT: case 68: paddle.x+=amount; break; //right arrow	or letter D 
  } //switch
} //doKeyDown

Get Adobe Flash player
We can now move the paddle but it is not really a great game yet. Experiment and add any of the following:

  • Play a sound when you catch a star;
  • Check to see if you have 20 points and announce that you won (play another sound)
  • Add a button to start over.
  • It is difficult to get points. How would you make this game more interesting for beginners and advanced players?
  • Add levels: level 1 there is just one ball, or the speed gets faster.
  • Use you imagination to make the game enjoyable.

Download the class. Download the movie.

NEXT: Strings in ActionScript