Created
April 23, 2012 22:06
-
-
Save slembcke/2474202 to your computer and use it in GitHub Desktop.
Wildcard collision handler musings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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