|
Post by TheSquirrelly1 on Jul 1, 2004 11:26:30 GMT -5
Ok... I've got my 2D Side scrolling game with a character that can runn around, jump over holes, and shoot small little balls (thanks for that .png by the way ), all of this and NPCs that just bounce around between walls (kinda Mario-ish, huh?)... Now on to more pressing issues.... I'm having trouble deciding how I should do the bullet/NPC collision... The only way I have been able to come up with is to cycle through every one of my bullets (up to BulletMax) and check it's bounds with EVERY NPC... So, if I have like 10 bullets on the screen, and 200 NPCs loaded in my level, it could (and probably would) take quite a while to calculate this every game cycle... Is there a better way to do this? Thanks, Squirrelly1
|
|
|
Post by AHBanen on Jul 1, 2004 14:07:34 GMT -5
Squirrelly1, Thinking out loud, I would try (in random order):
a) create a rough grid (e.g. 10*10) and hold in a 3D array (10*10*nr_of_NPCs) the book keeping if a NPC is in a specific part of the grid. Determine in which grid the bullet is and check collision with the NPCs only in that part of the grid
or
b) Do a book keeping of the NPC positions in polar format (angle distance, e.g from the top left corne)r. Sort the positions according to angle. [Note there may be more than one NPC that has the same angle) Determine the position of the bullet in polar format. Check which NPCs have the same angle, then check which have the same distance as the bullet.
c) Again book keeping: sort the positions of the NPCs according to X-axis. Sort the ones on the same X position according to Y-position. Determine position of the bullet (Xb,Yb) Determine which NPCs have the same X-position, then which of this subset have the same Y position as the bullet: Boom!
André
|
|
|
Post by TheSquirrelly1 on Jul 1, 2004 16:32:13 GMT -5
Can you give me an example of the polar collison thing?
And one more thing...
What is the best way to get the X and Y coordinates of a specific tile in my tile map? The collision I'm using forces my player sprite to be lifted off of the ground so that he doesn't colide with it...
Thanks,
Squirrelly1
|
|
|
Post by AHBanen on Jul 1, 2004 18:55:03 GMT -5
Squirrelly1, The Sprite thing I can't answer I haven't studied that part of Basic4GL yet.
The polar thing is easy: angle = atan( y/x) distance = sqrt( x*x + y*y)
Note: you can't store all angles; so you will have to make a choice, e.g. using increments of PI / 180 [= ( 3.14 / 2) / 90] to store 90 'wedges' radiating from the left top corner (the angles are all in radians).
In essence the polar solution isn't much different from the X-Y grid solution, just a different approach.
André
|
|