Game Development Reference
In-Depth Information
}
return true;
}
/**
* Process key up event
* @param e Key event
* @param key key code
* @return
*/
public boolean keyUp(int key) {
if (key == KeyEvent.KEYCODE_DPAD_LEFT
|| key == KeyEvent.KEYCODE_DPAD_RIGHT
|| key == KeyEvent.KEYCODE_Q
|| key == KeyEvent.KEYCODE_W)
dx = 0;
if (key == KeyEvent.KEYCODE_DPAD_UP
|| key == KeyEvent.KEYCODE_DPAD_DOWN
|| key == KeyEvent.KEYCODE_O
|| key == KeyEvent.KEYCODE_L)
dy = 0;
return true;
}
In SpaceBlaster , when the pad arrows are pressed, the position of the ship is shifted by 1 unit in the
corresponding direction. S stars the game; E ends it, and Q terminates the application. The onTouchEvent
allows the ship to be dragged around the device screen using your fingertips. When the game is running,
tapping anywhere on the device screen (other than the ship) will start the game if it's not already started
or fire the laser gun if the game is already running.
At this point, the project, including all files and resources, should look as shown 24.251in Figure 3-7.
Search WWH ::




Custom Search