Game Development Reference
In-Depth Information
After this, simply call the new method in the update() method of WorldController :
public void update (float deltaTime) {
handleDebugInput(deltaTime);
handleInputGame(deltaTime);
level.update(deltaTime);
testCollisions();
cameraHelper.update(deltaTime);
}
The player is now controllable using the left and right arrow keys to move in the
corresponding direction. We also add an autoforward moving behavior if the game
is run on a non-desktop platform such as Android. Pressing either the Space bar key
or touching the display of your smartphone will trigger the player character to jump.
You can now run the game once again and try to pick up the first items as well as
try to carefully jump from rock to rock without falling from the edge. Moreover, you
might want to check what happens when you fall down. Obviously, nothing will
happen in this case as we have not added any game logic yet to handle it properly.
We also want to make the camera stop following the player's character too far down
the level to make it more clear to the player that the level ends at the height of the
water and to avoid a graphical glitch.
In a later chapter, we will take a closer look at a full-blown physics
engine called Box2D that implements all the necessary features to
detect a collision. However, we will not revise our implementation
by replacing it with Box2D's one because Canyon Bunny does not use
physically accurate movements to make the game feel right. Trying to
make real-world physics simulations do unrealistic physics can be a
very hard and tedious task.
Losing lives, game over, and fixing the
camera
Whenever the player falls into the water, it will cost one extra life. The game will be
over as soon as there are no extra lives left and the player falls into the water once
again. There will be a short delay of three seconds between the game over message
and a complete restart of the game.
Add the following lines to Constants :
// Delay after game over
public static final float TIME_DELAY_GAME_OVER = 3;
 
Search WWH ::




Custom Search