Game Development Reference
In-Depth Information
3.
Also within the
Step
event of
obj_skeleton_land
, insert these lines at the start of the
case
statement for
ESTATE_MOVE
, in front of what is there already:
1:
if( target_dist < EPURSUE_DIST && target_hidden == false )
2:
{
3:
if( pursuing == false )
4:
{
5:
pursuing = true;
6:
sound_play( snd_alerted );
7:
state = ESTATE_WAIT;
8:
alarm[0] = 30;
9:
}
10:
alarm[1] = 300;
11:
}
The first line ensures that this block of code is only executed if the target is close
enough (as defined by the constant
EPURSUE_DIST
) and it is not hidden according to the
line-of-sight tests.
Lines 3 and 5 make sure that the initial response to sighting the target is only
repeated once for each pursuit. This response is to play an alerted sound effect and
cause the skeleton to pause for a second, as if they are challenging the target to identify
themselves (lines 5-8).
Nonetheless, line 10 will continue to set alarm1 (used for the pursuit timeout) to 10
seconds for as long as the target is in sight. So Flynn will have to stay out of sight for 10
seconds before a skeleton will stop following him.
Still within the
Step
event of
obj_skeleton_land
, alter the check that uses the
is_pasable_for_enemy
script, so that it has an additional line at the end as shown.
if( is_passable_for_enemy( facing*32 ) != true ||
irandom_range( 0, 300 ) == 0 ||
(pursuing == true && facing != target_dirn && target_dist < EPURSUE_DIST) )
This has the effect of forcing the skeleton to go into the wait state if it is pursuing
something within range, but not facing toward it. At the end of the wait state (in the
Alarm0
event), we will change the skeleton's direction to face its target, and thereby
create the pursuit behavior we're after.
All three lines of the check are combined with the logical
or
operator, so this check
succeeds if the space in front of the skeleton isn't passable
or
a random number
between 0 and 300 returns 0, or the final line is true. However, the final line is actually
three separate conditions that are combined with the logical
and
operator (“
&&
”), so it
only succeeds if the skeleton is pursuing
and
it is not facing its target
and
its target is
not too far away. Notice that the final line has a set of brackets around the three
conditions that are combined with the
and
operators to indicate that they are grouped
together into one.
4.
Search WWH ::
Custom Search