Game Development Reference
In-Depth Information
The arrow keys are handled in the Racetrack class and they pass the user inputs to
the ship object. In fact, the ship moves in only a limited area. We will move the
world around it, namely the items on the track at the speed of the ship.
The RaceTrack object traps the ups and downs of a key as follows:
private function keyUp(event:KeyboardEvent):void {
var key:int;
key = event.keyCode;
switch (key) {
case Keyboard.RIGHT:
m_keyRIGHT = false;
break;
case Keyboard.LEFT:
m_keyLEFT = false;
break;
case Keyboard.DOWN:
m_keyDOWN = false;
break;
case Keyboard.UP:
m_keyUP = false;
break;
}
}
private function keyDown(event:KeyboardEvent):void {
var key:int;
key = event.keyCode;
switch (key) {
case Keyboard.RIGHT:
m_keyRIGHT = true;
break;
case Keyboard.LEFT:
m_keyLEFT = true;
break;
case Keyboard.DOWN:
m_keyDOWN = true;
break;
case Keyboard.UP:
m_keyUP = true;
break;
case 83: // Key 's'
m_ship.shieldReq();
break;
}
}
 
Search WWH ::




Custom Search