Game Development Reference
In-Depth Information
feather.update(deltaTime);
clouds.update(deltaTime);
}
We added the new actors to the render() method and created a new update()
method so that we can collectively update all the game world objects in a level in one
call.
Finally, modify the update() method of WorldController as the following listings:
public void update (float deltaTime) {
handleDebugInput(deltaTime);
level.update(deltaTime);
cameraHelper.update(deltaTime);
}
These changes makes sure that all the game objects contained within the level will be
updated when the update() method of WorldController is called.
Adding the game logic
The next step will be to add the game logic that constitutes the rules of our game
world. However, the game logic will need to be able to detect the so-called collisions
between two game objects before it can handle all of our events, such as walking
over an item to collect it. So, we will implement a very basic collision detection
method that tests two overlapping rectangles. If an overlap is detected, it means that
there is also a collision between these two tested objects. So, we can bind a certain
action to this event in the game logic to handle collisions as required.
Adding collision detection
Here, we add the code to check the collision of the bunny head with each actor game
object, the gold coin, feather, and the rock.
First, add the following import lines to WorldController :
import com.badlogic.gdx.math.Rectangle;
import com.packtpub.libgdx.canyonbunny.game.objects.BunnyHead;
import com.packtpub.libgdx.canyonbunny.game.objects.BunnyHead
.JUMP_STATE;
import com.packtpub.libgdx.canyonbunny.game.objects.Feather;
import com.packtpub.libgdx.canyonbunny.game.objects.GoldCoin;
import com.packtpub.libgdx.canyonbunny.game.objects.Rock;
 
Search WWH ::




Custom Search