# Drawing a river

This topic is 4142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Greetings everyone. I'm working on a webbased strategy game and I'm a little stuck at something. Let me start with sharing the url: http://projectx.daedeloth.be/ (Invitation code: 688feba2b5bfcbd) Like you see, I use an isometric map. The trees are drawn "random", which was quite easy. I decided not to store the map, I always recalculate it again. This is the source of the drawing class: http://rafb.net/p/E9gmNL69.html Like you see, I calculate random numbers based on the x and y value of the square and then decide if I should draw a bush, a tree or a special resource. Now I'd like to add rivers, but rivers are harder to do than trees: rivers have to be connected. I've been thinking about this for a few weeks now, without finding a solution. The problem is ofcourse that the function only has the x and y value of the element... Many thanks for your help, Thijs Van der Schaeghe.

##### Share on other sites
One way or another you need to know what it is connected to.

Usually there are a set of images for the tiles, and the correct one is selected depending upon the adjacent tiles. Also works this way for roads.

( An example tileset: rivers are at bottom
http://www.msg.com.mx/~arturo/Projects/Freeciv-Worms/img/tileset.png )

##### Share on other sites
Yes, that is the usual way of drawing a river or road.
Calculating the adjacent tiles also is easy, just call the same function with the adjacent spaces, so determining the tile won't be any problem.

I only need some sort of algorithm to determine if that place should be "river" or "land", in a random looking way, without losing the whole "river" idea (meaning that I don't have a thousand pools instead of a few rivers).

*edit: So just for example:
if (\$x % 10 == 0) { return new Map_Water (); }

This would draw a river every 10 tiles.

However, this doesn't look random at all :)

##### Share on other sites
Right. So you're going to have to refactor your program to give you the adjacency information or some other information more than what you have at present in order to accomplish this goal.

-me

##### Share on other sites
Rivers are connected to something. So, have a network of lines across the map, and any squares that these lines touch are river squares. The tiles next to them but not covered by a line are beach squares. The same for roads.

##### Share on other sites
Yep, I understand how this generally works.
But I'm not in a "general situation" here.

Oh well, I'll dig into it later.
For now I'll just limit my engine to random trees :)

Thanks anyway.

##### Share on other sites
Rivers work by collecting water from high places. Here's what I'd do:

1. Generate a height map for your world.
2. Give every tile in your world a uniform amount of water ("rain")
3. Iterate over your world, moving water to an adjacent tile that is downhill.
3a. Record the amount of water that enters every square. Above some threshold, these squares are going to be river squares or lake squares.
3b. Continue until all the water has pooled into lakes/oceans or run off the edge of the map, depending on what you want to have happen.
3c. Whenever you have water leave a square, lower the height of that square slightly. This will create basins and increase river cohesion to give better looking results.

This should give some very nice results, creating river basins.

Alternatively, if you want something easier, you can just pick any two random points on your map and draw a line between them. Then, using midpoint displacement, give that line a little wobble. You can either set one of the end points to a body of water, or just build a lake at one of the end points. If you wanted to make tributaries, you can just take a point on the primary river as the end point for another river. You'll probably want to point the tributaries so that they seem to come from "upstream", converging to a larger river. Or you could do the reverse and build something like the Nile basin. All depends on your point of view.

##### Share on other sites
try using a different method to create your landscape. Rather than incrementing through each square and giving it a random tile, why not add features in a random way. For example, adding a river using one of the ideas above, or adding a forest. to add a forest, I would pick a center point, a density, and and put dense trees in the middle and less dense trees at the outside. As you go further away from the center point, the trees can be smaller. You can do the same with mines, by adding a large supply of rock, with smaller supplies around it.

##### Share on other sites
True, but take in mind:

1. I don't want to store my map
2. I don't have a "memory" to load a random map.

This is php I'm talking about.

And storing every single tile in a database doesn't sound very good to me.

##### Share on other sites
once the map has been drawn it will take the same memory as it does now. You don't have to store the tiles after they have been created.

1. 1
2. 2
3. 3
Rutin
14
4. 4
frob
12
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633670
• Total Posts
3013262
×