Game Development Reference
In-Depth Information
If there wasn't a collision, then lines 18 and 19 will move the instance forward one pixel
and line 20 will add one to the
dist
variable, accordingly. We now return to the start of the
while
loop, which will keep repeating this process until
dist
is greater than
max_dist
or the
script returns
true
as a result of finding a collision. Line 23 will therefore only ever be reached
if no collision was found and it returns
false
to indicate that this is the case.
Figure 11-5.
In this diagram, the black line has a length of one pixel and is rotated by the angle dirn. The
function lengthdir_x( 1, dirn ) provides the horizontal component of that line (in red) and lengthdir_y
provides the vertical component of that line (in blue)
Changing Lifts
There were also two scripts we created in Zool so that we could get hold of all adjacent lift
instances and change them all into another kind of lift object during the same step. The
check_object_returned
script provided the id of adjacent instances and the
change_instance_for
script used that id to change those instances into another kind of object. However, both of these
scripts can be simplified to a couple of lines of code in GML, so it isn't worth having them as
scripts at all anymore.
You can write the
check_object returned
script as:
returned = instance_place( x+dx, y+dy, find_obj );
Where
dx
and
dy
are the offsets required and
find_obj
is the type of object we're looking for.
Similarly, you can write the
change_instance_for
script as just two lines:
with( returned )
instance_change( change_obj, true );
Where
change_obj
is the type of object we want the instance to change into. Both of these
scripts have therefore been removed from
zoolgml.gmk
, and replaced with these lines where
they were called. However, another script has been added to handle the entire process of
switching lift instances called
change_lift_instances
and this uses both of these processes to
handle the majority of the lift changing process in one place.
Search WWH ::
Custom Search