Game Development Reference
In-Depth Information
lives--;
if (isGameOver())
timeLeftGameOverDelay = Constants.TIME_DELAY_GAME_OVER;
else
initLevel();
}
}
The player's character will now lose extra lives when falling down into the water.
You can verify this by checking the top-right corner of the game screen. Each missing
extra life will turn into a transparent bunny head icon. The game over delay and the
restart of the game after that are also working now.
There is still one small modification needed to fix the camera follow behavior.
Change the update() method of CameraHelper as follows:
public void update (float deltaTime) {
if (!hasTarget()) return;
position.x = target.position.x + target.origin.x;
position.y = target.position.y + target.origin.y;
// Prevent camera from moving down too far
position.y = Math.max(-1f, position.y);
}
Adding the game over text and the feather
icon to the GUI
Here, we add the game over text and the feather icon to our game.
Add the following method to WorldRenderer :
private void renderGuiGameOverMessage (SpriteBatch batch) {
float x = cameraGUI.viewportWidth / 2;
float y = cameraGUI.viewportHeight / 2;
if (worldController.isGameOver()) {
BitmapFont fontGameOver = Assets.instance.fonts.defaultBig;
fontGameOver.setColor(1, 0.75f, 0.25f, 1);
fontGameOver.drawMultiLine(batch, "GAME OVER", x, y, 0,
BitmapFont.HAlignment.CENTER);
fontGameOver.setColor(1, 1, 1, 1);
}
}
 
Search WWH ::




Custom Search