Checking for collisions in a single list

BlitzMax Forums/BlitzMax Programming/Checking for collisions in a single list

I have a single list in a tentity type that all of my other game types are extended from, for example player, enemies, bullets and so on. All seems to work well, I can update all of my game objects by running through this single list that everything gets added to when it is created.

The problems begin when I try to check for a collision between two of the object in the one, single list. How can I check for example for collisions between the players bullets and the enemies to see if they have been hit? Is there a way to find out whether a type is an enemy or a player and so on? I`m a little confused but I`m sure that the solution is really simple.

Do I need to use multiple lists instead? One for the enemies, one for the bullets... I`d really like to stick to the one if possible.

Any examples or help would be most appreciated.

Jason.

its as simple as:
for e:enemy=eachin entitylist

for b:bullet=eachin entitylist

collisions

next

next


Ouch... isn't that going to be painfully slow?

I posted an example the other day, where you can hide away the fact that you are using multiple lists. Smaller lists would mean more efficiency, in theory.

What if you were to put all the bullets on one layer, enemies on another and the player on a third?

Yes, check out the layering capability of the BMax collision checking functions: It's a little weird at first, but it is more efficient because you can group items by how they are supposed to interact: Bullets shouldn't collide with other bullets, for example.

Or, check the type of the object before collision checking (if the current object is a bullet, skip over other bullets objects, etc).

Russell

Smaller lists would mean more efficiency, in theory.


Yeah, in theory... In practice there may also be negative effects on performance (eg. cache misses) from multiple lists. Unless there's a great need of performance, using a single list is good enough. And for something that performance critical, TList is way too slow.

Thanks for the help. So is there a way to check the type of an object just out of interest?

Jason.

For Local obj:Object = EachIn MyList
	
	If TPlayer(obj)
	  Local player:TPlayer = TPlayer(obj)
		'etc..
	Else If TBullet(obj)
	  Local bullet:TBullet = TBullet(obj)
		'etc..
	End If
	
Next


Something of that sorte.

Thanks, I`ll give it a go.

Jason.

Use callbacks for collisions, it is a much better solution.

Use callbacks for collisions, it is a much better solution.

Only in 3D.

I've tried to find some more information specific on callbacks for collisions and i found a lot of threads pointing toward a document on a guys website that no longer exist.

Could you point me in the right direction for some more information about this? Because i don't know exactly what to look for i just get too much hits in google where the words just exists but there's nothing specific on collision callbacks. I know, i should find it myself but it would really help if you could point me in the right direction.

I read this but i just don't understand it :(

Oh wait, just in 3D? I only want to make 2D games. What would be the 'best' solution for 2D in your opinion?
Sigh, i should stay in the beginners corner.

I don't use bmax pixel collision routines, but for circle, dist, rect, etc, I just iterate each bullet through a list of sprites (as JP said) and it works fine. Even with hundreds (or 1000's) of objects on screen.

"iterate each bullet through a list of sprites"

I'm sorry but i don't understand what that means.
I have my big list with all my gameobjects, i cycle thrue them and then... ?