I'm a beginner, so this could be completely wrong, but here is how I would handle it. Let's assume you have a ball hitting a brick. When they collide, you want the side of the ball to flatten (by replacing the sprite) and the brick to have vibration lines coming out of the side that was hit.
BallObj
float x
float y
enum direction {North, East, South, West}
showCollision()
BrickObj
float x;
float y;
showCollision(impactDirection)
CollisionService
isColliding(obj1, obj2)
Given that rough structure, code would be:
if(isColliding(BallObj, BrickObj)) {
BallObj.showCollision()
BrickObj.showCollision(BallObj.direction)
}
BallObj::showCollision() {
image = ball_north.png //if traveling north
}
BrickObj.showCollision(impactDirection) {
image = brick_south.png //opposite of direction passed in
}
Then, each frame, maintain the direction the ball is traveling in the BallObj class by looking at the last coords before overriding with the new coords.
That example would work for 4 way directions. If you need 360 degrees, it becomes a bit more complex, but a similar approach should work. Also, if both objects are moving, they could both take the object they hit as a parameter, and check for a getDirection function off of the object. Curious to hear from the experts if this is how it would work out.