If the landscape is a picture you have two options:
1 - Look at all the pixel values and do some sort of color comparison at any given X to find what the floor is at that position. i.e.
//Assume ground is a BufferedImage with type BufferedImage.TYPE_INT_ARGB
//Assume we have a ground color that is a 4 int array (might be like {0,0,0,0})
//x is the X position to check and startY is where the entity is standing (so you can make caves and the like work).
public int get groundHeightAtX(int x, int startY)
{
int[] testArray = new int[4];
for (int y = startY; y < ground.getData().getHeight(); y++)
{
int[] pixels = ground.getData().getPixel(x,y,testArray);
if (pixels[0] == groundColor[0] && pixels[1] == groundColor[1] && pixels[2] == groundColor[2] && pixels[3] == groundColor[3])
{
return y;
}
}
//If there's no floor found, this is considered a bottomless pit.
return Integer.MAX_VALUE;
}
If you do that, it would be smart to cache the values for every X (in another array, probably) so that you’re not calling this constantly for every single entity.
2 - Create some sort of geometry that represents the ground, probably a bunch of points - you’d find which points that you lie between and then use the slope of the line to decide the height at that particular point. Faster but requires more effort.