Amos Professional Manual  Contents  Index

Detecting Collisions


SPRITEBOB COL
function: test for collision between one Sprite and range of Bobs
c=Spritebob Col(number)
c=Spritebob Col(number,start To finish)

As its name suggests, this function checks for a collision between the Sprite whose number you specify, and one or more Blitter Objects. If the Sprite collides with a Bob, a value of -1 (true) is returned, otherwise 0 (false) is given.

This function will test for collisions with all Bobs on screen, but the checking process can be restricted with the optional setting of the range of Bobs to be monitored, from the first Bob number to the last in the range. If you need to test for collisions between several Sprites and Bobs, the command should be enclosed in a loop, like this:

X> For FIRSTSPRITE=1 To LASTSPRITE
    If Spritebob Col(FIRSTSPRITE,FIRSTBOB To LASTBOB) Then Boom
   Next FIRSTSPRITE

Remember that all specified Sprites must be assigned to a masked image, before collision detection can work. You are also warned that this function will only work with low resolution screens, and attempts to use it in high resolution will lead to unpredictable results. This is because your Sprites and Bobs are likely to have different sized screen points.

BOBSPRITE COL
function: test for collision between one Bob and range of Sprites
c=Bobsprite Col(number)
c=Bobsprite Col(number,first To last)

This function checks for a collision between the single Bob whose number you specify, and all active Sprites on screen. The result will be -1 (true) is a collision is detected, or 0 (false) if the object remains untouched. To narrow the range of Sprites to be monitored, simply include the first to the last number in that range. As with SPRITEBOB COL, this function should only be used in low resolution.

COL
function: test status of an object after collision detection
status=Col(number)

One obvious problem with all of the previous detection functions is that they only report on whether an individual object has been hit. To discover information about any other objects involved in a collision, the COL function is used. This means that each object can be tested on its own, to see if it has collided with the source object.

Give the number of the object you wish to test, either a Bob or a Sprite, depending on the circumstances, and its status will be reported with a value of -1 (true) if it has collided, or 0 (false) if it remains untouched.

Back    Next
07.04.04