Amos Professional Manual  Contents  Index

Detecting Collisions


Collisions with rectangular blocks
The last part of this Chapter explains how rapid checks can be made to see if an Object has entered a rectangular area of the screen. These screen "zones" can be used for collision detection in computer games, as well as for setting up buttons, control panels and dialogue boxes.

RESERVE ZONE
instruction: RESERVE memory for a detection zone
Reserve Zone
Reserve Zone number

The RESERVE ZONE instruction must be used to allocate enough memory for the exact number of zones required, before a SET ZONE command is given. There is no limit to the number that can be specified, apart from the amount of available memory.

To erase all current zone definitions and restore the allocated memory to the main program, simply give the RESERVE ZONE command without any number parameter.

SET ZONE
instruction: set a screen zone for testing
Set Zone number,x1 ,y1 To x2,y2

After memory has been allocated with the RESERVE ZONE command, SET ZONE is used to define a rectangular area of the screen which can be tested by the various ZONE functions. The command is followed by the number of the new zone, followed by its coordinates from top left to bottom right-hand corner.

ZONE
function: return the zone number under specified screen coordinates
number=Zone(x,y)
number=Zone(screen number,x,y)

The ZONE function is used to give the number of the screen zone at the specified screen coordinates x,y. These coordinates are normally relative to the current screen, but an optional screen number can be included before the coordinates.

After the ZONE function has been called, the number of the first zone at these coordinates will be returned, or a value of zero (False) will be given if no zone is detected.

This function can be used with the X BOB and Y BOB functions to detect whether or not a Bob has entered a specific screen zone, as follows:

X> N=Zone(X Bob(n),Y Bob(n))
Back    Next
07.04.06