- Home /
How to generate Blocks like Terraria (2D)
Hey guys, I'm making a Terraria + Castlevania SotN mix, got Characterstats, Inventory, etc. done.
When reaching the point where I have to create the world the player will be wandering, I just made a quick and dirty solution. I took the PerlinNoise, put in a 128x128 Texture to show me the output (this grey noise). Checked the output values, saw there is always something bewtween 0.0f and 0.6f (with my current settings).
I created 9 Blocks for testing, and placed the blocks depending on the Noisevalue..
0.0f - 0.1f dirt 0.1f - 0.2f stone
etc...
My problem is, I don't know how to modify the noise correctly to create biomes with it. I found barely anything that could help me on my topic, so I hope you could give me at least a nice hint.

Have a nice day
Answer by sparkzbarca · Dec 27, 2013 at 01:50 PM
i don't claim to know how its normally done but the way i'd do it.
Define each bio as a class
have in it a list of blocks which that bio can choose from to spawn
assign each block a random chance of being selected
so for example
DesertBio
{
list<blocks> BlocksSpawnable;
BlocksSpawnable.add(DesertTile);
BlocksSpawnable.add(WaterTile); //small chance of an oasis
BlocksSpawnable[1].getComponent<BlockScript>().SpawnChance = 80;
BlocksSpawnable[0].getComponent<BlockScript>().SpawnChance = 20;
//create bio returns a 2 dimensional list of blocks to spawn
blocks[,] CreateBio(int Length, int Width)
{
blocks[,] BlocksToSpawn = new blocks[Length, Width];
// at this point you can start specializing
//for example if height is != 0 (not at ground level) remove snowy ground cover blocks from
//possible spawn list and redistribute there spawn chance.
//check all neighboring blocks and if a water block exists chance to spawn water goes to 75%
//so for example
for(int X = currentX - 1 ;X <= currentX + 1; X++
{
for (int Y = currentY - 1; X <= currentY + 1; Y++
{
if(Blocks[X,Y].tag == "water")
//Modify spawn chance
}
}
//now that you've done all the modifications you just generate a number and compare to figure out which block to spawn.
}
Hope this helps, post if you need more help
I'm gonna try this and tell you how it worked, but it looks pretty good for now
well you also need to implement a method to randomly create biomes in the same way by randomly designating chunks of the world as biomes and then using special rules to deter$$anonymous$$e the next biome so that you can have randomly sized biomes and make sure there isnt a desert next to a snowland.
Hey, thanks a lot for the help, but I came upon this [[Tutorial] Procedural meshes and voxel.] [1]
And it looks pretty easy actually.
[1]: http://forum.unity3d.com/threads/198651-Tutorial-Procedural-meshes-and-voxel-terrain-C
Answer by alteveer · Mar 02, 2014 at 12:25 AM
This guy is a genius:
http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/
The code is in AS3, so easy to port to JS, I am using this to make island shapes and it works very well. The key is to hook the threshold, etc variables up to public variables so you can tweak them while the game is running.
Answer by GrKl · Dec 19, 2016 at 07:30 AM
When doing something similar in 3D, I used different Perlin Noise calls with different parameters to set some basic values:
Call one gave me the height of the terrain Call two gave me the humidity of the terrain Call three gave the temperature.
Earth biomes actually work basically on these 3 data.
You can now set biomes depending on the above results. Google Image search "biome graph". This should help with the idea.
You than specify how each biome should behave
Your answer