Amos Professional Manual  Contents  Index

Detecting Collisions


Before a detailed explanation of the collision functions, it is worth examining AMOS Professional in action with a ready-made program. This will demonstrate how collisions are handled.

Please load the following tutorial:

DP> Load "AMOSPro Tutorial:Tutorials/Collision_Detection.AMOS"

Now run the program and select Example 1. This shows how a simple bat and ball are made to interact, and to simplify things, the bat has been fixed in position! The collision detection in this example relies on the following line:

X> If Bob Col(1) Then Boom

Notice how the explosion effect is triggered the instant that the bat overlaps the ball, even by the smallest margin. Example 2 really sets the ball rolling!

The same instruction can also be used to detect collisions between a single source and any number of target objects, with the BOB COL function checking all of the Bobs automatically in Example 3.

To refine the system, and check for collisions with a smaller range of objects, simply add the first and last numbers of that range to the BOBSPRITE COL command, in the demonstration program. For example, changing the relevant line as follows will test for one red and one green ball only:

E> If Bobsprite 001(1,2 To 4) Then Bell 10

Masks
Invisible "masks" are created around images for two main reasons. Firstly they ensure that the background colour (zero) is transparent, so a masked Bob will merge with the current screen display. The second reason for masking an image is to provide AMOS Professional with a mechanism for detecting collisions. The collision detection functions will only work if a mask has first been created around the required images.

Masks are automatically defined around an image when that image is assigned to a Blitter Object, in other words, when the BOB command is used. But it is important to remember that Sprites have no masks unless you specifically attach them. So if you intend to make use of collision detection, it is vital to ensure that all your objects are wearing their masks.

MAKE MASK
instruction: mask an image for collision detection
Make Mask
Make Mask number

This command creates a mask around every one of the images in the Object Bank, and may take

Back    Next
07.04.02