I am working a tile-based platform game which currently uses bounding boxes and overlap checks for collision detection. I find this approach inflexible. I want to have different collision responses depending upon the type of tile.
My new idea is to use 9 points which surround my player object and check which of these points is within the bounds of the tile. One point on each corner, each side and one in the center. Each tile type would use a different set of rules for collision handling.
However each tile type would have to use a complex set of conditional statements for collision testing - perhaps overly complicated. Any guidance?
This sounds like a case for Strategy patterns: http://en.wikipedia.org/wiki/Strategy_pattern
Define an interface that is "process collision" and then a number of implementations of that interface for different collision rules.
For each tile you then just setCollisionStrategy(MyRuleHere)
.
To check for a collision you just identify the tile then
if (tile.getCollisionStrategy.collide(player)) {
// Collision
}
The collide method could even return an enumeration for different types of collision - or return a more complex object - or even process the collision itself and make changes in the player. The right approach there would depend on your overall architecture.