Game Development Reference
In-Depth Information
Notice that we also detect if the Key 's' was pressed, which is to put up the ship's
shields. In the main loop, we call the processUserInput method that will update
the coordinates and/or update the current speed of the ship.
private function processUserInput():void {
var speed:Number = m_ship.getSpeed();
var i:int;
if ( m_keyRIGHT ) {
m_ship.right();
}
if ( m_keyLEFT ) {
m_ship.left();
}
if ( m_keyDOWN ) {
m_ship.down();
}
if ( m_keyUP ) {
m_ship.up();
}
}
The four methods on the SpaceShip class that implement the case when each key is
pressed are as follows:
public function right():void {
updateSpeed(m_speedDelta);
if ( x < MAX_X )
x += m_speedDelta;
}
public function left():void {
updateSpeed(-m_speedDelta);
if ( x > 0 )
x -= m_speedDelta;
}
public function up():void {
if ( y > 0 )
y -= m_vt;
}
public function down():void {
if ( y < MAX_Y )
y += m_vt;
}
 
Search WWH ::




Custom Search