The fundamental theory of optics is "The incoming and outgoing angle relative to the surface's normal are the same". Because light behaves as particles, this means objects that bounce without deforming will also bounce according to this rule.
So, when there's a collision:
- Get the angle_difference between the surface normal (45, 135, 225 or 315 degrees for the four types of 45-degree slopes) and the direction the object is currently moving in plus 180 degrees (to get an outwards direction)
- Add a minus sign to that to get the "inverted angle"
- The object now moves in direction Surface Normal + Inverted Angle.
The tricky part is figuring out what the surface normal is. You could have an array of 4 values (approaching from the left, right, up and down directions... a cube would have 180, 0, 90 and 270 for these, while a diagonal
/| slope would have 135, 0, 135 and 270 - i.e., the left and up normals are the same). Or you could do it
properly and mess around with raycasts and stuff.