Game Development Reference
In-Depth Information
19.
Add a
Step, Step
event and include a
Test Variable
action that checks if the
Variable
state
is
equal to
ESTATE_WAIT
. We're going to use the
Step
event to control the Beastie's
state machine using the state variable, so there will be a check for each state in turn
and a different set of behaviors for each one.
20.
Follow this with a
Speed Horizontal
action (
move
tab) that sets
Hor. Speed
to
0
. The
wait state is the simplest state—the Beastie just stands still. There is no transition out
of this state in the
Step
event, as we will handle this with an
Alarm
event in a moment.
21.
Include a
Test Variable
action (
control
tab) that checks if the
Variable
state
is
equal to
ESTATE_MOVE
.
22.
Follow this with a
Start Block
action. The move state is going to be more complicated.
23.
Include a
Speed Horizontal
action (
move
tab) that sets
Hor. Speed
to
facing
. The
basic behavior of the move state is simply that—moving. However, we also need to
cope with transitions into other states when required.
24.
Include a
Check Object
action (
control
tab) to check if there would
NOT
be a collision
with an instance of
obj_platform
at a
Relative
position of
X
=
facing*16
,
Y
=
1
. This
checks for when the Beastie has reached the end of the platform he is walking along.
25.
Follow this with a
Set Variable
action that sets the
Variable
state
to
ESTATE_DECIDE
.
This is the default state for deciding what to do next.
26.
Include a
Check Object
action to check if there would be a collision with an instance of
obj_enemy_limit
at a
Relative
position of
X
=
facing*16
,
Y
=
0
. The enemy limiter objects
will turn Beastie enemies around too.
27.
Follow this with a
Set Variable
action that sets the
Variable
state
to
ESTATE_DECIDE
.
28.
Include a
Test Chance
action with
150
Sides
. We want the Beastie to randomly change
state sometimes and at a room speed of 30 steps per second, we would expect this
event to fire once every 5 seconds (on average).
29.
Follow this with a
Set Variable
action that sets the
Variable
state
to
ESTATE_DECIDE
.
30.
Include an
End Block
action.
31.
Include a
Test Variable
action that checks if the
Variable
state
is
equal to
ESTATE_DECIDE
. This is the state that will decide what to do next.
32.
Follow this with a
Start Block
action.
33.
Include a
Test Variable
action with
point_distance(x,y,obj_zool.x,
obj_zool.y)
for
Variable
,
smaller than
for
Operation,
and
150
for
Value
. Make sure you type that first
part of this very carefully with all the commas, dots, and parenthesis in the correct
places, otherwise you'll get problems. Actually, this is not a variable at all, but Game
Maker allows us to treat the result of a function like
point_distance
as a value. This
function calculates the distance between two points, which in our case are
x
,
y
(the
position of the Beastie) and
obj_zool.x
,
obj_zool.y
(the position of Zool).
Search WWH ::
Custom Search