Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --By Vlad [vladimir264]
- --Max WxH is 51x19
- --REQUIRES 'grid' API!
- os.loadAPI("grid")
- blocks={}
- i=1
- b=1
- j=1
- function testTerrain(fileName)
- file = fs.open(fileName, "r")
- if file then
- while b==1 do
- a=file.readLine()
- --print(tostring(a)) --[THIS LINE IS FOR DEBUGGING PURPOSES ONLY]
- if a~=nil then
- ln=string.len(a)
- for I=1,ln do
- if string.find(a,"d") then
- blocks[j]={x=string.find(a,"d"),y=i,t="grass"}
- a=string.gsub(a,"d","G",1)
- j=j+1
- end
- if string.find(a,"c") then
- blocks[j]={x=string.find(a,"c"),y=i,t="dirt"}
- a=string.gsub(a,"c","D",1)
- j=j+1
- end
- if string.find(a,"8") then
- blocks[j]={x=string.find(a,"8"),y=i,t="stone"}
- a=string.gsub(a,"8","S",1)
- j=j+1
- end
- if string.find(a,"0") then
- blocks[j]={x=string.find(a,"0"),y=i,t="iron"}
- a=string.gsub(a,"0","=",1)
- j=j+1
- end
- if string.find(a,"1") then
- blocks[j]={x=string.find(a,"1"),y=i,t="source"}
- a=string.gsub(a,"1","+",1)
- j=j+1
- end
- if string.find(a,"7") then
- blocks[j]={x=string.find(a,"7"),y=i,t="light"}
- a=string.gsub(a,"7","-",1)
- j=j+1
- end
- end
- else
- b=0
- end
- i=i+1
- if i>19 or i==20 then
- i=1
- b=0
- end
- end
- file.close()
- end
- end
- function reCreate()
- for k,v in pairs(blocks) do
- if blocks[k].t=="grass" then
- paintutils.drawPixel(blocks[k].x,blocks[k].y,colors.green)
- grid.setBlock(blocks[k].x,blocks[k].y)
- elseif blocks[k].t=="dirt" then
- paintutils.drawPixel(blocks[k].x,blocks[k].y,colors.brown)
- grid.setBlock(blocks[k].x,blocks[k].y)
- elseif blocks[k].t=="stone" then
- paintutils.drawPixel(blocks[k].x,blocks[k].y,colors.lightGray)
- grid.setBlock(blocks[k].x,blocks[k].y)
- elseif blocks[k].t=="iron" then
- paintutils.drawPixel(blocks[k].x,blocks[k].y,colors.white)
- grid.setBlock(blocks[k].x,blocks[k].y)
- --elseif blocks[k].t=="source" then
- -- paintutils.drawPixel(blocks[k].x,blocks[k].y,colors.orange)
- -- grid.setBlock(blocks[k].x,blocks[k].y)
- --elseif blocks[k].t=="light" then
- -- paintutils.drawPixel(blocks[k].x,blocks[k].y,colors.gray)
- -- grid.setBlock(blocks[k].x,blocks[k].y)
- end
- end
- end
- function setBlock(X,Y,T)
- for k,v in pairs(blocks) do
- K=k
- if blocks[K].x~=X and blocks[K].y~=Y then
- blocks[j]={x=X,y=Y,t=T}
- grid.setBlock(X,Y)
- end
- end
- end
- function removeBlock(X,Y)
- for k,v in pairs(blocks) do
- K=k
- if blocks[K].x==X and blocks[K].y==Y then
- grid.removeBlock(X,Y)
- table.remove(blocks,K)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement