-1
\$\begingroup\$

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.

\$\endgroup\$

closed as too broad by Kromster, MrCranky, Nate, Anko, Almo Aug 22 '16 at 15:56

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ top down 2d or side scrolling 2d? \$\endgroup\$ – Ave Aug 12 '16 at 0:57
  • \$\begingroup\$ Not sure what that means. Basically if a player diggs into the ground he the camera goes down with him. Its a lot like the game growtopia. Or blockheads \$\endgroup\$ – abc1234 Aug 12 '16 at 0:59
  • \$\begingroup\$ top down, side scrolling \$\endgroup\$ – Ave Aug 12 '16 at 1:01
  • \$\begingroup\$ Side Scrolling. \$\endgroup\$ – abc1234 Aug 12 '16 at 1:04
  • \$\begingroup\$ An MMO more complex than minecraft in Pygame may be a bit of an overscope. \$\endgroup\$ – Evorlor Aug 12 '16 at 13:05
3
\$\begingroup\$

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
  • Forest
  • Town
  • Beach
  • Lake
  • Ocean

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!

\$\endgroup\$
  • \$\begingroup\$ You're welcome I hope that helps. Good luck with your game. :) \$\endgroup\$ – Grady Aug 12 '16 at 2:02
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ What is RNG.... \$\endgroup\$ – abc1234 Aug 13 '16 at 18:08
  • \$\begingroup\$ @abc1234 RNG -> Random number generator. What you are using to get the randomness for the blocks \$\endgroup\$ – Destructible Lemon Aug 13 '16 at 23:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.