# Algorithm for continuously generating a tile map for a topdown 2D game? [duplicate]

In essence, what I'm looking for is a procedural 2D tilemap continuously generated in a fashion like Minecraft - which is to say generated as the player approaches the edges of the already explored parts of the map. Map is going to be for a topdown 2D-shooter and the purpose of the map is mostly just for background and determining types of enemies and loot to spawn, so it really doesn't need to be very complex.

I've already researched some into the topic, but most of the answers have honestly been a bit too complicated or seemingly made for pregenerated maps. Voronoi Diagrams and Simplex Noise, while impressive, I don't really understand how to implement in a continuous fashion in realtime. Or at all, really.

What I'm imagining with the generator would be to create simple biomes, composed of two values determining its 'artificiality' (i.e. how man-made the biome is) and 'life' (which is how populated it is). An example would be a city, with high values of life and artificiality both. The values for each would be skewed towards that of its neighbour to ensure that you don't have completely random values. It'd probably be a good idea to ensure that a 'biome' doesn't get too large too, by limiting the amount of tiles?

My question is, are there any better or simpler algorithms to use for something like this beyond Voronoi and Simplex? The game is programmed in C#, I feel I should mention.

## marked as duplicate by MichaelHouse♦Dec 3 '13 at 15:49

• Also: gamedev.stackexchange.com/questions/18735/… and gamedev.stackexchange.com/questions/4628/… and gamedev.stackexchange.com/questions/756/…. See here for even more resources: pcg.wikidot.com – MichaelHouse Dec 3 '13 at 15:51
• @Byte56 The main difference I felt is that most of those seem to me to be focused on runtime generation and not continuous generation, or at least don't mention that they are, which is what I was looking for. I looked at all of those questions and felt a lot of the answers were too complex for my understanding. My main question here is if there was something more simple, since I -think- my needs are pretty simple. I also tried to be as specific as possible, since a lot of those questions have been considered too vague as well. But you're right, it's still kinda similar. – RoundhouseKitty Dec 4 '13 at 11:32
• Yep, since the answer you've selected is "learn how it works or copy how it works", I think it's a duplicate. Sometimes we just need that kick telling us it's not so bad and we should just learn it already. Good luck with your game! – MichaelHouse Dec 4 '13 at 14:07

Maybe Midpoint Displacement might work for you? The algorithm is a bit simpler than simplex, but you might have to tune it a bit to get rid of artifacts in the result.

The linked article does the full explanation better than I could, but the general idea behind it is this:

1. Assign random values to the four corners
2. In the middle between those, average the neighbor values and add/substract some "error" for randomness
3. Repeat for new midpoints until the map is filled.

This should give you a good map of random values, and with some tinkering you should be able to connect several chunks of it by using the values of one edge to start the next chunk and so on. If you need to, you could create two maps, one for "life" values and one for "artificiality" values and combine them.

• That seems super neat, I'll give that one a lookover too! – RoundhouseKitty Dec 4 '13 at 11:33
• Was just going to post the exact same link before noticing this answer. +1 – Arahman Dec 4 '13 at 18:06
• I've looked into this, and actually found out that it was super simple to understand. I'll switch this to the answer, as it managed to answer my question. I'm not sure if it's super for continuous generation, but I'll work something out. – RoundhouseKitty Dec 10 '13 at 13:53
• Continuous generation may indeed be tricky. My idea would be: after the first chunk is generated, take the edge of it and use it as values for the edge of the next chunk. On the opposite edge of the new chunk, the starting values could be tweaked to have a certain maximum deviation from the already existing edge so that one chunk is not too different from its neighbour, repeat for neighbours in other directions. Once you have all starting values, generate as normal except vor the edge values already determined by neighbours. That's from the top of my head, not sure if that's practical. – Christian Dec 10 '13 at 14:04
• Basing it on chunks is a pretty good idea, actually, at least in theory. – RoundhouseKitty Dec 10 '13 at 14:08

Simplex noise is pretty much the standard in this scenario. If it seems too complex for you, you have two options:

1. Find the time and put some effort into understanding it,

2. Look for an existing implementation and adjust it to your needs.

I would really suggest the first one, but I can understand that it seems overwhelmingly difficult at first glance.

So let's talk about option 2. There's a project on code.google.com: simplexnoise project The noise generation itself is in the Noise.cs file. Indeed, it looks complex. There's a test application also (see Form1.cs), which shows you how to use the Noise class to generate an output in real-time.

Since there is no existing solution for your exact needs (biomes, cities etc.), you should play with this test application, poking it, to see what happens if you change certain constants. I'd suggest even creating multiple layers of noise, applying them over each other, adding filters and so on. This way you could simulate environmental variables that are independent from each other (for example, terrain elevation vs. population density).

I know from my own example that learning while 'playing' is very effective. You will eventually learn how this whole noise thing works, and you will get a clearer idea of how to implement it in your own game.

• Thanks for the answer! It's appreciated. I'll go check out the project and see if I can toy around with it a bit. – RoundhouseKitty Dec 3 '13 at 12:24