Game Development Reference
In-Depth Information
// Lower Left
canvas.drawText("Ships: " + shipsLeft, fontSize, height - fontSize,
mPaint);
// Upper right
String str = "High: " + highScore;
canvas.drawText("High: " + highScore, width
- (fontSize / 1.2f * str.length()), fontSize, mPaint);
if (!sound) {
str = "Mute";
canvas.drawText(str, width - (fontSize * str.length()), height
- fontSize, mPaint);
}
if ( ! playing) {
if (loaded) {
str = "Game Over";
final float x = (width - (str.length() * fontSize / 2)) / 2;
canvas.drawText(str, x, height / 4, mPaint);
}
}
else if ( paused ) {
str = "Game Paused";
final float x = (width - (str.length() * fontSize / 2)) / 2;
canvas.drawText(str, x, height / 4, mPaint);
}
}
Updating Game Physics
The third step in the game life cycle is to update the game physics. This simply means updating the
positions of all sprites in the game. Listing 4-8 shows the implementation for Asteroids. Let's take a
closer look at this method:
1.
First, update the game sprites including the ship, photons, UFO, missile,
asteroids, and explosions.
2.
Update the scores.
3.
Start the UFO if the score reaches the UFO score threshold.
4. Create a new batch of asteroids if all have been destroyed.
Listing 4-8 also shows the method used to update the ship: updateShip() (note that sections have
been stripped from Listing 4-8 for simplicity). This method performs the following tasks:
Search WWH ::




Custom Search