Game Development Reference
In-Depth Information
The second case is that the turtle is in waiting mode, and the player is jumping on the turtle. In
that case, the player should make an extra-high jump. An easy way to check whether the player is
jumping on the turtle is to look at the y velocity. Assume that if that velocity is positive, the player is
jumping on the turtle. So, you call the jump method to make the player jump extra high:
else if (player.velocity.y > 0 && player.alive)
player.jump(1500);
And of course, you only want to do this if the player is still alive.
You now have the main interaction programming. In the next chapter, you finish this game by adding
mountains and moving clouds in the background. You also add the code that manages transitions
between the levels.
TO DIE OR NOT TO DIE?
I made a choice in this section that the player dies immediately when they touch an enemy. Another choice would be
to give the player several lives or to add a health indicator for the player that decreases every time the player touches
an enemy.
Adding multiple lives or a health indicator to a game can make the game more fun, but you also have to be sure the levels
are still challenging enough. A health bar makes sense only if the game's levels are much larger than in this chapter's
example. You also need to add side scrolling so that levels can be larger than a single screen.
Implementing side scrolling isn't that difficult: you draw all the game objects in the game world according to a camera
offset that moves along with the player. As a challenge, try to extend the Tick Tick game with side scrolling and add a
health bar for the player.
What You Have Learned
In this chapter, you have learned:
How to program various kinds of player interactions with water drops and
enemies
How to program ice tile behavior
How to cause the player to die in certain situations
 
Search WWH ::




Custom Search