Game Development Reference
In-Depth Information
Now, add the following code to the init() method:
public void init () {
dimension.set(1, 1);
regHead = Assets.instance.bunny.head;
// Center image on game object
origin.set(dimension.x / 2, dimension.y / 2);
// Bounding box for collision detection
bounds.set(0, 0, dimension.x, dimension.y);
// Set physics values
terminalVelocity.set(3.0f, 4.0f);
friction.set(12.0f, 0.0f);
acceleration.set(0.0f, -25.0f);
// View direction
viewDirection = VIEW_DIRECTION.RIGHT;
// Jump state
jumpState = JUMP_STATE.FALLING;
timeJumping = 0;
// Power-ups
hasFeatherPowerup = false;
timeLeftFeatherPowerup = 0;
}
The preceding code initializes the bunny head game object by setting its physics
values, a starting view direction, and jump state. It also deactivates the feather
power-up effect.
Next, add the following code to the setJumping() method:
public void setJumping (boolean jumpKeyPressed) {
switch (jumpState) {
case GROUNDED: // Character is standing on a platform
if (jumpKeyPressed) {
// 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
case JUMP_FALLING: // Falling down after jump
 
Search WWH ::




Custom Search