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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| 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; } } 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.