I'm gonna show you a pretty slow and stupid way of doing this, but it's simple, and once you get it to work you can propably optimize it by yourself.
It's about calculating where two straight lines intersect. Can be done with rounded shapes too, but that's another deal. If we have just vertical and horizontal terrain it's even easier. The way I do it is that I check collision between the projectile's trajectory and all the surfaces. You can propably create some kind of system that only checks those surfaces that are relevant, but we want to keep it as simple as possible here so just say all of them.
If
A is the point where the bullet is created and
B is the point where it has traveled as long as you want your weapon's range to be, you could calculate a straight line
A to
B that's defined y=kx+m. You can get k and m out of the positions of the two points.
Now if we want to check where this line intersects with a vertical surface of the terrain, we do like this:
We want
hitpoint. We know that
hitpoint's x-value is 4, since that is the position of the vertical surface. Thing is, we also know that hitpoint is on the line
AB. So, hitpoint is on
AB, and it's x-value is 4.
y = k*4 + m
We have k and m since earlier, so now it's easy to get the y-value of
hitpoint. What we know do is that we check if this y-position is below the top of the vertical surface and above its bottom. If so, we have an intersection.
Then we do this with all surfaces. With the horizontals you do the same thing, exept y is the known, like this:
4 = kx+m
Save those hitpoints that are intersections, and later check wich one of them is closest to
A. That's the one where the bullet impacts.
If you want tilted lines in the collision geometry you put two lines equal to each other to get their intersection point.