Game Development Reference
In-Depth Information
Next, add the following lines to WorldController :
private float timeLeftGameOverDelay;
public boolean isGameOver () {
return lives < 0;
}
public boolean isPlayerInWater () {
return level.bunnyHead.position.y < -5;
}
In isPlayerInWater() , we test the bunny head's vertical position to find out
whether it fell down into the water. As the water is placed at the bottom edge of the
screen ( y = 0 ), we simply need to look for a value smaller than this. In our example,
we use -5 instead of 0 to also add a little delay in time. This is because travelling all
the way down to the vertical position of -5 simply takes longer than it would do if
we were using 0 . The resulting effect is that the game will enforce a little pause on
the player after each lost life.
After this, make the following modifications to init() and update() in
WorldController :
private void init () {
Gdx.input.setInputProcessor(this);
cameraHelper = new CameraHelper();
lives = Constants.LIVES_START;
timeLeftGameOverDelay = 0;
initLevel();
}
public void update (float deltaTime) {
handleDebugInput(deltaTime);
if (isGameOver()) {
timeLeftGameOverDelay -= deltaTime;
if (timeLeftGameOverDelay < 0) init();
} else {
handleInputGame(deltaTime);
}
level.update(deltaTime);
testCollisions();
cameraHelper.update(deltaTime);
if (!isGameOver() && isPlayerInWater()) {
 
Search WWH ::




Custom Search