Game Development Reference
In-Depth Information
else
scoreString = "score: " + lastScore;
Settings.
addScore
(lastScore);
Settings.
save
(game.getFileIO());
}
}
In the
updateRunning()
method, we first check whether the user touched the pause button
in the upper-right corner. If that's the case, then the game is put into the
GAME_PAUSED
state.
Otherwise, we update the
World
instance with the current delta time and the x-axis value of the
accelerometer, which are responsible for moving Bob horizontally. After the world is updated, we
check whether our score string needs updating. We also check whether Bob has reached the
castle; if he has, we enter the
GAME_NEXT_LEVEL
state, which shows the message in the top-left
screen in Figure
9-2
and waits for a touch event to generate the next level. In case the game is
over, we set the score string to either
score: #score
or
new highscore: #score
, depending on
whether the score achieved is a new high score. We then add the score to the
Settings
class
and tell it to save all the settings to the SD card. Additionally, we set the game screen to the
GAME_OVER
state.
private void
updatePaused() {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int
len = touchEvents.size();
for
(
int
i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if
(event.type != TouchEvent.
TOUCH
_
UP
)
continue
;
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
if
(OverlapTester.
pointInRectangle
(resumeBounds, touchPoint)) {
Assets.
playSound
(Assets.
clickSound
);
state =
GAME
_
RUNNING
;
return
;
}
if
(OverlapTester.
pointInRectangle
(quitBounds, touchPoint)) {
Assets.
playSound
(Assets.
clickSound
);
game.setScreen(
new
MainMenuScreen(game));
return
;
}
}
}
In the
updatePaused()
method, we check whether the user has touched the RESUME element or
QUIT UI element and react accordingly.
private void
updateLevelEnd() {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int
len = touchEvents.size();
for
(
int
i = 0; i < len; i++) {