Created
January 4, 2015 17:14
-
-
Save anonymous/007bd54b7ed4635014aa to your computer and use it in GitHub Desktop.
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
// 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