Game Development Reference
In-Depth Information
scoreVisual = Math.min(score, scoreVisual +250 * deltaTime);
}
private void onCollisionBunnyWithGoldCoin (GoldCoin goldcoin) {
goldcoin.collected = true;
AudioManager.instance.play(Assets.instance.sounds.pickupCoin);
score += goldcoin.getScore();
Gdx.app.log(TAG, "Gold coin collected");
}
private void onCollisionBunnyWithFeather (Feather feather) {
feather.collected = true;
AudioManager.instance.play(Assets.instance.sounds.pickupFeather);
score += feather.getScore();
level.bunnyHead.setFeatherPowerup(true);
Gdx.app.log(TAG, "Feather collected");
}
These changes add the code to trigger the sound effects for the Life Lost , Picked
up Gold Coin , and Picked up Feather events at the right time.
Next, add the following two import lines to the BunnyHead class:
import com.badlogic.gdx.math.MathUtils;
import com.packtpub.libgdx.canyonbunny.util.AudioManager;
After this, make the following changes to the same class:
public void setJumping (boolean jumpKeyPressed) {
switch (jumpState) {
case GROUNDED: // Character is standing on a platform
if (jumpKeyPressed) {
AudioManager.instance.play(Assets.instance.sounds.jump);
// Start counting jump time from the beginning
timeJumping = 0;
jumpState = JUMP_STATE.JUMP_RISING;
}
break;
case JUMP_RISING: // Rising in the air
if (!jumpKeyPressed) {
jumpState = JUMP_STATE.JUMP_FALLING;
}
break;
case FALLING:// Falling down
 
Search WWH ::




Custom Search