Game Development Reference
In-Depth Information
piece of the puzzle is trivial, so let's take a look at the world updating mechanism. We delegate
the acceleration value calculation to a method called calculateInputAcceleration() . Once
the world is updated, we check whether any of the three states (lives, waves, or score) have
changed and update the scoreString accordingly. Finally, we check whether the game is over,
in which case we enter the GameOver state.
private float calculateInputAcceleration() {
float accelX = 0;
if (Settings. touchEnabled ) {
for ( int i = 0; i < 2; i++) {
if (game.getInput().isTouchDown(i)) {
guiCam.touchToWorld(touchPoint.set(game.getInput()
.getTouchX(i), game.getInput().getTouchY(i)));
if (OverlapTester. pointInRectangle (leftBounds, touchPoint)) {
accelX = −Ship. SHIP_VELOCITY / 5;
}
if (OverlapTester. pointInRectangle (rightBounds, touchPoint)) {
accelX = Ship. SHIP_VELOCITY / 5;
}
}
}
} else {
accelX = game.getInput().getAccelY();
}
return accelX;
}
The calculateInputAcceleration() method is where we actually interpret the user input. If touch
is enabled, we check whether the left or right onscreen movement button was pressed and, if
so, we set the acceleration value accordingly to either −5 (left) or 5 (right). If the accelerometer is
used, we simply return its current value on the y axis (remember, we are in landscape mode).
private void updateGameOver() {
List<TouchEvent> events = game.getInput().getTouchEvents();
int len = events.size();
for ( int i = 0; i < len; i++) {
TouchEvent event = events.get(i);
if (event.type == TouchEvent. TOUCH_UP ) {
Assets. playSound (Assets. clickSound );
game.setScreen( new MainMenuScreen(game));
}
}
}
The updateGameOver() method is again trivial and simply checks for a touch event, in which case
we transition to the MainMenuScreen .
@Override
public void present( float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClear(GL10. GL_COLOR_BUFFER_BIT | GL10. GL_DEPTH_BUFFER_BIT );
guiCam.setViewportAndMatrices();
 
Search WWH ::




Custom Search