Advertisement
tyridge77

Untitled

Jul 6th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. local areaSize = 128 --128
  2. local brickSize = 4 --4
  3. local noiseScale = 32 --32
  4. local noiseMagnitude = 50 --50
  5. local aboutHeight = 0.65 --0.65
  6. local playerGenRadius = 64 --64
  7.  
  8. --the level indicates the bottom of the region
  9. local snowLevel = 128
  10. local snowBottom = 40 --snow is generated differently
  11. local rockLevel = 64
  12. local grassLevel = 12
  13. local beachLevel = 8
  14. local waterLevel = 7
  15.  
  16. local topSeedX = math.random() --screw DRY
  17. local topSeedY = math.random()
  18. local midSeedX = math.random()
  19. local midSeedY = math.random()
  20. local lowSeedX = math.random()
  21. local lowSeedY = math.random()
  22. local biomeSeedX = math.random()
  23. local biomeSeedY = math.random()
  24.  
  25. --local g = Instance.new("Model", game.Workspace)
  26.  
  27. function genTerrainBlock(i, j)
  28. --[[
  29. local b = Instance.new("Part", g)
  30. b.Size = Vector3.new(brickSize,height,brickSize)
  31. b.Position = Vector3.new(i*brickSize,height/2,j*brickSize)
  32. b.Anchored = true
  33. local brickColor = BrickColor.new("Deep blue") --fill everything unchanged with water
  34. ]]--
  35. local noiseLayers = {(math.noise(i/noiseScale+topSeedX, j/noiseScale+topSeedY)+0.5)*noiseMagnitude,
  36. (math.noise(i/(noiseScale/2)+midSeedX, j/(noiseScale/2)+midSeedY)+0.5)*noiseMagnitude*0.7,
  37. (math.noise(i/(noiseScale/5)+lowSeedX, j/(noiseScale/5)+lowSeedY)+0.5)*noiseMagnitude*0.4
  38. }
  39. local height = 0.0
  40. for k,v in pairs(noiseLayers) do
  41. height = height + v
  42. end
  43. if height < 1 then
  44. height = 2
  45. end
  46. height = math.ceil(math.pow(height, (math.noise(i/(noiseScale*4)+biomeSeedX, j/(noiseScale*4)+biomeSeedY)+aboutHeight)))
  47. --print(tostring(height))
  48. if height < 7 then
  49. height = 6
  50. end
  51. local terrainColor = Enum.Material.Water
  52. if height >= beachLevel and height < grassLevel then
  53. --brickColor = BrickColor.new("Pastel yellow")
  54. terrainColor = Enum.Material.Sand
  55. elseif height >= grassLevel and height < rockLevel then
  56. --brickColor = BrickColor.new("Camo")
  57. if math.noise(i/noiseScale+biomeSeedX, j/noiseScale+biomeSeedY) > 0 then
  58. terrainColor = Enum.Material.Grass
  59. else
  60. terrainColor = Enum.Material.Ground
  61. end
  62. elseif height >= rockLevel and height < snowLevel then
  63. --brickColor = BrickColor.new("Dark stone grey")
  64. terrainColor = 896 --Enum.Material.Rock isn't a thing apparently
  65. elseif height >= snowLevel then
  66. --brickColor = BrickColor.new("Institutional white")
  67. terrainColor = Enum.Material.Snow
  68. end
  69. --add snow
  70. if height >= snowBottom then
  71. if math.random() < (height-snowBottom)/(snowLevel-snowBottom) then
  72. terrainColor = Enum.Material.Snow
  73. end
  74. end
  75. game.Workspace.Terrain:FillRegion(Region3.new(Vector3.new(i*brickSize,-1300,j*brickSize),
  76. Vector3.new(i*brickSize+brickSize,height,j*brickSize+brickSize)):ExpandToGrid(4),
  77. 4, terrainColor)
  78. --b.BrickColor = brickColor
  79. --game.Workspace.Terrain:FillBlock(b.CFrame, b.Size, terrainColor)
  80. --b:Remove()
  81. end
  82.  
  83. for i=-areaSize,areaSize do
  84. for j=-areaSize,areaSize do
  85. genTerrainBlock(i,j)
  86. end
  87. end
  88.  
  89. --[[
  90. game.Players.PlayerAdded:connect(function(player)
  91. player.CharacterAdded:connect(function(character)
  92. while player ~= nil do
  93. local cPos = character.Head.Position
  94. for i=cPos.X-playerGenRadius,cPos.X+playerGenRadius do
  95. for j=cPos.Z-playerGenRadius,cPos.Z+playerGenRadius do
  96. local material, occupancy = game.Workspace.Terrain:ReadVoxels(
  97. Region3.new(
  98. Vector3.new(i, 0, j),
  99. Vector3.new(i+0.1, 0.1, j+0.1) --epsilon
  100. ):ExpandToGrid(4), 4)
  101. if material[1][1][1] == Enum.Material.Air then
  102. genTerrainBlock(i/brickSize,j/brickSize)
  103. end
  104. end
  105. end
  106. wait()
  107. end
  108. end)
  109. end)
  110. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement