Article View: rec.games.programmer
Article #286Re: Collision detection PLEASE, all geniuses respond!
From: Cullhane Gibbs
Date: Thu, 30 Jul 1992 02:22
Date: Thu, 30 Jul 1992 02:22
70 lines
3667 bytes
3667 bytes
Greetings,
I personally believe that the both the sparse array approach & quad
tree method for programming collision detection in arcade type
games is inappropriate - mainly because there are much faster
methods
available. While its always a speed/memory tradeoff in
arcade type games, you really should endeavour to
get everything running around 50 frames a second thereby
allowing smooth animation etc. I really hate jerky scrolls and
jerky character movement. Having said that this is the way I
would approach the collision detection problem.
(1) For aliens on the screen - say in a shoot em up - unless
your'e lucky enough to be programming a machine with powerful
hardware sprites and collision detection, create rectangular
boundaries around the aliens and just test for overlap. Even
the the boundaries around the aliens are square during the heat
of action (and depending on the size and shape of aliens) most
players won't notice that a rectangular boundary, rather than a
pixel perfect collision has occurred.
(2) Background are a little more complex. Every one
whose created a scrolling or large playfield for a game will know
that you don't store a contiguous huge bitmap for the playfield.
Rather the playfield is built up from a set of , say , 16*16 blocks
that can be reused over and over. Under this method one ends up with
two main files:
(a) The bitmap graphic data describing the 16*16 blocks
(b) A gamefield data file describing which block are
placed where on the screen. The gamefield file contains
numbers that reference particular blocks.
One could now have a third file that contains tag info
on each block in the gamefield data file. Each number in
this file references the block numbers in the gamefield data
file. However these numbers may be constructed as follows:
If bit 0 of this byte is set then the player
can't walk through this block.
if bit 1 of this block is set the player loses
energy, etc, etc.
Now when the player is on the screen you convert
his position to a block position equivalent and
offset this position into the third file just
discussed, test the bits and then take the
appropriate action, e.g. stop moving or decrement
energy. Of course there are various variations on
this setup, but it is fast. You may also which to
increase the resolution on the blocks in the third
file, i.e. down to each fourth pixel set. Have you
ever noticed in some games, e.g. Turrican that when
you move your player to the edge of a platform he
can at the edge be standing on thin air. This is
because the tag information is only accurate to
a 16*16 block or what ever. This process may also
sound
painstaking for large playfields but if you write a
map editor or something the process is easily
(fairly) automated.
See ya,
Cully
Technical Details
Message-ID:
<1992Jul30.022252.26480@griffin.itc.gu.edu.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!usc!rpi!batcomputer!munnari.oz.au!bunyip.cc.uq.oz.au!griffin!medusa.itc.gu.edu.au!cullhaneReferences:
<1992Jul26.181425.207@micor.ocunix.on.ca> <19613@optima.cs.arizona.edu> <AXC.92Jul28165951@alfa.fct.unl.pt>Show Full Headers
Complete Article Headers
Newsgroups: rec.games.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!usc!rpi!batcomputer!munnari.oz.au!bunyip.cc.uq.oz.au!griffin!medusa.itc.gu.edu.au!cullhane From: cullhane@medusa.itc.gu.edu.au (Cullhane Gibbs) Subject: Re: Collision detection PLEASE, all geniuses respond! Message-ID: <1992Jul30.022252.26480@griffin.itc.gu.edu.au> Sender: news@griffin.itc.gu.edu.au Nntp-Posting-Host: medusa.itc.gu.edu.au Reply-To: cullhane@medusa.UUCP (Cullhane Gibbs) Organization: Griffith University, Brisbane, Australia References: <1992Jul26.181425.207@micor.ocunix.on.ca> <19613@optima.cs.arizona.edu> <AXC.92Jul28165951@alfa.fct.unl.pt> Date: Thu, 30 Jul 92 02:22:52 GMT Lines: 71