Game Development Reference
In-Depth Information
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;
}
}
@Override
public void
pause() {
}
@Override
public void
resume() {
}
@Override
public void
dispose() {
}
}
The remaining methods should be self-explanatory. Let's get to the last missing piece of our Mr.
Nom game: the game screen.
Abstracting the World of Mr. Nom: Model, View, Controller
So far, we've only implemented boring UI stuff and some housekeeping code for our assets and
settings. We'll now abstract the world of Mr. Nom and all the objects in it. We'll also free Mr. Nom
from the screen resolution and let him live in his own little world with his own little coordinate
system.