Game Development Reference
In-Depth Information
1: {
2: var yoff, xdirn, x1, y1, x2, y2;
3:
4: xdirn = argument0;
5: yoff = argument1;
6:
7: if( xdirn > 0 )
8: {
9: x1 = bbox_right;
10: x2 = bbox_right+1;
11: }
12: else
13: {
14: x1 = bbox_left-1;
15: x2 = bbox_left;
16: }
17:
18: y1 = y+yoff-32;
19: y2 = y1+32;
20:
21: if( collision_rectangle(x1, y1, x2, y2, obj_wall, true, true) > 0 &&
22: collision_rectangle(x1, y1+80, x2, y2+80, obj_wall, true, true) > 0)
23: return true;
24: else
25: return false;
26: }
This script takes two arguments: the first indicates the direction to look for walls (a
negative value for left and a positive for right), and the second provides an optional
vertical offset (for when you want to “look-ahead” above or below the character).
Lines 7-16 set up the left and right boundaries of a very thin rectangle that starts at
the edge of the bounding box and extends just one pixel beyond (see Figure 12-3, left).
Lines 18 and 19 then set the top and bottom boundaries of this rectangle to
correspond to the area just below Flynn's hands, and then lines 21 and 22 check for
instances of obj_wall within both this rectangle and one 80 pixels beneath it. The use
of the && (and) operator means that the script will only return true if both tests
succeed; otherwise, it returns false.
7.
So there are now a number of places where we will use this script instead of the
existing code that checks for walls. Open obj_flynn_air and obj_flynn_land in turn
and edit their End Step events. In each one, change the line that reads:
if( place_meeting( x+facing, y, obj_wall ) == true )
to:
if( is_climbable( facing, 0 ) == true )
 
Search WWH ::




Custom Search