home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 6627 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Subject: Re: Collision Detects !!!!
  2. References: <4je2ks$a05@ftp.man.szczecin.pl>
  3. X-Newsreader: TIN [version 1.2 PL2]
  4. Path: imada.ou.dk!breese
  5. From: breese@imada.ou.dk (Bjorn Reese)
  6. Message-ID: <1996Mar30.173102.10460@imada.ou.dk>
  7. Sender: news@imada.ou.dk
  8. Nntp-Posting-Host: wagner.imada.ou.dk
  9. Organization: Dept. of Math. & Computer Science, Odense University, Denmark
  10. Date: Sat, 30 Mar 1996 17:31:02 GMT
  11. Newsgroups: comp.sys.amiga.programmer
  12.  
  13. Cezary Kobylinski (amigos@safona.tuniv.szczecin.pl) wrote:
  14. > I want to know what is the best method to detect collision between any 
  15. > bobs ?!
  16.  
  17. Use coordinate check as a quick and approximate detection.
  18.  
  19. 0) Assign a square to each object so that all pixels of the
  20.    object are within the square.
  21.  
  22. 1) Check if the squares of two objects overlaps with each other.
  23.  
  24. 2) If there was an overlap (and if you want more accuracy) apply
  25.    the blitter check or a similar mask check.
  26.  
  27. Assuming that (xpos,ypos) is the upper left corner of the bob,
  28. it could look something like this (must be done for each pair
  29. of a's an b's)
  30.  
  31.   if (a->flags.solid &&
  32.       (a->xpos < b->xpos + b->xsize) &&
  33.       (a->xpos + a->xsize > b->xpos ) &&
  34.       (a->ypos < b->ypos + b->ysize) &&
  35.       (a->ypos + a->ysize > b->ypos )) {
  36.     /* Overlap */
  37.   }
  38.  
  39. --
  40. Bjorn Reese                      Email: breese@imada.ou.dk
  41. Odense University, Denmark       URL:   http://www.imada.ou.dk/~breese
  42.  
  43. "It's getting late in the game to show any pride or shame" - Marillion
  44.