I am developing a MMO, and i'll describe it as a 2d mine craft (it's a lot more complicated than that). There will be a multitude of blocks that will be in a world. I need them to be randomly placed. Im not quite sure how to do this, such as should I make a tile map with the items and place a random item in the tilemap when the world is loaded??? I am using python with pygame. Any answers will be appreciated.
I couldn't tell from your question if your world is top down or side on. But I'm going to assume top down for my answer.
If you just want the blocks to be totally random, all you'd need to is go through each block in your 2D world, which is basically an image, and place a random block value. That would be "random", but it wouldn't look very nice.
I would recommend investigating procedural generation of environments, concepts such as biomes, noise functions, etc.
Ideally you'd define a set of Biomes like:
- Grass Field
Each Biome would contain it's own rules for how to generate blocks for that type of Biome. Such as forest might contain a rule for frequently generating tree blocks. Beach could use 90% sand blocks and 10% shells/rocks/beachball blocks.
And then your procedural generation function would be somewhat like this: Biome pickBiome(int seed, int x, int y)
At each point on your map you could call that function, which would use noise functions and other calculations to pick a biome. This function would return a consistent result every time it's called if called with the same seed and at the same coordinate. Different worlds would be generated by using different seed values, not just a rand() function.
The function would also have to smoothly transition from one biome to another, so perhaps the function could return several biomes and a weight function to blend between biomes while generating the world.
I also recommend looking up how Minecraft itself generates terrain as it works on a similar basis to everything I just described.
Hopefully that gives you some ideas! Good luck!
To add on to Grady's answer. You also have some templates for creating dungeons. Obviously it will be a pain in the arse to find a RNG algorithm that will set up a very complex dungeon from scratch. So this is where a lot of games tend to cheat.
When you play a game that features fully featured RNG like minecraft, terraria, or Starbound, you will start to notice that there are some elements that are similar enough in appearance if you paid attention. If you were to take a snap shot of those pieces, and carry them with you and compare them to the next location. You will see that more complex structures are really just prefabs of rooms with rules set to how they should link up.
To get a mental picture of this... if you were to go out to the store, and buy a D&D tileset, you would notice that they are prefabricate slots of land. The dungeon master can put these together in any manner of way to achieve some insane number of dungeon set ups. The only rule is that there needs to be some form of consistency. Like a river under no circumstance should just end randomly as you transition from one prefab to the next without an outflow. So either you tell the RNG algorithm to link a prefab that safely continues that detail, OR you provide a way to just cut it off in a pleasing way.