Game Development Reference
In-Depth Information
timeLeftFeatherPowerup = 0;
setFeatherPowerup(false);
}
}
}
The preceding code handles the switching of the viewing direction according to the
current move direction. Also, the time remaining of the power-up effect is checked. If
the time is up, the feather power-up effect is disabled.
Next, add the following code to override the updateMotionY() method:
@Override
protected void updateMotionY (float deltaTime) {
switch (jumpState) {
case GROUNDED:
jumpState = JUMP_STATE.FALLING;
break;
case JUMP_RISING:
// Keep track of jump time
timeJumping += deltaTime;
// Jump time left?
if (timeJumping <= JUMP_TIME_MAX) {
// Still jumping
velocity.y = terminalVelocity.y;
}
break;
case FALLING:
break;
case JUMP_FALLING:
// Add delta times to track jump time
timeJumping += deltaTime;
// Jump to minimal height if jump key was pressed too short
if (timeJumping > 0 && timeJumping <= JUMP_TIME_MIN) {
// Still jumping
velocity.y = terminalVelocity.y;
}
}
if (jumpState != JUMP_STATE.GROUNDED)
super.updateMotionY(deltaTime);
}
The preceding code handles the calculations and switching of states that is needed to
enable jumping and falling.
 
Search WWH ::




Custom Search