Game Development Reference
In-Depth Information
Next, fill in the onCollisionBunnyWithGoldCoin() method with the
following code:
private void onCollisionBunnyWithGoldCoin (GoldCoin goldcoin) {
goldcoin.collected = true;
score += goldcoin.getScore();
Gdx.app.log(TAG, "Gold coin collected");
}
This code handles collisions between the bunny head game object and a gold coin
game object. It simply flags the gold coin as being collected so that it will disappear.
Furthermore, the player's score increases by the value the gold coin game object
returns from its getScore() method.
Finally, fill in the onCollisionBunnyWithFeather() method with the
following code:
private void onCollisionBunnyWithFeather (Feather feather) {
feather.collected = true;
score += feather.getScore();
level.bunnyHead.setFeatherPowerup(true);
Gdx.app.log(TAG, "Feather collected");
}
This code handles collisions between the bunny head game object and
a feather game object. The handling of this collision is similar to the
onCollisionBunnyWithGoldCoin() method, but it also activates or refreshes the
power-up effect for the bunny head.
Now, let's make one more modification to the update() method of
WorldController :
public void update (float deltaTime) {
handleDebugInput(deltaTime);
level.update(deltaTime);
testCollisions();
cameraHelper.update(deltaTime);
}
You can now run the game to verify that the level loading and collision detection
works. Within a very short time span, you should see that the player's character
falls down a bit and then stops on top of the rock underneath it. The following is a
screenshot of this scene:
 
Search WWH ::




Custom Search