Game Development Reference
In-Depth Information
if (jumpKeyPressed && hasFeatherPowerup) {
timeJumping = JUMP_TIME_OFFSET_FLYING;
jumpState = JUMP_STATE.JUMP_RISING;
}
break;
}
}
The preceding code allows us to make the bunny jump. The state handling in the
code will decide whether jumping is currently possible and whether it is a single or a
multi jump.
Next, add the following code to the setFeatherPowerup() method:
public void setFeatherPowerup (boolean pickedUp) {
hasFeatherPowerup = pickedUp;
if (pickedUp) {
timeLeftFeatherPowerup =
Constants.ITEM_FEATHER_POWERUP_DURATION;
}
}
public boolean hasFeatherPowerup () {
return hasFeatherPowerup && timeLeftFeatherPowerup > 0;
}
The preceding code allows us to toggle the feather power-up effect via the
setFeatherPowerup() method. The hasFeatherPowerup() method can be used to
find out whether the power-up is still active.
Next, add the following code to override the update() method:
@Override
public void update (float deltaTime) {
super.update(deltaTime);
if (velocity.x != 0) {
viewDirection = velocity.x < 0 ? VIEW_DIRECTION.LEFT :
VIEW_DIRECTION.RIGHT;
}
if (timeLeftFeatherPowerup > 0) {
timeLeftFeatherPowerup -= deltaTime;
if (timeLeftFeatherPowerup < 0) {
// disable power-up
 
Search WWH ::




Custom Search