Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2015 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/007bd54b7ed4635014aa to your computer and use it in GitHub Desktop.
Save anonymous/007bd54b7ed4635014aa to your computer and use it in GitHub Desktop.
// Some global place
class CollisionMapping
{
enum Layer : Uint32 {
Terrain,
Actors,
}
// Maps individual collision types (bird, pipe etc) to a smaller set of
// more generic types to make them more manageable
// Should be configured manually
// Using strings instead of enums means it can be extended without modifying code
map<string, Layer> colliderTypeToLayer;
// Maps a Layer to a mask of layers to interact with
// Should be configured manually
UInt32 collidesWith[Layer.Size];
UInt32 contactWith[Layer.Size];
UInt32 getCollidesWithMask(string colliderType)
{
Layer layer = colliderTypeToLayer[derivedType];
return collidesWith[layer];
}
UInt32 getContactWithMask(string colliderType)
{
Layer layer = colliderTypeToLayer[derviedType];
return contactWith[layer];
}
};
Bird.swift?
collisionName = "bird"
//In the Scene, will eventually make a factory out of this
self.bird.addComponent(Colliding(
collisionsAs: ColliderType.Bird.rawValue,
CollisionMapping.getCollidesWithMask(collisionName),
CollisionMapping.getContactWithMask(collisionName)
)
self.bird.addComponent(
Physical(dynamic:true,
shape:.Circle(50)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment