Game Development Reference
In-Depth Information
Obviously, it must be possible for Fishpod to change states as well, but the conditions for
doing so also depend on the current state; so pressing the left arrow should change Fishpod into
the walking state from the standing state, but not from the falling state. Figure 2-9 shows these
five states and the relationships between them, with each arrow representing a different potential
path for changing states.
Figure 2-9. A (finite) state machine diagram for the Fishpod character. “Collision” refers to a collision
between Fishpod and a platform, unless otherwise specified. “Supported/not supported” refers to whether
Fishpod has a platform directly below him or not. Note that the two blue arrows are the only state transitions
directly controlled by the player by pressing keys
If you read our previous topic, then you'll know that it's possible to represent different states
like this by creating separate objects for each state and using the Change Instance action to
switch between them when required. Change Instance turns an instance of one type of object
into another while keeping the same position, direction, and speed or any other individual
properties of the instance. We'll see how this works in practice a bit later, but first we need to
consider the additional complication created by the different directions the character can be
facing.
Although we have shown five states in our state machine, there will actually be ten states in
this game, as each of the five states can either be facing left or right. We could easily go ahead and
create different left and right objects for each state, but this would seem to over-complicate the
situation, and the whole point of a state machine is to make things easier. Instead, we will use a
variable to keep track of which direction the character is facing, using a value of 1 for facing left
and a value of 2 for facing right. This is great for Game Maker, as numbers are fast and easy for
computers to process, but not so great for us because it is easy to forget what the values mean.
Fortunately, Game Maker provides constants as a way of creating memorable names for
important values you are using in your game.
 
Search WWH ::




Custom Search