Advertisement
CCCoder

World generation code

Dec 1st, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.54 KB | None | 0 0
  1. for x = 0, editor.worldSize do
  2.         local s = x / editor.worldSize -- range from 0 to 1
  3.         linex[ #linex + 1 ] = x * editor.tdefsize
  4.         liney[ #liney + 1 ] = love.math.noise( 10 * s + 20, seed) * 1250
  5.         liney[ #liney ] = roundTo( liney[ #liney ], editor.tdefsize )
  6.         local biomeNum = round( biomey[ x ], 3 )
  7.         if biomeNum > 0 and biomeNum < 5 then -- PLAINS GENERATION
  8.             if liney[ #liney ] < 300 then
  9.                 spawnBlock( linex[ #linex ], liney[ #liney ], blocks.snowGrass, chunk )
  10.             else
  11.                 spawnBlock( linex[ #linex ], liney[ #liney ], blocks.grass, chunk )
  12.             end
  13.             if love.math.random( 1, 10 ) == 3 then
  14.                 local ypos
  15.                 for i = 1, love.math.random( 4, 5 ) do
  16.                     spawnBlock( linex[ #linex ], liney[ #liney ] - ( i * editor.tdefsize ), blocks.treeLog, chunk )
  17.                     ypos = liney[ #liney ] - ( i * editor.tdefsize )
  18.                 end
  19.                 for i = 1, 3 do
  20.                     spawnBlock( linex[ #linex ] - editor.tdefsize * 2 + ( i * editor.tdefsize), ypos, blocks.treeLeaves, chunk )
  21.                 end
  22.                 spawnBlock( linex[ #linex ], ypos - editor.tdefsize, blocks.treeLeaves, chunk )
  23.             else
  24.                 local r = love.math.random( 1, 10 )
  25.                 if liney[ #liney ] > 500 then
  26.                     if r == 1 or r == 2 then
  27.                         spawnBlock( linex[ #linex ], liney[ #liney ] - editor.tdefsize, blocks.weeds, chunk )
  28.                     elseif r == 5 then
  29.                         spawnBlock( linex[ #linex ], liney[ #liney ] - editor.tdefsize, blocks.rose, chunk )
  30.                     end
  31.                 end
  32.             end
  33.         elseif biomeNum >= 5 and biomeNum < 8 then --DESERT GENERATION
  34.             spawnBlock( linex[ #linex ], liney[ #liney ], blocks.sand, chunk )
  35.             if love.math.random( 1, 16 ) == 3 then
  36.                 for i = 1, love.math.random( 2, 3 ) do
  37.                     spawnBlock( linex[ #linex ], liney[ #liney ] - ( i * editor.tdefsize ), blocks.treeCactus, chunk )
  38.                 end
  39.             end
  40.         elseif biomeNum >= 8 and biomeNum < 10 then --SWAMP GENERATION
  41.             if liney[ #liney ] < 300 then
  42.                 spawnBlock( linex[ #linex ], liney[ #liney ], blocks.snowGrass, chunk )
  43.             else
  44.                 spawnBlock( linex[ #linex ], liney[ #liney ], blocks.swampGrass, chunk )
  45.             end
  46.             if love.math.random( 1, 10 ) == 3 then
  47.                 local ypos
  48.                 for i = 1, love.math.random( 3, 4 ) do
  49.                     spawnBlock( linex[ #linex ], liney[ #liney ] - ( i * editor.tdefsize ), blocks.treeLog, chunk )
  50.                     ypos = liney[ #liney ] - ( i * editor.tdefsize )
  51.                 end
  52.                 for i = 1, 5 do
  53.                     spawnBlock( linex[ #linex ] - editor.tdefsize * 3 + ( i * editor.tdefsize), ypos, blocks.treeLeaves, chunk )
  54.                 end
  55.                 for i = 1, 3 do
  56.                     spawnBlock( linex[ #linex ] - editor.tdefsize * 2 + ( i * editor.tdefsize), ypos - editor.tdefsize, blocks.treeLeaves, chunk )
  57.                 end
  58.                 spawnBlock( linex[ #linex ], ypos - editor.tdefsize, blocks.treeLeaves, chunk )
  59.             end
  60.         end
  61.         local toBottom = 3000 - liney[ #liney ]
  62.         local toBottom = toBottom / editor.tdefsize
  63.         for i = 1, toBottom do
  64.             local block
  65.             if biomeNum > 0 and biomeNum < 5 then
  66.                 local depth = love.math.random( 5, 9 )
  67.                 if i < depth then
  68.                     spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), blocks.dirt, chunk )
  69.                 elseif i >= depth then
  70.                     local block = generateOre( i + depth )
  71.                     if block == "none" then
  72.                         spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), blocks.stone, chunk )
  73.                     else
  74.                         spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), block, chunk )
  75.                         print( "Generated ore " .. block.name )
  76.                     end
  77.                 end
  78.             elseif biomeNum >= 5 and biomeNum < 8 then
  79.                 local depth = love.math.random( 7, 8 )
  80.                 if i < depth then
  81.                     spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), blocks.sand, chunk )
  82.                 elseif i >= depth and i < round( depth + depth / 2 ) then
  83.                     spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), blocks.sandstone, chunk )
  84.                 else
  85.                     spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), blocks.stone, chunk )
  86.                 end
  87.             elseif biomeNum >= 8 and biomeNum < 10 then
  88.                 local depth = love.math.random( 5, 9 )
  89.                 if i < depth then
  90.                     spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), blocks.dirt, chunk )
  91.                 elseif i >= depth then
  92.                     spawnBlock( linex[ #linex ], liney[ #liney ] + ( i * editor.tdefsize ), blocks.stone, chunk )
  93.                 end
  94.             end
  95.         end
  96.         chunkCount = chunkCount + 1
  97.         if chunkCount > editor.chunkSize then
  98.             chunk = chunk + 1
  99.             chunkCount = 0
  100.             if chunks[ chunk ] == nil then
  101.                 chunks[ chunk ] = { x = linex[ #linex ], tiles = { } }
  102.             end
  103.         end
  104.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement