Game Development Reference
In-Depth Information
Figure 2-8. The room editor showing just the middle sections of the platforms
State Machines
Platform games are not trivial things to program and they usually require far too many different
behaviors to be able to try and consider programming them all at once. State machines provide a
way of breaking down large programming tasks into smaller chunks so that you can consider
them more easily. They can help you to create programs that are more easily understood and
contain fewer bugs as a result. In this example, we're going to use a state machine for our main
character, as Fishpod has a number of different states that affect the way it behaves. Our game
description at the start of the chapter listed five different states: standing, walking, jumping,
falling, and dying. Apart from the obvious differences in appearance, the character's behavior in
these five states should be quite different too. For example, you would expect him to
automatically fall down the screen when he is in his falling state, but not in his standing state. We
can briefly describe these different behaviors as follows:
Standing motionless on a platform's surface.
Walking horizontally across a platform's surface.
Jumping diagonally under momentum and the influence of gravity.
Falling under the influence of gravity.
Dying under the influence of gravity and without collisions.
 
Search WWH ::




Custom Search