Mail Archives: djgpp/1997/02/12/08:22:39
In article <32f87f78 DOT 950435 AT ursa DOT smsu DOT edu>, aho450s AT nic DOT smsu DOT edu (Tony O'Bryan) writes:
>On Wed, 05 Feb 1997 06:21:03 -0600, tamasiu AT informatik DOT tu-muenchen DOT de wrote:
>
>>Hi!
>>What is the best/fastest way to do collision detection routines for a
>>Action game in Allegro?
>>Chris.
>
>The fastest way is probably to check for collision on the four "corners" of each
>image rectangle. However, that leaves a lot to be desired as far as accuracy is
>concerned. One method I use is to store the coordinate outline of each image
>and check if two images overlap at any point. It's more time-consuming, but
>it's more accurate.
>
Well I think it's quite easy...
You have two sprites a & b (the transparent color is index 0)
The coordinates & dimensions should be unsigned long
1 check the boundary boxes
1 is (b.x2 < a.x1) or (b.x1 > a.x2)? -> no collision
2 is (b.y2 < a.y1) or (b.y1 > a.y2)? -> no collision
2 pixel accurate collision detection
1 calculate the overlapping rectangle (x & y offsets in both sprites, with, height and
moduli for both sprites [at least amiga coders should know this term :)])
2 for all lines (in the overlapping rectangle)
for all pixels
is (a.pixel <> 0) AND (b.pixel <> 0)? -> collision!
I'll write this thing in the next few days in gasm.
If there is any demand for the source let me know. I'll post it here then.
--
Mario Koeppen
mk2 AT irz DOT inf DOT tu-dresden DOT de http://www.inf.tu-dresden.de/~mk2
- Raw text -