HitTest: Move the Paddle

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:

Download the class. Download the movie.


INDEX, Detect if an object hit another, Detect if an object hit a target inside another, Catch a Falling Star Game, Add a paddle, Add code to movie for hit and miss, Modify FallingStar to hit and miss, Add code to move the paddle
Next lesson: Strings in ActionScript

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Add code to move the paddle