Thanks for the response.
Quote:I just want to point out that the way you're doing it does alot of superfluous checking which would result in double handling of collisions plus it's O(x^2) speed which doesn't scale well with increased amounts of game objects.
Yeah its a relatively small 2d shooter in XNA. I have code that makes sure it doesnt do detections if the two objects are the same, not active, etc. I could probably minimize tests using quad trees or some other optimization, but I'm not hurting at all in performance so I dont think I should worry about optimization.
I originally had separate lists for the different kinds of objects, but I like having all of them in one because it makes maintaining them easier.
Quote:I also want to point out that what you're doing is not a double dispatch (atleast the part that you've shown) but rather a normal single dispatch. Nothing wrong with that, it just doesn't provide typesafety the way a double dispatch does. More information can be found here.
I guess it really isnt since C# doesnt support it, but what I do exactly is I use reflection to put all the collide methods and their methodinfo in a static hash for the gameObject so at runtime the proper collide method is called, so code like this works :
public void Collide(Shot shot) { HitPoints -= (int)(100 * shot.Damage); if (HitPoints <= 0) { isDead = true; world.doEnemyKillAction(this); } } public void Collide(PlayerShip playerSet) { isDead = true; world.doEnemyKillAction(this); }
My original question has to deal with not having to perform the world.doEnemyKillAction. I guess I will just look into C#'s event handlers with delegates and use some form of the observer perhaps with the OnDeath event.
I included all the original code to attempt to give context such that I wouldnt have to change that code ever if I added new kinds of objects.