Game Development Reference
In-Depth Information
guiCam.touchToWorld(touchPoint.set(event.x, event.y));
if
(OverlapTester.
pointInRectangle
(resumeBounds, touchPoint)) {
Assets.
playSound
(Assets.
clickSound
);
state =
GAME_RUNNING
;
}
if
(OverlapTester.
pointInRectangle
(quitBounds, touchPoint)) {
Assets.
playSound
(Assets.
clickSound
);
game.setScreen(
new
MainMenuScreen(game));
}
}
}
The
updatePaused()
method loops through any available touch events and checks whether one
of the two menu entries was pressed (Resume or Quit). In each case, we play the click sound.
Nothing new here.
private void
updateRunning(
float
deltaTime) {
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_DOWN
)
continue
;
guiCam.touchToWorld(touchPoint.set(event.x, event.y));
if
(OverlapTester.
pointInRectangle
(pauseBounds, touchPoint)) {
Assets.
playSound
(Assets.
clickSound
);
state =
GAME_PAUSED
;
}
if
(OverlapTester.
pointInRectangle
(shotBounds, touchPoint)) {
world.shoot();
}
}
world.update(deltaTime, calculateInputAcceleration());
if
(world.ship.lives != lastLives || world.score != lastScore
|| world.waves != lastWaves) {
lastLives = world.ship.lives;
lastScore = world.score;
lastWaves = world.waves;
scoreString = "lives:" + lastLives + " waves:" + lastWaves
+ " score:" + lastScore;
}
if
(world.isGameOver()) {
state =
GAME_OVER
;
}
}
The
updateRunning()
method is responsible for two things: checking whether the pause button
was pressed (and reacting accordingly) and updating the world based on the user input. The first