C# generating lake-like shapes in a 2d top-down tile grid

245 views Asked by At

I'm a beginner in game development and want to create a top-down game using tilemaps. I'm using Godot as my game engine but a general C# solution is fine.

I'm looking to generate lakes in the tilemap but I can't come up with any ideas that might work due to my inexperience. Previously I tried using Simplex, but I decided against it due to the lack of control over where the lakes spawn.

Performance is somewhat important but the world will be finite and not procedural, similar to Terraria.

I'm open to any ideas on the matter that would be reasonable within a videogame.

1

There are 1 answers

1
Akade On BEST ANSWER

So for a finite world size, I can sketch an approach for you that you can try out. It is not language specific but you should be able to do that (easily) with C#:

  • The tiled world is represented as a bitmap: 0=land, 1=water
  • To generate a lake, mark the starting tile as water and add its coordinates to a queue
  • Deque a point from the queue. For that tile and for each direction, randomly decide if that adjacent tile is also water. Add newly added tiles to the queue.
    • Control the lake shape by different probabilities for different directions
    • Control the size of the lake by either limiting the iteration count or by decreasing the chance of a new water tile by the distance from the starting point
  • Repeat until the queue is empty.

Let me know how this workes out - I have only tested it using my mental code simulator so mileage may vary;) If you need help in implementing that approach, don't hesitate to ask.