Game Development Reference
In-Depth Information
The
presentLevelEnd()
method renders the string THE PRINCESS IS . . . at the top of the screen
and the string IN ANOTHER CASTLE! at the bottom of the screen, as shown in Figure
9-2
. We
perform some calculations to center those strings horizontally.
private void
presentGameOver() {
batcher.drawSprite(160, 240, 160, 96, Assets.
gameOver
);
float
scoreWidth = Assets.
font
.glyphWidth * scoreString.length();
Assets.
font
.drawText(batcher, scoreString, 160 - scoreWidth / 2, 480-20);
}
The
presentGameOver()
method displays the game-over UI element as well the score string.
Remember that the score screen is set in the
updateRunning()
method to either
score: #score
or
new highscore: #value
.
Finishing Touches
That's basically our
GameScreen
class. The rest of its code is given in Listing 9-23.
Listing 9-23. The Rest of GameScreen.java; the pause(), resume(), and dispose() Methods
@Override
public void
pause() {
if
(state ==
GAME
_
RUNNING
)
state =
GAME
_
PAUSED
;
}
@Override
public void
resume() {
}
@Override
public void
dispose() {
}
}
We just make sure our game screen is paused when the user decides to pause the application.
The last thing we have to implement is the
WorldRenderer
class.
The WorldRenderer Class
This class should be no surprise. It simply uses the
SpriteBatcher
we pass to it in the
constructor and renders the world accordingly. Listing 9-24 shows the beginning of the code.