#7477 - GBA Coda - Wed Jun 18, 2003 3:07 pm
Hi Guys,
Anyone here know any fast ways of doing collision detection in shoot 'em ups?
kinda experiencing slowdown in my demo...
currently i have the player shooting 12 shots at a time, But when i get about 20 enemies on screen -*the game dies*-
help!
GBA Coda ( kinda )
_________________
Expression has no effect in function Main()!
#7505 - Daniel Andersen - Wed Jun 18, 2003 9:16 pm
If you want to do pixel-based collision detection, i.e. for overlapping rectangles, save with each sprite-frame a table with a word (32bit) for each row in that frame; each word then contains the whole row interpreted as bits instead of bytes, that is, each non-zero pixel n has its corresponding n'th bit set.
In this way collision detection is easy; on each row, first do a logical shift on a row of one of the tables to make the X-coordinates match, then do a AND on the resulting words (e.g. the two rows from the tables). If the result is non-zero a collision has occured, if it is zero no collision has occured. And there you have it! This pixelwise collision detection algorithm is linear, O(n) that is!
Needless to say you also have to compare the right table rows if the two sprites' Y-coordinates do not match.
I have implemented this algorithm in my Basic + Golden Environment called GNES (which is to come soon). It is very powerfull.
#7529 - GBA Coda - Thu Jun 19, 2003 11:44 am
Thanks a lot Guys!
i'm gonna try that stuff :)
_________________
Expression has no effect in function Main()!
#13159 - shunyata - Sat Dec 06, 2003 5:51 pm
i cant help but wonder if insertionsort (shellsort with only the 1- increment) would be slightly faster on such small sets of nearly sorted data...?