Amos Professional Manual  Contents  Index

Detecting Collisions


In this Chapter, you will learn how to turn moving objects into truly interactive game components, by giving them friendly or hostile personalities. These personalities depend on what happens when two or more objects collide, and all of the classic computer games demand continual monitoring for collision between moving objects. Collision detection must be instant, accurate and totally reliable, otherwise games will lack excitement and playability.

AMOS Professional provides a comprehensive range of functions that allow perfect monitoring for collisions between objects on screen: Bobs, Hardware Sprites, Computed Sprites or any combination of these different types. The detection routines are sensitive to the actual shape of your objects, so all results are incredibly accurate. There is not a single "classic" computer game that you cannot match in terms of speed and sensitivity when it comes to detecting collisions. Here is a synopsis of the options available.

Collision detection options
AMOS Professional permits effortless checking for a collision between any group of screen objects, by means of four powerful functions. Each function uses the same principle, which takes a single source object and then searches for collisions between that object and one or more targets. If the test is successful and a collision is detected, a value of -1 is returned, meaning True. On the other hand, if there is no collision, a value of 0 is given, meaning False.

As a default, the collision functions will test all relevant active objects for collision with the single object that you are interested in, but if you want to restrict your test to a selection of active objects, each function can be qualified with an optional setting for the range of targets. This range is set by specifying the number of the first object in the range to the number of the last target object you are interested in.

Here is a list of the four available collision tests:
BOB COL monitors for collisions between Bobs.
SPRITE COL monitors for collisions between Sprites.
SPRITEBOB COL checks a single Sprite for collisions with Bobs.
BOBSPRITE COL tests a single Bob for collisions with Sprites.

After a collision has been detected by one of those tests, you can make an immediate check for the other objects involved, using a collision function named COL, which is used like this:

collision=Col(number)
where the number relates to one of the objects being checked.

Most of these options are also available in the built-in AMAL animation system, to which Chapter 7.6 is devoted.

Types of collisions
There are three general categories of collision which can occur in a computer game:

Back    Next
07.04.01