Amos Professional Manual  Contents  Index

Detecting Collisions


Supposing you are testing Bob 1 for a collision between Bobs 2,3 and 4. The initial test could look like this:

X> C=Bob Col(1,2 To 4)

Alter the collision has been detected, you can check on the other objects using the COL I unction, as follows:

X> For B=2 To 4
    If Col(B) Then Print "You have hit Bob number ";B
   Next B

A faster version of this function allows instant monitoring for the second object in the collision, like this:

X> object=Col(-1)

This returns the number of the object which has collided with your target, or a zero if no collision has happened. So the alternative version to the last example is:

X> C=Bob Col(1,2 To 4)
   Print "You have hit Bob number ";Col(-1)

The AMAL equivalent of this function is C, and both are perfect for detecting collisions between individual "hostiles" and "friendlies". You simply check for a collision between each object with a BOB COL or SPRITE COL, then grab the number of the collision object with the COL function.

SET HARDCOL
instruction: set hardware register for hardware Sprite collision detection
Set Hardcol bitmap1 ,bitmap2

This command is available to experienced Amiga programmers, and it permits Sprite collision detection using the computer's hardware. SET HARDCOL cannot be used with computed Sprites, so only Sprites zero to 7 may be monitored for collision.

The CLXCON register is set for hardware Sprite collision detection using two parameters. Bitmap1 is an enabler, that sets bits 12,13,14 and 15 of the CLXON register, and bitmap2 determines the comparison itself, setting bits zero to 5. Please refer to your hardware manual for a technical explanation of this register.

HARDCOL
function: return collision status after a Set Hardcol instruction
c=Hardcol

Once the hardware register has been set with a SET HARDCOL command, the HARDCOL function can be used to read the system register CLXDAT, returning zero (False) if there is no collision, or -1 (True) if a collision is detected. The COL function can then be used to return the identification number of the colliding Sprite.

Back    Next
07.04.05