Game Development Reference
In-Depth Information
Line 2 checks if Archie has collided with the enemy instance that he's supposed to be
targeting and that he's not already in the distract state. If this is true, then lines 4 and 5
put Archie's into the distract state and set an alarm to 10 seconds.
Add an Alarm, Alarm0 event for obj_parrot and include an Execute Code action
containing the following code. This returns Archie to the follow state once the 10
seconds are up and resets the target.
1: {
2: state = ASTATE_FOLLOW;
3: target_id = noone;
4: }
4.
5. Now, return to the Step event of obj_parrot and expand the third case statement to
include the following code:
1: case ASTATE_DISTRACT:
2:
3: targetx = target_id.x - (facing*16);
4: targety = target_id.bbox_top;
5:
6: if( facing = FACE_LEFT )
7: targetx += obj_path_offset.x;
8: else
9: targetx -= obj_path_offset.x;
10:
11: targety += obj_path_offset.y;
12:
13: break;
Lines 3 and 4 set the initial target position to be just in front and above the target's
bounding box. Lines 6-11 then add or subtract the position of obj_path_offset from
the target position. Note that the horizontal position is added if Archie is facing left and
subtracted if he is facing right, flipping the path so that he always remains on the near
side of his enemy. This makes it possible to control which direction to lure enemies by
using Archie to attack them from the side you want them to move in.
Now, go to the Room Editor and place a couple of instances of obj_skeleton in front of
Flynn's start position in order to try out the new moves (don't worry if they float off the ground
for the ti me be i n g ). T r y di str acti n g the m fr om di ffe r e n t di r e cti on s a n d make sur e the pa th
mirrors correctly. If you have any problems with your version, then you can check it against the
file shadows5.gmk in the Chapter12/Games directory on the CD.
 
Search WWH ::




Custom Search