From: mk2 AT irz DOT inf DOT tu-dresden DOT de (Mario Koeppen) Newsgroups: comp.os.msdos.djgpp Subject: Re: Collison detection fo Action game Date: 12 Feb 1997 05:08:44 +0100 Organization: Dept. of Computer Science, TU Dresden, Germany Lines: 39 Distribution: world Message-ID: <5drfoc$fub@irz401.inf.tu-dresden.de> References: <855142026 DOT 12716 AT dejanews DOT com> <32f87f78 DOT 950435 AT ursa DOT smsu DOT edu> Reply-To: mk2 AT irz DOT inf DOT tu-dresden DOT de NNTP-Posting-Host: irz401.inf.tu-dresden.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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