2D Terrain Collision Detection

I am messing around with a project, built in the style of a 2D side-scroller game.

The ground will eventually look something similar to this:

https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQM0ZuDsGAhtcVtvuacBfcYdppdSg438k5GHFY3vgI3OcP2QTpkHA

What is my best course of action for collision detection assuming the only data I’ll have are the 2D Vector coordinates of each vertex on the terrain?

That should actually be fairly simple.

What I would do is create a low poly mesh of the terrain. Go through every couple of vertices in the terrain and find the average “height” for the data points. Store these in a list somehow. Then, when the player moves, simply find the vertex in the low poly mesh that the player would be “touching” and then perform a point to rectangle collision detection.

wouldn’t this provide a somewhat loose collision detection? with the result being that the bounding box of the character sometimes going inside the mesh?

or would they be so close together that it wouldn’t matter?

You can use Box2D for this quite well. I’ve recently experimented with generated 2D polygon terrain and Box2D physics, and this turned out to be very doable. The ground shape can be a ChainShape, which is basically a chained line. I also experimented a bit with updating the ChainShape so that it only covered a bit of ground below the player (to be updated whenever the player reached the edge), but that turned out to be unnecessary performance-wise.

Here’s the repository of a prototype lander-style game (very rough pre-alpha) if you are interested: https://bitbucket.org/BasvS/lander
Here I generate the landscape: https://bitbucket.org/BasvS/lander/src/316dd5c7ef29108b7d056a846bd58bbe1f16a678/lander/src/nl/grunnt/lander/mission/MissionGenerator.java?at=master
Here I create a Box2D shape of the landscape https://bitbucket.org/BasvS/lander/src/316dd5c7ef29108b7d056a846bd58bbe1f16a678/lander/src/nl/grunnt/lander/EntityFactory.java?at=master

p.s. LibGDX comes with Box2D built in