Game Development Reference
In-Depth Information
5.
Again in the
Step
event of
obj_skeleton_land
, alter the check before playing the
bootstep sound effect to include an additional line at the start, as follows:
1:
if( target_dist < EPURSUE_DIST*2 )
2:
if( image_index == 6 || image_index == 18 )
3:
sound_play( snd_bootstep );
This stops you from being able to hear footsteps from all skeletons on the whole level
at once—just the ones within a reasonable earshot distance. Note that putting two
if
statements directly after each other in this way is the same as combining the separate
expressions with a logical
and
operator, so you could use a single
if
statement and it
would do the same thing:
1:
if( target_dist < EPURSUE_DIST*2 &&
2:
(image_index == 6 || image_index == 18) )
3:
sound_play( snd_bootstep );
6.
Finally, for the
Step
event of
obj_skeleton_land
, change the
case
statement for
ESTATE_ATTACK
to include the following code. This will then play sword sound effects at
appropriate points in the animation when we trigger it later on.
1:
case ESTATE_ATTACK:
2:
if( image_index = 8 || image_index == 18 )
3:
sound_play( snd_sword );
4:
hspeed = 0;
5:
break;
7.
Now you can finally close the
Step
event and add an
Alarm, Alarm1
event to
obj_skeleton_land
. Include an
Execute Code
action containing the following code to
reset the pursuing state. It also resets the target object back to Flynn, as it will
sometimes change when skeletons start to pursue Archie as well.
1:
{
2:
target_obj = obj_flynn;
3:
pursuing = false;
4:
}
8.
Finally, edit the
Alarm, Alarm0
event and include the following code after the first two
lines that switch the direction of facing. This code simply changes the skeleton's facing
direction to look at its target when it is in pursuit. This is ultimately what creates the
pursuit behavior for the skeleton.
1:
if( pursuing == true )
2:
{
3:
if( target_obj.x > x )
4:
facing = FACE_RIGHT;
5:
else
6:
facing = FACE_LEFT;
7:
}
Search WWH ::
Custom Search