I'm using SpriteKit's collision detection. It has a callback that looks like this:
- (void)didBeginContact:(SKPhysicsContact *)contact
The contact object has two physics bodies:
SKPhysicsBody *bodyA;
SKPhysicsBody *bodyB;
My game will have lots of objects, and of course I can test the categoryBitMask
to find out what collided with what. But given that I intend to have many kinds (not more than 32 of course) and might dynamically introduce new types, what's the most elegant way to do dynamic double dispatch to code the logic for collisions, explosions, points scored, etc that will result from all these collisions? Of course I can build a giant hairy if-statement, but I was hoping for something cleaner.
Maybe a lookup table storing selectors for the appropriate handlers? And then I index the lookup table by some combination of the categoryBitMasks
? I'd love to hear some suggestions.