4
\$\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 a different material in this map, given a start and end point (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 end points (You may have to scroll the code view to the right)

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

Setting the start and end points 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 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 doesnt 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 the 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 Im to avoid generating the map as an array of ASCII chars :-)

\$\endgroup\$
  • 1
    \$\begingroup\$ There was another question about generating mineral veins a while back that you may find interesting. \$\endgroup\$ – DMGregory May 9 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 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.