Game Development Reference
In-Depth Information
private void
drawPausedUI() {
Graphics g = game.getGraphics();
g.drawPixmap(Assets.
pause
, 80, 100);
g.drawLine(0, 416, 480, 416, Color.
BLACK
);
}
private void
drawGameOverUI() {
Graphics g = game.getGraphics();
g.drawPixmap(Assets.
gameOver
, 62, 100);
g.drawPixmap(Assets.
buttons
, 128, 200, 0, 128, 64, 64);
g.drawLine(0, 416, 480, 416, Color.
BLACK
);
}
public void
drawText(Graphics g, String line,
int
x,
int
y) {
int
len = line.length();
for
(
int
i = 0; i < len; i++) {
char
character = line.charAt(i);
if
(character == ' ') {
x += 20;
continue
;
}
int
srcX = 0;
int
srcWidth = 0;
if
(character == '.') {
srcX = 200;
srcWidth = 10;
}
else
{
srcX = (character - '0') * 20;
srcWidth = 20;
}
g.drawPixmap(Assets.
numbers
, x, y, srcX, 0, srcWidth, 32);
x += srcWidth;
}
}
The methods
drawReadUI()
,
drawRunningUI()
,
drawPausedUI()
, and
drawGameOverUI()
are
nothing new. They perform the same old UI rendering as always, based on the coordinates
shown Figure
6-8
. The
drawText()
method is the same as the one in
HighscoreScreen
, so we
won't discuss that one either.
@Override
public void
pause() {
if
(state == GameState.
Running
)
state = GameState.
Paused
;