How can I generate water in a procedural 2D sideview landscape?
Here's what I currently have:
- First generate the heightmap of the land
- Then generate the water, based on the land
Here's how I generate the water based on the land:
Assign each block a lake target for water (rain) flow.
- First, choose the best direction.
- Then, for each block it checks along the way, calculate the slope between that block and the next block. If that slope is zero, keep on going to create a noninteger slope, until a
MAX_BLOCK_DELTA_Xis reached. If this accurate slope is close to zero, we say the water drains or evaporates. Otherwise, keeping searching for the bottom of a lake, until the slope goes up again.
Next, lakes are created, based on the most targets chosen in one proximity.
- Lastly, the lake height is calculated from the lake's amount of water (I don't know how to do this).
I see some problems with my current algorithm, like if the bottom of a lake is flat the water drains. Could this be improved? If so, how? Either way, how would I calculate the lake's height? How would I do rivers?
Edit: Caves and overhangs are not allowed.
Edit 2: This answer of my other question provides a way to identify valleys. I think this could be used, but I don't know which end to start scanning.