User:HoubkneghteS/tg

--# Main -- This was made by Adam9812. It is public domain.

-- Terrain Generator 3.0

function setup displayMode(NORMAL) backingMode(RETAINED) parameter.integer("hilliness",0,140) parameter.boolean("amplifiedTerrain") parameter.color("grasslandFill",55,138,24) parameter.color("desertFill",226,213,111) parameter.color("mesaFill1",248,90,39) parameter.color("mesaFill2",250,140,60) parameter.color("swampFill",58,77,51) parameter.color("coldFill",240,240,240) parameter.boolean("underlayTrue") parameter.boolean("overlayTrue") parameter.number("wetAverage",0,25) parameter.number("tempAverage",-5,25) parameter.action("Regenerate Terrain",generate) parameter.action("Reload Terrain",Tload) parameter.boolean("biomes") parameter.action("Save Preferences",save) parameter.action("Load Preferences",load) load generate parameter.boolean("guiTrue",true, Tload) parameter.action("Help",help) parameter.action("Display World Code",sourse)

end

function terrain if underlayTrue == false or biomes == false then background(1, 117, 251, 255) end fill(grasslandFill) if biomes == true then if wet1 < 5 then fill(desertFill) end if wet1 > 18 then fill(swampFill) end if wet1 < 0 then if mesaColor1 == 1 then fill(mesaFill1) elseif mesaColor1 == 2 then fill(mesaFill2) else fill(desertFill) end end if temp1 5 then fill(coldFill) end end rect(-1,-1,43,h1) rect(40,-1,42,h2) rect(80,-1,42,h3) if biomes == true then if wet1 < 0 then if mesaColor2 == 1 then fill(mesaFill1) elseif mesaColor2 == 2 then fill(mesaFill1) else fill(desertFill) end end end rect(120,-1,42,h4) rect(160,-1,42,h5) fill(grasslandFill) if biomes == true then if wet2 < 5 then fill(desertFill) end if wet2 < 0 then if mesaColor3 == 1 then fill(mesaFill1) elseif mesaColor3 == 2 then fill(mesaFill2) else fill(desertFill) end end if wet2 > 18 then fill(swampFill) end if temp2 5 then fill(coldFill) end end rect(200,-1,42,h6) rect(240,-1,42,h7) if wet2 < 0 and biomes == true then if mesaColor4 == 1 then fill(mesaFill1) elseif mesaColor4 == 2 then fill(mesaFill2) else fill(desertFill) end end rect(280,-1,42,h8) rect(320,-1,42,h9) rect(360,-1,42,h10) fill(grasslandFill) if biomes == true then if wet3 < 5 then fill(desertFill) end if wet3 < 0 then if mesaColor5 == 1 then fill(mesaFill1) end if mesaColor5 == 2 then fill(mesaFill2) end if mesaColor5 == 3 then fill(desertFill) end end if wet3 > 18 then fill(swampFill) end if temp3 < 0 and wet3 < 5 then fill(coldFill) end end rect(400,-1,42,h11) rect(440,-1,42,h12) rect(480,-1,42,h13) rect(520,-1,42,h14) fill(grasslandFill) if biomes == true then if wet4 < 0 then if mesaColor6 == 1 then fill(mesaFill1) end if mesaColor6 == 2 then fill(mesaFill2) end if mesaColor6 == 3 then fill(desertFill) end end if wet4 > 18 then fill(swampFill) end if temp4 5 then fill(coldFill) end if wet4 < 5 then fill(desertFill) end end rect(560,-1,42,h15) if wet4 < 0 and biomes == true then if mesaColor7 == 1 then fill(mesaFill1) end if mesaColor7 == 2 then fill(mesaFill2) end if mesaColor7 == 3 then fill(desertFill) end end rect(600,-1,42,h16) rect(640,-1,42,h17) rect(680,-1,42,h18) rect(720,-1,42,h19) end

function save saveLocalData("hilliness",hilliness) saveLocalData("underlayTrue",underlayTrue) saveLocalData("overlayTrue",overlayTrue) saveLocalData("biomes",biomes) saveLocalData("wetAverage",wetAverage) saveLocalData("tempAverage",tempAverage) print("Preference Saving succesful!") end

function load hilliness = readLocalData("hilliness",20) underlayTrue = readLocalData("underlayTrue",true) overlayTrue = readLocalData("overlayTrue",true) wetAverage = readLocalData("wetAverage",8) tempAverage = readLocalData("tempAverage",8) biomes = readLocalData("biomes",true) print("Preference Loading succesful!") end

function help print("Hilliness: How hilly the terrain will be.") print("Biome Fills: What color the terrain will be if it is that biome.") print("Underlay True: Whether underlays (trees, cactuses, etc.) generate.") print("Overlay True: Whether overlays (swamps, rocks, etc.) generate.") print("Regnerate Terrain: Generates a completely new set of Terrain. All types of values will be recreated.") print("Reload Terrain: Reloads terrain with all the height, biome, underlay and overlay values, but different minor details.") print("Biomes: Whether biomes exist.") print("GUITrue: Whether the bottom bar appears.") end

function sourse print("H1: "..h1) print("H2: "..h2) print("H3: "..h3) print("H4: "..h4) print("H5: "..h5) print("H6: "..h6) print("H7: "..h7) print("H8: "..h8) print("H9: "..h9) print("H10: "..h10) print("H11: "..h11) print("H12: "..h12) print("H13: "..h13) print("H14: "..h14) print("H15: "..h15) print("H16: "..h16) print("H17: "..h17) print("H18: "..h18) print("H19: "..h19) if biomes == true then print("Wet1: "..wet1) print("Wet2: "..wet2) print("Wet3: "..wet3) print("Wet4: "..wet4) print("Temp1: "..temp1) print("Temp2: "..temp2) print("Temp3: "..temp3) print("Temp4: "..temp4) end end

function draw if guiTrue == true then GUI end end --# Generation function generate if amplifiedTerrain == false then h1 = math.random(2,600) h2 = h1 + math.random(-hilliness,hilliness) h3 = h2 + math.random(-hilliness,hilliness) h4 = h3 + math.random(-hilliness,hilliness) h5 = h4 + math.random(-hilliness,hilliness) h6 = h5 + math.random(-hilliness,hilliness) h7 = h6 + math.random(-hilliness,hilliness) h8 = h7 + math.random(-hilliness,hilliness) h9 = h8 + math.random(-hilliness,hilliness) h10 = h9 + math.random(-hilliness,hilliness) h11 = h10 + math.random(-hilliness,hilliness) h12 = h11 + math.random(-hilliness,hilliness) h13 = h12 + math.random(-hilliness,hilliness) h14 = h13 + math.random(-hilliness,hilliness) h15 = h14 + math.random(-hilliness,hilliness) h16 = h15 + math.random(-hilliness,hilliness) h17 = h16 + math.random(-hilliness,hilliness) h18 = h17 + math.random(-hilliness,hilliness) h19 = h18 + math.random(-hilliness,hilliness) vari = 5 else h1 = math.random(2,1000) h2 = h1 + math.random(-hilliness * 3,hilliness * 3) h3 = h2 + math.random(-hilliness * 3,hilliness * 3) h4 = h3 + math.random(-hilliness * 3,hilliness * 3) h5 = h4 + math.random(-hilliness * 3,hilliness * 3) h6 = h5 + math.random(-hilliness * 3,hilliness * 3) h7 = h6 + math.random(-hilliness * 3,hilliness * 3) h8 = h7 + math.random(-hilliness * 3,hilliness * 3) h9 = h8 + math.random(-hilliness * 3,hilliness * 3) h10 = h9 + math.random(-hilliness * 3,hilliness * 3) h11 = h10 + math.random(-hilliness * 3,hilliness * 3) h12 = h11 + math.random(-hilliness * 3,hilliness * 3) h13 = h12 + math.random(-hilliness * 3,hilliness * 3) h14 = h13 + math.random(-hilliness * 3,hilliness * 3) h15 = h14 + math.random(-hilliness * 3,hilliness * 3) h16 = h15 + math.random(-hilliness * 3,hilliness * 3) h17 = h16 + math.random(-hilliness * 3,hilliness * 3) h18 = h17 + math.random(-hilliness * 3,hilliness * 3) h19 = h18 + math.random(-hilliness * 3,hilliness * 3) vari = 10 end wet1 = wetAverage + math.random(-vari,vari) wet2 = wetAverage + math.random(-vari,vari) wet3 = wetAverage + math.random(-vari,vari) wet4 = wetAverage + math.random(-vari,vari) temp1 = tempAverage + math.random(-vari,vari) temp2 = tempAverage + math.random(-vari,vari) temp3 = tempAverage + math.random(-vari,vari) temp4 = tempAverage + math.random(-vari,vari) cactusChance1 = math.random(1,3) cactusChance2 = math.random(1,3) rockChance1 = math.random(1,3) rockChance2 = math.random(1,3) grassChance1 = math.random(1,2) grassChance2 = math.random(1,2) grassChance3 = math.random(1,2) swampChance1 = math.random(1,2) swampChance2 = math.random(1,2) swampChance3 = math.random(1,2) treeChance1 = math.random(1,3) treeChance2 = math.random(1,3) treeChance3 = math.random(1,3) treeChance4 = math.random(1,3) treeChance5 = math.random(1,3) treeType1 = math.random(1,5) treeType2 = math.random(1,5) treeType3 = math.random(1,5) treeType4 = math.random(1,5) treeType5 = math.random(1,5) mesaColor1 = math.random(1,3) mesaColor2 = math.random(1,3) mesaColor3 = math.random(1,3) mesaColor4 = math.random(1,3) mesaColor5 = math.random(1,3) mesaColor6 = math.random(1,3) mesaColor7 = math.random(1,3) mesaColor8 = math.random(1,3) Tload print("Terrain Generation Succesful!") end

function Tload if biomes == true and underlayTrue == true then underlay end terrain if biomes == true and overlayTrue == true then overlay end end --# GUI function GUI fill(255, 255, 255, 255) rect(-5,-5,WIDTH + 10, 45) fill(0, 0, 0, 255) fontSize(30) font("HelveticaNeue") text("1",15,20) fontSize(19) text("Save", 50, 19) text("Load", 100, 19) if CurrentTouch.state == BEGAN and CurrentTouch.x > 22 and CurrentTouch.x < 60 and CurrentTouch.y < 43 then

World1:save end if CurrentTouch.state == BEGAN and CurrentTouch.x > 60 and CurrentTouch.x < 115 and CurrentTouch.y < 43 then

World1:load end end --# UnderlayOverlay function underlay background(1, 117, 251, 255) if cactusChance1 == 1 and hilliness < 60 and wet1 6 then sprite("Dropbox:Cactus",math.random(145,151),h4 + math.random(16,24),30) end if cactusChance2 == 1 and hilliness < 60 and wet3 6 then sprite("Dropbox:Cactus",456,h12+math.random(22,27),32) end if grassChance1 == 2 and hilliness 5 and temp1 > 0 then sprite("Dropbox:Grass",math.random(61,64),h2) end if grassChance2 == 2 and hilliness 5 and temp1 > 0 then sprite("Dropbox:Grass",math.random(144,149),h4 - math.random(0,1)) end if grassChance3 == 2 and hilliness 5 and temp2 > 0 then sprite("Dropbox:Grass",304,h8 + math.random(0,3),40) end if treeChance1 > 0 and wet1 > 11 and wet1 <= 18 and hilliness < 25 then if temp1 > 1 then if treeType1 <= 2 then sprite("Dropbox:Tree",26,h1 + 13,37) else sprite("Dropbox:Tree2",math.random(24,27),h1 + 21,35) end end if treeType1 >= 4 and temp1 < 1 then sprite("Dropbox:Pine",26,h1 + math.random(10,14),math.random(36,46)) end end if treeChance2 > 0 and wet1 > 11 and wet1 <= 18 and hilliness < 25 then if temp1 > 0 then if treeType2 >= 3 then sprite("Dropbox:Tree2",math.random(65,67),h2 + 18,42) elseif treeType2 == 5 then sprite("Dropbox:Tree",67,h2 + math.random(7,11),math.random(26,31)) else sprite("Dropbox:Tree",math.random(64,67),h2 + 11,38) end end end if treeChance3 > 0 and wet1 > 11 and wet1 <= 18 and hilliness < 25 then if temp1 > 1 then if treeType3 <= 2 then sprite("Dropbox:Tree",math.random(142,152),h4 + math.random(11,14),math.random(33,39)) else sprite("Dropbox:Tree2",148,h4 + 16,math.random(33,38)) end end if treeType3 >= 4 and temp1 < 1 then sprite("Dropbox:Pine",math.random(145,149),h4 + math.random(9,13),math.random(36,42)) end end if treeChance4 > 0 and wet2 > 11 and wet2 <= 18 and hilliness < 25 then if temp2 > 1 then if treeType4 <= 2 then sprite("Dropbox:Tree",226,h6 + 13,37) else sprite("Dropbox:Tree2",228,h6 + 21,math.random(34,37)) end end if treeType4 >= 4 and temp2 < 1 then sprite("Dropbox:Pine",226,h6 + math.random(10,14),math.random(36,46)) end end

if treeChance5 > 0 and wet2 > 11 and wet2 <= 18 and hilliness < 25 then if temp2 > 1 then if treeType5 <= 2 then sprite("Dropbox:Tree",256,h7 + 13,37) else sprite("Dropbox:Tree2",math.random(258,260),h7 + 21,35) end end if treeType5 >= 4 and temp2 < 1 then sprite("Dropbox:Pine",256,h7 + math.random(11,14),math.random(36,46)) end end end

function overlay if swampChance1 == 1 and wet1 > 18 and hilliness 4 then sprite("Dropbox:Marsh",math.random(45,80),h2 - math.random(42,330),120) end if swampChance2 == 1 and wet2 > 18 and hilliness 4 then sprite("Dropbox:Marsh",math.random(196,260),h5 - math.random(42,290),math.random(90,150)) end if swampChance3 == 1 and wet3 > 18 and hilliness 4 then sprite("Dropbox:Marsh",math.random(458,531),h13 - math.random(42,330),math.random(60,110)) end if rockChance1 == 1 and wet1 < 16 then if wet1 > math.random(9,11) then sprite("Dropbox:Rock1",35,h2 - math.random(130,400),52) else sprite("Dropbox:Rock2",35,h2 - math.random(130,400),52) end end if rockChance2 == 1 and wet2 < 16 then if wet1 > math.random(9,11) then sprite("Dropbox:Rock1",200,h5 - math.random(130,400),math.random(48,55)) else sprite("Dropbox:Rock2",200,h5 - math.random(130,400),52) end end end --# World1 World1 = class

function World1:save saveLocalData("self.h1",h1) saveLocalData("self.h2",h2) saveLocalData("self.h3",h3) saveLocalData("self.h4",h4) saveLocalData("self.h5",h5) saveLocalData("self.h6",h6) saveLocalData("self.h7",h7) saveLocalData("self.h8",h8) saveLocalData("self.h9",h9) saveLocalData("self.h10",h10) saveLocalData("self.h11",h11) saveLocalData("self.h12",h12) saveLocalData("self.h13",h13) saveLocalData("self.h14",h14) saveLocalData("self.h15",h15) saveLocalData("self.h16",h16) saveLocalData("self.h17",h17) saveLocalData("self.h18",h18) saveLocalData("self.h19",h19) saveLocalData("self.wet1",wet1) saveLocalData("self.wet2",wet2) saveLocalData("self.wet3",wet3) saveLocalData("self.wet4",wet4) saveLocalData("self.temp1",temp1) saveLocalData("self.temp2",temp2) saveLocalData("self.temp3",temp3) saveLocalData("self.temp4",temp4) saveLocalData("self.cactusChance1",cactusChance1) saveLocalData("self.cactusChance2",cactusChance2) saveLocalData("self.grassChance1",grassChance1) saveLocalData("self.grassChance2",grassChance2) saveLocalData("self.grassChance3",grassChance3) saveLocalData("self.rockChance1",rockChance1) saveLocalData("self.rockChance2",rockChance2) saveLocalData("self.swampChance1",swampChance1) saveLocalData("self.swampChance2",swampChance2) saveLocalData("self.swampChance3",swampChance3) saveLocalData("self.mesaColor1",mesaColor1) saveLocalData("self.mesaColor2",mesaColor2)

saveLocalData("self.mesaColor3",mesaColor3) saveLocalData("self.mesaColor4",mesaColor4) saveLocalData("self.mesaColor5",mesaColor5) saveLocalData("self.mesaColor6",mesaColor6) saveLocalData("self.mesaColor7",mesaColor7) saveLocalData("self.mesaColor8",mesaColor8) saveLocalData("self.treeChance1",treeChance1) saveLocalData("self.treeChance2",treeChance2) saveLocalData("self.treeChance3",treeChance3) saveLocalData("self.treeChance4",treeChance4) saveLocalData("self.treeChance5",treeChance5) saveLocalData("self.treeType1",treeType1) saveLocalData("self.treeType2",treeType2) saveLocalData("self.treeType3",treeType3) saveLocalData("self.treeType4",treeType4) saveLocalData("self.treeType5",treeType5) end

function World1:load h1 = readLocalData("self.h1") h2 = readLocalData("self.h2") h3 = readLocalData("self.h3") h4 = readLocalData("self.h4") h5 = readLocalData("self.h5") h6 = readLocalData("self.h6") h7 = readLocalData("self.h7") h8 = readLocalData("self.h8") h9 = readLocalData("self.h9") h10 = readLocalData("self.h10") h11 = readLocalData("self.h11") h12 = readLocalData("self.h12") h13 = readLocalData("self.h13") h14 = readLocalData("self.h14") h15 = readLocalData("self.h15") h16 = readLocalData("self.h16") h17 = readLocalData("self.h17") h18 = readLocalData("self.h18") h19 = readLocalData("self.h19") wet1 = readLocalData("self.wet1") wet2 = readLocalData("self.wet2") wet3 = readLocalData("self.wet3") wet4 = readLocalData("self.wet4") temp1 = readLocalData("self.temp1") temp2 = readLocalData("self.temp2") temp3 = readLocalData("self.temp3") temp4 = readLocalData("self.temp4") cactusChance1 = readLocalData("self.cactusChance1") cactusChance2 = readLocalData("self.cactusChance2") grassChance1 = readLocalData("self.grassChance1") grassChance2 = readLocalData("self.grassChance2") grassChance3 = readLocalData("self.grassChance3") rockChance1 = readLocalData("self.rockChance1") rockChance2 = readLocalData("self.rockChance2") swampChance1 = readLocalData("self.swampChance1") swampChance2 = readLocalData("self.swampChance2") swampChance3 = readLocalData("self.swampChance3") mesaColor1 = readLocalData("self.mesaColor1") mesaColor2 = readLocalData("self.mesaColor2") mesaColor3 = readLocalData("self.mesaColor3") mesaColor4 = readLocalData("self.mesaColor4") mesaColor5 = readLocalData("self.mesaColor5") mesaColor6 = readLocalData("self.mesaColor6") mesaColor7 = readLocalData("self.mesaColor7") mesaColor8 = readLocalData("self.mesaColor8") treeChance1 = readLocalData("self.treeChance1") treeChance2 = readLocalData("self.treeChance2") treeChance3 = readLocalData("self.treeChance3") treeChance4 = readLocalData("self.treeChance4") treeChance5 = readLocalData("self.treeChance5") treeType1 = readLocalData("self.treeType1") treeType2 = readLocalData("self.treeType2") treeType3 = readLocalData("self.treeType3") treeType4 = readLocalData("self.treeType4") treeType5 = readLocalData("self.treeType5") Tload end