Game Development Reference
In-Depth Information
it has the ability to access the local variables of the calling instance in this way, but you must be
sure that your calling instance has those variables. Of course, every instance has these
bounding box variables, so this is not a concern here.
Finally, in lines 13-16, the script uses the collision_rectangle function to check for
instances of the object held by the variable stand_obj within a small rectangle beneath the
instance's feet (as in Figure 11-4). The last two arguments of the collision_rectangle function
specify that we want precise collision detection (which we do because we're looking for solid
landscape, and that includes ramps and slopes), and that we want it to ignore collisions with
itself (in case you wanted to check if a platform was on top of a platform). If it finds a collision,
then the function returns the id of one of the colliding instances (a value > 0) and if it doesn't,
then it returns a negative value. We don't care exactly which instance it is, so we return true
from the script if it is greater than 0 and false otherwise. This return value can then be used to
determine whether the script was successful in finding something to stand on.
Figure 11-4. Zool will now fall down in this situation (as he should) because we are only checking directly
beneath his feet (in red)
Note If you want to find out more about a Game Maker function like collision_rectangle or any of the
others discussed in this topic, then select Contents from the Help menu and type the name of the function
into the search tab. Usually, the first search result found will contain the help page for that function.
Staying in Contact
Since Chapter 5, we've used the move_to_contact_with script as a way of ensuring that Zool stops
when he comes into contact with a specific type of object, rather than all objects or just objects
with the Solid flag set (which we wish to avoid using altogether). It does this using a “brute force”
approach, moving one pixel at a time in the direction provided until it collides with an instance
of the specified object. Let's look at how that works.
 
Search WWH ::




Custom Search