Skip to content

Instantly share code, notes, and snippets.

@slembcke
Created April 23, 2012 22:06
Show Gist options
  • Save slembcke/2474202 to your computer and use it in GitHub Desktop.
Save slembcke/2474202 to your computer and use it in GitHub Desktop.
Wildcard collision handler musings
static cpBool
PlayerTerrainBegin(cpArbiter *arb, cpSpace *space, void *data)
{
CP_ARBITER_GET_SHAPES(arb, playerShape, terrainShape);
GameObject *player = cpShapeGetUserData(playerShape);
GameObject *terrain = cpShapeGetUserData(terrainShape);
cpBool retvalA = player.collidedWith(terrain);
cpBool retvalB = terrain.collidedWith(player);
// Uh... Make the player muddy?
return cpTrue || retvalA && retvalB || whatever;
}
// This would be the default handler to be called when a specific handler doesn't exist
static cpBool
DefaultBegin(cpArbiter *arb, cpSpace *space, void *data)
{
CP_ARBITER_GET_SHAPES(arb, shapeA, shapeB);
GameObject *a = cpShapeGetUserData(shapeA);
GameObject *b = cpShapeGetUserData(shapeB);
return (a.collidedWith(b) && b.collidedWith(a);
}
// when the space is initialized:
cpSpaceAddCollisionHandler(space, PLAYER_TYPE, TERRAIN_TYPE, PlayerTerrainBegin, NULL, NULL, NULL, NULL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment