5
\$\begingroup\$

This is my first foray into game programming. I am using Monogame (XNA replacement).

I have begun playing around with a 2d map generator (Think Terraria) and have started off with generating the initial map using the Voronoi method. This is working successfully so far as a prototype. I'm currently just outputting the map as an array of ASCII characters to represent a material or biome type. Example: % = Granite, @ = Dirt etc.

I now want to be able to randomly create 'seams' of different material in this map, given a start and endpoint (x,y), magnitude, and a varying thickness of the material and to make the line of material change direction to a certain degree, especially if it is quite long.

Example map. What I am trying to achieve is represented by the letter 'G', 'S' and 'E' are start and endpoints (You may have to scroll the code view to the right)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%GGEG%%%%%%%%%%%
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxooo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%GGG%%%%%%%%%%%%%
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoooo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%GGGGG%%%%%%%%%%%%%%
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxooooo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%GGGG%%%%%%%%%%%%%
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxooooo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%GGG%%%%%%%%%%%%%%%%
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoooooo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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ooooooooo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Setting the start and endpoints is easy enough but doing the rest eludes me. I've had disappointing results when writing code that simply decrements the y value by one, and then randomly decreasing/increasing x by 1 (With bias on a direction based on if the end position is left or right of start point) and changing the material at that point.

The above method I am using also doesn't work if the start and end are horizontal.

The aim is to pre-generate as much of the map as possible using a large 2-dimensional array which will then be used for placing the correct block material. The array will only be used at the start of the game world.

P.S. If anyone also has advice regarding the way I am going about generating a starting map please feel free to let me know if I'm to avoid generating the map as an array of ASCII chars :-)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ There was another question about generating mineral veins a while back that you may find interesting. \$\endgroup\$
    – DMGregory
    May 9, 2019 at 11:03
  • \$\begingroup\$ You should specify a bit more what characteristics your seams shall have? Maybe give more examples. I think your approach with some kind of biased random walk doesn't sound too bad. \$\endgroup\$
    – Trilarion
    May 9, 2019 at 11:21

1 Answer 1

0
\$\begingroup\$

I think looking up the math and algorithms behind “random walks” would solve your problem. You basically select a range of angles and a range of step lengths, and the probability to change direction. Each iteration it walks forward by the step length and then decides whether it changes direction.

https://en.wikipedia.org/wiki/L%C3%A9vy_flight

For your use case, you’ll need to add a width to this so it can affect surrounding tiles. You’ll also need some way to deal with map edges.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .