Game Development Reference
In-Depth Information
3.
Now add an Alarm, Alarm0 event to obj_skeleton_land and include an Execute Code
action containing the following code:
1: {
2: if( is_passable_for_enemy( facing*32 ) != true )
3: facing = -facing;
4:
5: state = ESTATE_MOVE;
6: }
This uses the same is_passable_for_enemy function to see if the skeleton's path is clear
at the end of a wait, and reverses his direction before entering the move state again if it
is blocked.
Try out the game now and observe the moving skeletons. If you placed some directly in
front of your start point before then you'll need to remove them again now as they won't cope
well with ramps (make sure you don't accidently delete the ramps in the process). You can now
also give Archie a proper test on moving targets. However, the skeletons still don't respond to
the parrot or Flynn, so we'll start to address that next.
A Deathly Stare
So now we'll make the skeleton's behavior a bit more interesting by including the concepts of
pursuit and line of sight. Flynn will need to be fairly close to a skeleton and within its line of
sight in order to trigger a pursuit in the first place. However, you might have noticed that there
isn't actually a state for pursuing. This is because the movement state already does everything
we need; we just have to be more discerning about when to change direction during a pursuit.
In order to make this work, we will force the skeleton into the wait state when he is in
pursuit of a target, but not facing it. At the end of the wait, we will change his direction so that it
is facing his target before moving again. Using this method, skeletons will both pursue the
player and patrol up and down beneath Flynn when he is on a higher platform.
Implementing the Pursuing Behavior for the Skeleton Object
1. Open the Create event of obj_skeleton_land and add all of the following variable
initializations:
1: target_obj = obj_flynn;
2: target_hidden = false;
3: target_dist = 0;
4: pursuing = false;
5: gravity = 0;
6: speed = 0;
7:
8: x1 = 0;
9: x2 = 0;
10: y1 = 0;
11: y2 = 0;
 
Search WWH ::




Custom Search