One simple way of detecting collisions (and of doing something useful with them) is mathematically. All that is needed is a comparison between the two colliding objects in question, thus asking/and answering the question "How close are they from each other"?
Such question is sometimes in the [computer] form:
IF (XA-XB)>C THEN COLLISION
where XA = the x position of object A, and
XB = '' ' '' ' '' B.
[Note how (XA-XB) is the actual distance between the objects,
that is, how far they are one from the other. Also, C is a
limit value that means how close the objects can be to each
other before trouble happens (before a collision occurs).]
Sometimes I like examples first, explanations later -much like invade first find out later but so very different!-, so I've set up a working example of this simple mathematical approach.
Let's see:
WORKING EXAMPLE
---------------
This is an example of a very simple mathematical way to detect collisions between MOBs (movable object blocks) on screen. This example is a program which will be shown as it was made from bottom up. If you follow the code and how it was written (and why), this example can also be a good reference on how to program in 8088 assembly.
** Everything: All sources and .COM zipped up and ready for d/l.
** Attempt 00: Setting things up.
** Attempt 01: First routines, One truck.
** Attempt 02: Two trucks.
** Attempt 03: Floor: Let's make them stand on something.
** Attempt 04: Cycling: Starting to move.
** Attempt 0B: Actual finished example.
Example of how a simple method of mathematical collision detection works. It shows two trucks moving towards one another on screen, bumping into each other and then turning back on the edges of the screen to repeat the cycle.