Game Development Community

Randomly Generated Maps

by Josh Steffen · in Torque Game Builder · 08/11/2011 (9:41 pm) · 1 replies

Is it possible to use the get random command to spawn around say 2000 to 10000 dirt blocks then 1000 to 5000 stone blocks then use the get position command to then randomly place the blocks from around say Y 100 to -100 and X 100 to -100 to make a basic landscape with some caves, hills, and mountains with out placing the blocks on each other and say for the first 30 units down it's mostly dirt block then after that mostly stone because I plan to make a 2d mining game like terraria and minecraft games.

#1
08/12/2011 (12:14 pm)
Yeah it is possible and shouldn't be very hard.

I would treat your game as one giant x,y grid with each cell the size of your blocks. Then instead of creating your blocks and then moving them into place just determine which block will go into which cell and then just create them with position (x*cell size, y*cell size) and they should be in the correct spot.

As for your first 30 layers of mostly dirt and then the rest mostly stone that will be written into your code that determines which block is placed.

Say your top left corner is 0,0 and you want the first 30 layers (0 to -30 y) to be stone 90% of the time and stone 10% of the time you could use

%random_number = getRandom(1,100)
if(%random_number >= 90)
{
makeDirt(x,y);
}
else
{
makeStone(x,y);
}