|
Post by Tag365 on Mar 28, 2015 19:26:54 GMT
{"saveload.lua":"if not terrain then require \"main\" end\n-- Save a chunk of terrain.\nfunction saveterrain(x, y)\n if not savedisabledbygame then\n local cx, cy = x, y\n if y > -1 then\n return false\n end\n if savingenabled then\n if not terrain[y] then\n terrain[y] = {}\n end\n local chunk = terrain[y][x]\n if chunk then\n local file = io.open(approot..\"SavedData\/\"..savetofolder..\"\/\"..y..\"x\"..x..\".chunk\", \"w\")\n --print(\"Saving chunk at \"..y, x)\n local stringx = \"\"\n for y, v in ipairs(chunk) do\n stringx = \"\"\n if v then\n for x, v2 in ipairs(v) do\n if not v2[1] then\n v2[1] = 1\n end\n if #tostring(v2[1]) < 2 then\n stringx = stringx..\"00\"..tostring(v2[1])\n elseif #tostring(v2[1]) < 3 then\n stringx = stringx..\"0\"..tostring(v2[1])\n else\n stringx = stringx..tostring(v2[1])\n end\n --[[if v2[KeyMetadata] then\n local file2 = io.open(\"SavedData\/\"..savetofolder..\"\/\"..cy*16 + y..\"x\"..cx*16 + x..\".data\", \"w\")\n local tab = {}\n for k3, v3 in pairs(v2) do\n if k3 > 1 then\n tab[k3] = v3\n end\n end\n local str = JSON.EncodeJSON(tab)\n file2:write(str)\n file2:close()\n end]]\n end\n file:write(stringx..\"\\n\")\n end\n end\n file:close()\n end\n return true\n end\n end\nend\n\n-- Saves the whole world.\nfunction saveworld()\n if not savedisabledbygame then\n local file = io.open(approot..\"SavedData\/\"..savetofolder..\"\/Data.lua\", \"w\")\n file:write(seed..\"\\n\")\n file:write(posx..\"\\n\")\n file:write(posy..\"\\n\")\n local inv = JSON.EncodeJSON(inventory)\n file:write(inv)\n file:close()\n for y, v in pairs(terrain) do\n draw.beginframe()\n draw.clear({0, 0, .4, .1})\n draw.transformedimage(\"@resources\/BlockSaving.png\", scrx*.5, scry*.5, 2, gettime()*10)\n draw.endframe()\n for x, v2 in pairs(v) do\n saveterrain(x, y)\n end\n end\n end\nend\n\nfunction loadworld(name)\n drawloadingscreen()\n savetofolder = name\n name = savetofolder\n if lfs.isFile(approot..\"SavedData\/\"..name..\"\/Data.lua\") then\n local file = io.open(approot..\"SavedData\/\"..name..\"\/Data.lua\")\n seed = file:read()\n posx = file:read()\n posy = file:read()\n inventory = tostring(file:read())\n inventory = JSON.DecodeJSON(inventory)\n file:close()\n end\n local ccx, ccy = math.floor(posx\/16\/blocksize), math.floor(posy\/16\/blocksize)\n local chunksloaded = 0\n local max = math.abs((ccy - chunkloading) - (ccy + chunkloading) - 1)*math.abs((ccx - chunkloading) - (ccx + chunkloading) - 1)\n for y = ccy - chunkloading, ccy + chunkloading do\n terrain[y] = {}\n draw.beginframe()\n draw.clear(draw.black)\n drawloadingscreen()\n draw.stringinrect(\"Loading Chunks...\", 0, 16, scrx, 48, draw.white)\n draw.fillrect(0, scry - 48, (chunksloaded\/max)*scrx, scry, draw.blue)\n draw.endframe()\n for x = ccx - chunkloading, ccx + chunkloading do\n --print(\"Loading chunk at \"..y, x)\n loadterrain(x, y)\n chunksloaded = chunksloaded + 1\n end\n end\n playgame()\nend\n\n-- Loads the world while in the main menu.\nfunction loadworldmainmenu()\n local name = savetofolder\n if lfs.isFile(approot..\"SavedData\/\"..name..\"\/Data.lua\") then\n local file = io.open(approot..\"SavedData\/\"..name..\"\/Data.lua\")\n seed = file:read()\n posx = file:read()\n posy = file:read()\n inventory = tostring(file:read())\n inventory = JSON.DecodeJSON(inventory)\n file:close()\n end\n local ccx, ccy = math.floor(posx\/16\/blocksize), math.floor(posy\/16\/blocksize)\n local chunksloaded = 0\n local max = math.abs((ccy - chunkloading) - (ccy + chunkloading) - 1)*math.abs((ccx - chunkloading) - (ccx + chunkloading) - 1)\n local lastyield = sys.gettime()\n coroutine.yield()\n for y = ccy - chunkloading, ccy + chunkloading do\n terrain[y] = {}\n for x = ccx - chunkloading, ccx + chunkloading do\n --print(\"Loading chunk at \"..y, x)\n loadterrain(x, y)\n chunksloaded = chunksloaded + 1\n if sys.gettime() - lastyield > (1\/20) then\n lastyield = sys.gettime()\n coroutine.yield()\n end\n end\n end\n return true\nend\n\n-- Loads a chunk of terrain.\nfunction loadterrain(x, y)\n terrain[y][x] = {}\n local chunk = terrain[y][x]\n local file = io.open(approot..\"SavedData\/\"..savetofolder..\"\/\"..y..\"x\"..x..\".chunk\")\n --local file2 = io.open(\"SavedData\/\"..savetofolder..\"\/\"..y..\"x\"..x..\".data\")\n if not file then\n --print(\"Generating Chunk \"..x, y..\"...\")\n generateterrain(x, y)\n else\n --print(\"Loading Chunk \"..x, y..\" from disk...\")\n local line\n for y2=1, 16 do\n line = file:read()\n chunk[y2] = {}\n for i=1, 16 do\n chunk[y2][i] = {}\n chunk[y2][i][1] = tonumber(string.sub(line, (i - 1)*3 + 1, i*3))\n --[[if lfs.isFile(\"SavedData\/\"..savetofolder..\"\/\"..y*16 + y2..\"x\"..x*16 + i..\".data\") then\n local file2 = io.open(\"SavedData\/\"..savetofolder..\"\/\"..y*16 + y2..\"x\"..x*16 + i..\".data\")\n chunk[y2][i] = JSON.DecodeJSON(file2:read(\"*a\"))\n chunk[y2][i][1] = tonumber(string.sub(line, (i - 1)*3 + 1, i*3))\n file2:close()\n end]]\n end\n end\n end\n if file then\n file:close()\n -- Regenerate Lighting\n if not skylight[x] then\n skylight[x] = {}\n for i=1, 16 do\n skylight[x][i] = 0\n end\n end\n regenlighting(x, y)\n end\nend","menus.lua":"if not terrain then require \"main\" end\n\n-- Touch event functions for craftingmenu.\nfunction cbegintouch(x, y)\n\n\nend\n\nfunction ctouch(x, y)\nend\n\nfunction cendtouch(x, y)\n if x > scrx - 128 and y > scry - 48 then\n returntogame = true\n end\nend\n\n-- This is the crafting menu function.\nfunction craftingmenu()\n draw.tracktouches(cbegintouch, ctouch, cendtouch)\n while true do\n draw.tracktouches(cbegintouch, ctouch, cendtouch)\n draw.doevents()\n -- Draw the frame\n draw.beginframe()\n draw.clear(draw.black)\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n draw.stringinrect(\"Build Items\", 0, 16, scrx, 48, draw.white)\n draw.endframe()\n -- Check if we need to return to the game.\n if returntogame then\n returntogame = false\n return\n end\n end\nend\n\nfunction tappedinventorybutton(scroll, x1, y1, x2, y2, tx, ty)\n local itemsperrow = math.floor((x2 - x1)\/48)\n local row = 0\n for k, v in pairs(inventory) do\n if k - (row*itemsperrow) > itemsperrow then\n row = row + 1\n end\n if tx > (k - (row*itemsperrow) - 1)*48 + x1 and tx < (k - (row*itemsperrow))*48 + x1 then\n if ty > y1 + (row*48) - scroll and ty < y1 + ((row + 1)*48) - scroll then\n return k\n end\n end\n end\nend\n\n-- Touch event functions for inventorymenu.\nfunction ibegintouch(x, y)\n if not buildmode then\n selectkey = tappedinventorybutton(0, 0, 0, scrx, scry, x, y)\n end\nend\n\nfunction itouch(x, y)\n shownamex, shownamey = x, y - 48\n if y > scry - 48 then\n scroll = scroll + 8\n elseif y < 48 then\n scroll = scroll - 8\n end\n if buildmode then\n local xcenter = 48*8 + 8\n local xstart = (scrx - xcenter)*.5 + 4\n if y > scry - 96 and y < scry - 48 and x > xstart and x < xstart + 48*7 then\n selected = math.min(math.floor(x\/48), 7)\n blockhovering = inventory[selected][1]\n else\n local y = y + scroll\n local blocksperrow = scrx\/48\n blockhovering = math.floor((x\/48) + (blocksperrow*math.floor(y\/48)))\n end\n else\n\n end\nend\n\nfunction iendtouch(x, y)\n blockhovering, shownamex, shownamey = nil, nil, nil\n local xcenter = 48*8 + 8\n local xstart = (scrx - xcenter)*.5 + 4\n if x > scrx - 128 and y > scry - 48 then\n returntogame = true\n elseif x > scrx - 256 and y > scry - 48 then\n settings()\n elseif x > scrx - 128*3 and y > scry - 48 then\n returntogame = true\n exitgame = true\n elseif buildmode then -- If in build mode\n local xcenter = 48*8 + 8\n local xstart = (scrx - xcenter)*.5 + 4\n if y > scry - 96 and y < scry - 48 and x > xstart and x < xstart + 48*7 then\n selected = math.min(math.floor(x\/48), 7)\n else\n local y = y + scroll\n local blocksperrow = scrx\/48\n local newblock = math.floor((x\/48) + (blocksperrow*math.floor(y\/48)))\n if drawblock[newblock] then\n inventory[selected] = {newblock, 0, 100}\n --[[elseif newblock == 0 then\n inventory[selected] = {0, 0, 0}]]\n end\n end\n else\n\n end\nend\n\n-- Main menu.\nfunction inventorymenu()\n scroll = 0\n draw.tracktouches(ibegintouch, itouch, iendtouch)\n while true do\n draw.tracktouches(ibegintouch, itouch, iendtouch)\n draw.doevents()\n -- Draw the frame\n draw.beginframe()\n draw.clear(draw.black)\n local blocksperrow = scrx\/48\n if buildmode then -- if in build mode\n for k, v in ipairs(drawblock) do\n if (math.floor(k\/blocksperrow)*48) + 24 - scroll > -24 and (math.floor(k\/blocksperrow)*48) + 24 - scroll < scry + 24 then\n draw.transformedimage( \"@resources\/Block\" .. drawblock[k]..\".png\", (48*(k - (math.floor(k\/blocksperrow)*blocksperrow)) + 24), (math.floor(k\/blocksperrow)*48) + 24 - scroll, 48\/drawblocksz[k], 0)\n end\n end\n draw.stringinrect(\"Build Mode Inventory\", 0, 16, scrx, 48, draw.white)\n else -- If not in build mode\n --draw.stringinrect(\"Inventory\", 0, 16, scrx, 48, draw.white)\n drawinventoryinbox(0, 0, 0, scrx, scry)\n end\n drawinventory()\n if blockhovering then\n drawstring = blocknames[blockhovering] or drawblock[blockhovering] or \"Block \"..blockhovering\n drawstring = drawstring..\" (\"..blockhovering..\")\"\n draw.fillbox(shownamex, shownamey, draw.stringsize(drawstring), 16, draw.white)\n draw.string(drawstring, shownamex, shownamey - 2, draw.black)\n end\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n draw.endframe()\n -- Check if we need to return to the game.\n if returntogame then\n returntogame = false\n return\n end\n end\nend\n\n-- Touch event functions for mainmenu.\nfunction mbegintouch(x, y)\n\nend\n\nfunction mtouch(x, y)\n\nend\n\nfunction mendtouch(x, y)\n if x > scrx*.5 - 128 and x < scrx*.5 + 128 then\n if y > scry - 156 and y < scry - 120 then\n gotomenu = \"worlds\"\n elseif y > scry - 120 and y < scry - 84 then\n gotomenu = \"settings\"\n elseif y > scry - 84 and y < scry - 48 then\n returnfrommainmenu = true\n elseif y > scry - 48 and y < scry - 12 then\n gotomenu = \"computerTest\"\n end\n end\nend\n\n-- Main menu.\nfunction mainmenu()\n draw.tracktouches(mbegintouch, mtouch, mendtouch)\n local loadworldco = coroutine.create(loadworldmainmenu)\n loadworldlistco = coroutine.create(updateworldlist)\n math.randomseed(sys.gettime())\n local movex, movey = math.random()*8 - 4, math.random()*8 - 4\n local timeperlocationchange = 30 + (math.random()*20 - 10)\n local trans = 2\n local timestart = gettime()\n local worldhasloaded = false\n worldlistloaded = false\n coroutine.resume(loadworldco)\n coroutine.resume(loadworldlistco)\n while true do\n draw.tracktouches(mbegintouch, mtouch, mendtouch)\n draw.doevents()\n coroutine.resume(loadworldlistco)\n -- Handle the animated main menu.\n if worldhasloaded then\n posx, posy = posx + movex, -math.abs(posy - movey)\n math.randomseed(sys.gettime())\n movex, movey = movex + (math.random()*1 - .5), movey + (math.random()*1 - .5)\n if gettime() - timestart > timeperlocationchange + trans then\n posx = math.random()*2000000 - 1000000\n posy = -math.random()*16000\n timestart = gettime()\n end\n handlegame()\n else\n err, worldhasloaded = coroutine.resume(loadworldco)\n err, worldlistloaded = coroutine.resume(loadworldlistco)\n --print(worldhasloaded)\n timestart = gettime()\n end\n savedisabledbygame = true\n -- Draw the main menu.\n draw.beginframe()\n if worldhasloaded then\n drawbackground()\n err, msg = pcall(drawterrain)\n if not err then\n print(\"error when drawing animated menu: \"..msg)\n end\n if gettime() - timestart > timeperlocationchange then\n draw.clear({0, 0, 0, (gettime() - timestart - timeperlocationchange)\/trans})\n elseif gettime() - timestart < trans then\n draw.clear({0, 0, 0, 1 - (gettime() - timestart)\/trans})\n end\n else\n draw.clear(draw.black)\n draw.setfont(\"Arial\", 48)\n draw.stringinrect(\"Touch Lua Builder\", 0, 36, scrx, scry*.5, draw.white)\n draw.setfont(\"Arial\", 16)\n end\n drawbutton(\"Play Game\", scrx*.5 - 128, scry - 156, scrx*.5 + 128, scry - 120)\n drawbutton(\"Settings\", scrx*.5 - 128, scry - 120, scrx*.5 + 128, scry - 84)\n drawbutton(\"Exit Game\", scrx*.5 - 128, scry - 84, scrx*.5 + 128, scry - 48)\n drawbutton(\"Computer Test\", scrx*.5 - 128, scry - 48, scrx*.5 + 128, scry - 12)\n draw.endframe()\n -- Check which menu we need to go to.\n if gotomenu then\n if gotomenu == \"settings\" then\n settings()\n elseif gotomenu == \"worlds\" then\n selectworldmenu()\n elseif gotomenu == \"computerTest\" then\n local id = computers.newComputer()\n computers.startComputer(id)\n computers.switchToComputer(id)\n end\n gotomenu = nil\n end\n if returnfrommainmenu then\n returnfrommainmenu = false\n return\n end\n end\nend\n\n-- Touch event functions for worldoptionsmenu.\nfunction wobegintouch(x, y)\nend\n\nfunction wotouch(x, y)\nend\n\nfunction woendtouch(x, y)\n if y > scry - 48 and x > scrx - 128 then\n returnfromworldsmenu = true\n end\nend\n\n-- Options for a world\nfunction worldoptionsmenu()\n draw.tracktouches(wobegintouch, wotouch, woendtouch)\n while true do\n draw.doevents()\n draw.beginframe()\n draw.clear(draw.black)\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n draw.stringinrect(\"Options for \"..worlds[selectedworld][1], 0, 16, scrx, 48, draw.white)\n draw.endframe()\n -- Check if we need to return.\n if returnfromworldsmenu then\n returnfromworldsmenu = false\n return\n end\n end\nend\n\n-- Touch event functions for selectworldmenu.\nfunction wbegintouch(x, y)\n\nend\n\nfunction wtouch(x, y)\n if y > scry - 96 then\n scroll = scroll + 4\n elseif y < 96 then\n scroll = scroll - 4\n end\nend\n\nfunction wendtouch(x, y)\n if x > scrx*.5 - 128 and x < scrx*.5 + 128 and y < scry - 48 then -- If a world was selected\n worldtapped = math.floor((y + scroll)\/48) + 1\n elseif y > scry - 48 and x > scrx - 128 then\n returnfromworldsmenu = true\n elseif y > scry - 48 and x > scrx - 256 then\n -- Create New World\n local worldname = keyboard.Keyboard(\"World Name\", \"New World\")\n if worldname and worldname ~= \"\" then\n savetofolder = worldname\n lfs.mkdir(approot.. \"SavedData\/\"..savetofolder)\n loadworld(savetofolder)\n end\n elseif y > scry - 48 and x > scrx - 384 then\n -- World Options\n if selectedworld then\n lfs.rmdir(approot..\"SavedData\/\"..worlds[selectedworld][1])\n worldlistloaded = false\n loadworldlistco = coroutine.create(updateworldlist)\n coroutine.resume(loadworldlistco)\n end\n end\nend\n\n-- Load the worlds list.\nfunction updateworldlist()\n local worldfolders = sys.dir(approot..\"SavedData\")\n worlds = {}\n local lastyield = gettime()\n coroutine.yield()\n for k, v in ipairs(worldfolders) do\n if v ~= \".\" and v ~= \"..\" then\n if lfs.isDirectory(approot..\"SavedData\/\"..v) then\n worlds[#worlds + 1] = {v, 0}\n for k2, v2 in ipairs(sys.dir(approot..\"SavedData\/\"..v)) do\n if v2 ~= \".\" and v2 ~= \"..\" then\n if not lfs.isDirectory(approot..\"SavedData\/\"..v..\"\/\"..v2) then\n worlds[#worlds][2] = worlds[#worlds][2] + lfs.fileSize(approot..\"SavedData\/\"..v..\"\/\"..v2)\n end\n end\n if gettime() - lastyield > (1\/20) then\n lastyield = gettime()\n coroutine.yield()\n end\n end\n end\n end\n end\n return true\nend\n\n-- Select World menu.\nfunction selectworldmenu()\n draw.tracktouches(wbegintouch, wtouch, wendtouch)\n scroll = -48\n while true do\n draw.tracktouches(wbegintouch, wtouch, wendtouch)\n draw.doevents()\n exitgame = false\n if not worldlistloaded then\n err, worldlistloaded = coroutine.resume(loadworldlistco)\n end\n -- Draw Worlds Menu\n draw.beginframe()\n draw.clear(draw.black)\n for k, v in ipairs(worlds) do\n if k*48 - scroll > 0 and (k - 1) - scroll < scry then\n draw.fillrect(scrx*.5 - 128, (k - 1)*48 - scroll, scrx*.5 + 128, k*48 - scroll, draw.gray)\n draw.string(v[1], scrx*.5 - 128, (k - 1)*48 - scroll, draw.white)\n draw.string(v[2]..\" bytes\", scrx*.5 - 128, (k - 1)*48 - scroll + 24, draw.white)\n if selectedworld == k then\n draw.rect(scrx*.5 - 128, (k - 1)*48 - scroll, scrx*.5 + 128, k*48 - scroll, draw.white)\n end\n end\n end\n draw.fillrect(0, 0, scrx, 48, draw.darkgray)\n draw.stringinrect(\"Created Worlds\", 0, 16, scrx, 48, draw.white)\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n drawbutton(\"New World\", scrx - 256, scry - 48, scrx - 128, scry)\n if selectedworld then\n drawbutton(\"Delete World\", scrx - 384, scry - 48, scrx - 256, scry)\n end\n draw.endframe()\n -- Check if a world was tapped.\n if worlds[worldtapped] then\n if worldtapped == selectedworld then\n err, msg = pcall(loadworld, worlds[worldtapped][1])\n if not err then\n print(msg)\n end\n else\n selectedworld = worldtapped\n end\n worldtapped = nil\n end\n -- Check if we need to return.\n if returnfromworldsmenu then\n returnfromworldsmenu = false\n return\n end\n end\nend\n\n-- Settings menu.\nfunction settings()\n -- Touch event functions.\n function begintouch(x, y)\n\n end\n\n function touch(x, y)\n if y > 48 and y < 96 then\n chunkloading = math.max(math.min(math.floor((x - 160)\/((sliderwidth)\/(maxchunksloaded - 2))), maxchunksloaded - 2), 0) + 2\n elseif y > 96 and y < 128 then\n autosaveselected = math.max(math.min(math.floor((x - 160)\/((sliderwidth)\/#autosave)), #autosave), 0)\n autosavetime = autosave[autosaveselected]\n end\n end\n\n function endtouch(x, y)\n if x > scrx - 128 and y > scry - 48 then\n returnfromsettings = true\n elseif x > scrx - 256 and y > scry - 48 then\n savingenabled = not savingenabled\n end\n end\n draw.tracktouches(begintouch, touch, endtouch)\n maxchunksloaded = 16\n sliderwidth = (scrx - 48) - 160\n -- Menu loop.\n while true do\n draw.doevents()\n draw.beginframe()\n draw.clear(draw.black)\n draw.stringinrect(\"Settings\", 16, 16, scrx - 16, 48, draw.white)\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n -- Slider 1\n draw.string(\"Chunks Loaded\", 24, 56, draw.white)\n draw.string((chunkloading + 1)^2, 24, 72, draw.white)\n draw.fillrect(160, 56, scrx - 48, 88, draw.gray)\n draw.fillbox(148 + (((chunkloading - 2)\/(maxchunksloaded - 2))*(sliderwidth)), 48, 24, 48, draw.white)\n -- Slider 2\n draw.string(\"Autosave time\", 24, 56 + 48, draw.white)\n if autosavetime <= 0 then\n draw.string(\"Autosave disabled\", 24, 72 + 48, draw.white)\n elseif autosavetime < 60 then\n draw.string(autosavetime..\" seconds\", 24, 72 + 48, draw.white)\n elseif autosavetime == 60 then\n draw.string((autosavetime\/60)..\" minute\", 24, 72 + 48, draw.white)\n else\n draw.string((autosavetime\/60)..\" minutes\", 24, 72 + 48, draw.white)\n end\n draw.fillrect(160, 56 + 48, scrx - 48, 88 + 48, draw.gray)\n draw.fillbox(148 + ((autosaveselected\/#autosave)*(sliderwidth)), 48 + 48, 24, 48, draw.white)\n if savingenabled then\n drawbutton(\"Disable Saving\", scrx - 256, scry - 48, scrx - 128, scry)\n else\n drawbutton(\"Enable Saving\", scrx - 256, scry - 48, scrx - 128, scry, 1)\n end\n draw.endframe()\n -- Check if we need to return.\n if returnfromsettings then\n returnfromsettings = false\n local file = io.open(approot..\"SavedData\/Settings.txt\", \"w\")\n file:write(tostring(savingenabled))\n file:write(\"\\n\"..chunkloading)\n file:write(\"\\n\"..autosaveselected)\n file:close()\n return\n end\n end\nend","blocktexture.lua":"-- Generate Blocks\ndraw.setscreen(1)\ndraw.setclearcolor(draw.magenta)\n\n-- Set Colors\nlocal graybg = {.5, .5, .5, .3}\nlocal gray0 = {.7, .7, .7, 1}\nlocal gray1 = {.6, .6, .6, .7}\nlocal gray2 = {.5, .5, .55, .6}\nlocal gray3 = {.45, .45, .45, .5}\nlocal gray4 = {.3, .3, .35, .74}\nlocal gray5 = {.35, .35, .35, .75}\nlocal graysh = {.4, .4, .4, .33}\nlocal brown = {.6, .4, 0, 1}\nlocal brownsh = {.3, .1, 0, .33}\nlocal brownlg = {.8, .6, 0, .33}\nlocal wood = {.4, .2, 0, 1}\nlocal woodplank = {.6, .5, .2, 1}\nlocal greensh = {.1, .5, 0, .33}\nlocal waterlg = {.64, .64, .9, .654}\n\nfunction cobblerock(x, y)\n draw.fillrect(x, y, x + 3, y + 3, gray3)\n draw.fillrect(x, y, x + 2, y + 2, gray2)\n draw.line(x + 1, y + 1, x + 3, y + 1, gray1)\n draw.line(x, y, x, y + 3, gray1)\n draw.point(x, y, draw.gray)\n draw.line(x + 1, y + 4, x + 3, y + 4, gray5)\n draw.line(x + 3, y + 1, x + 3, y + 3, gray4)\n draw.point(x + 3, y + 3, gray5)\nend\n\n-- Draw Saving Icon\n--[=[\ndraw.beginframe()\ndraw.setlinestyle(2, \"butt\")\ndraw.circle(24, 24, 16, draw.white)\ndraw.clearrect(24, 0, 48, 24)\ndraw.line(16, 0, 24, 8, draw.white)\ndraw.lineto(16, 16, draw.white)\ndraw.endframe()\ndraw.setlinestyle(1, \"butt\")\ndraw.imagesave(\"@resources\/BlockSaving.png\", 0, 0, 48, 48)\n]=]\n\ndraw.setantialias(false)\n\n--[[ Draw Stone\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockStone.png\", 0, 0, 1, 1)]]\n\n-- Draw Cobblestone\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\nfor x=0, 16, 4 do\n for y=0, 16, 4 do\n cobblerock(x + 2, y + 2)\n cobblerock(x, y)\n end\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockCobblestone.png\", 0, 0, 4, 4)\nsys.sleep(math.huge)\n\n--[=[\n-- Draw Dirt\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.brown)\nmath.randomseed(363)\n--draw.rect(0, 1, 3, 4, draw.brown)\n--[[for i=1, 33 do\n x = math.random()*16\n draw.line(x, math.random()*16, x, math.random()*16, brownsh)\nend]]\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockDirt.png\", 0, 0, 4, 4)\n\n-- Draw Grass\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.brown)\nmath.randomseed(363)\nfor y=0, 16, 2 do\n for x=0, 16, 2 do\n draw.point(x, y, brownsh)\n draw.point(x + 1, y + 1, brownsh)\n end\nend\ndraw.rect(0, 1, 3, 4, draw.brown)\n--[[for i=1, 33 do\n x = math.random()*16\n draw.line(x, math.random()*16, x, math.random()*16, brownsh)\nend]]\ndraw.line(0, 0, 48, 0, draw.green)\ndraw.line(0, 1, 48, 1, draw.green)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockGrass.png\", 0, 0, 4, 4)\n\n-- Draw Wood\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, wood)\nmath.randomseed(363)\nfor i=1, 33 do\n x = math.random()*16\n draw.line(x, math.random()*16, x, math.random()*16, brownlg)\n draw.line(x, math.random()*16, x, math.random()*16, brownsh)\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockWood.png\", 0, 0, 4, 4)\n\n-- Draw Leaves\ndraw.beginframe()\ndraw.clearscreen()\nfor y=0, 16, 2 do\n for x=0, 16, 2 do\n draw.point(x, y, draw.green)\n draw.point(x + 1, y + 1, draw.green)\n end\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockLeaves.png\", 0, 0, 4, 4)\n\n-- Draw Water\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, waterlg)\nmath.randomseed(222)\nfor i=1, 33 do\n x = math.random()*16\n draw.line(x, math.random()*16, x, math.random()*16, waterlg)\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockWater.png\", 0, 0, 1, 1)\n\n-- Draw Lava\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.red)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockLava.png\", 0, 0, 1, 1)\n\n-- Draw Coal Ore\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\ndraw.fillrect(1, 1, 15, 15, draw.black)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockCoalOre.png\", 0, 0, 3, 3)\n\n-- Draw Iron Ore\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\ndraw.fillrect(1, 1, 15, 15, {.4, .5, 0, 1})\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockIronOre.png\", 0, 0, 3, 3)\n\n-- Draw Sapphire Ore\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\ndraw.fillrect(1, 1, 15, 15, draw.blue)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockSapphireOre.png\", 0, 0, 3, 3)\n\n-- Draw Ruby Ore\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\ndraw.fillrect(1, 1, 15, 15, draw.red)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockRubyOre.png\", 0, 0, 3, 3)\n\n-- Draw Emerald Ore\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\ndraw.fillrect(1, 1, 15, 15, {0, 1, 0, 1})\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockEmeraldOre.png\", 0, 0, 3, 3)\n\n-- Draw Trace Ore\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\nfor x=1, 16, 2 do\n for y=1, 16, 2 do\n draw.point(x, y, draw.red)\n end\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockTraceOre.png\", 0, 0, 3, 3)\n\n-- Draw Coal\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 47, 48, draw.black)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockCoal.png\", 0, 0, 4, 4)\n\n-- Draw Wood Planks\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, woodplank)\nfor i=3, 15, 4 do\n draw.line(0, i, 16, i, wood)\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockWoodPlanks.png\", 0, 0, 4, 4)\n\n-- Draw Crafting Table\ndraw.beginframe()\n--draw.clearscreen()\ndraw.fillrect(0, 0, 16, 2, woodplank)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockCraftingTable.png\", 0, 0, 15, 15)\n\n-- Draw Furnance\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.gray)\ndraw.fillrect(1, 8, 14, 14, draw.lightgray)\ndraw.rect(0, 8, 14, 15, graysh)\ndraw.rect(0, 1, 14, 15, graysh)\ndraw.rect(0, 1, 14, 15, graysh)\ndraw.rect(4, 10, 10, 15, graysh)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockFurnance.png\", 0, 0, 15, 15)\n\n-- Draw Iron Cable\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 5, 16, 11, draw.darkgray)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockIronCable.png\", 0, 0, 15, 15)\n\n-- Draw Tin Cable\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 6, 16, 10, draw.gray)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockTinCable.png\", 0, 0, 15, 15)\n\n-- Draw Computer Block\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, draw.black)\ndraw.fillrect(1, 11, 14, 14, draw.darkgray)\ndraw.rect(0, 12, 14, 15, graysh)\ndraw.rect(0, 1, 14, 15, graysh)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockComputer.png\", 0, 0, 15, 15)\n\n-- Draw Generator\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, {.95, .95, .95, 1})\ndraw.fillrect(1, 1, 14, 15, {.9, .9, .9, 1})\ndraw.fillrect(0, 8, 16, 16, {.75, .75, .75, 1})\ndraw.fillrect(1, 9, 14, 14, {.85, .85, .85, 1})\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockGenerator.png\", 0, 0, 15, 15)\n\n-- Draw Solar Panel\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, {.95, .95, .95, 1})\ndraw.fillrect(1, 1, 14, 15, {.9, .9, .9, 1})\ndraw.fillrect(0, 8, 16, 16, {.75, .75, .75, 1})\ndraw.fillrect(1, 9, 14, 14, {.85, .85, .85, 1})\ndraw.fillrect(1, 0, 14, 1, draw.blue)\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockSolarPanel.png\", 0, 0, 15, 15)\n\n-- Draw Battery Box\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, wood)\ndraw.fillrect(0, 8, 16, 16, {.75, .75, .75, 1})\ndraw.fillrect(1, 9, 14, 14, {.85, .85, .85, 1})\nfor y=9, 16, 2 do\n for x=1, 13, 2 do\n draw.point(x, y, draw.red)\n draw.point(x + 1, y + 1, draw.red)\n end\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockBatteryBox.png\", 0, 0, 15, 15)\n\n-- Draw Electric Furnance\ndraw.beginframe()\ndraw.clearscreen()\ndraw.fillrect(0, 0, 16, 16, {.95, .95, .95, 1})\ndraw.fillrect(1, 1, 14, 15, {.9, .9, .9, 1})\ndraw.fillrect(0, 8, 16, 16, {.75, .75, .75, 1})\ndraw.fillrect(1, 9, 14, 14, {.85, .85, .85, 1})\nfor y=9, 16, 2 do\n for x=1, 13, 2 do\n draw.point(x, y, draw.red)\n draw.point(x + 1, y + 1, draw.red)\n end\nend\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockElectricFurnance.png\", 0, 0, 15, 15)\n]=]\n\n-- Draw Chest\ndraw.beginframe()\ndraw.clearscreen()\ndraw.setantialias(false)\ndraw.fillrect(1, 4, 13, 15, woodplank)\ndraw.rect(1, 4, 13, 15, wood)\ndraw.rect(1, 4, 13, 7, wood)\ndraw.fillrect(6, 6, 8, 10, {.9, .9, .9, 1})\ndraw.rect(6, 6, 8, 10, {.8, .8, .8, 1})\ndraw.endframe()\ndraw.imagesave(\"@resources\/BlockChest.png\", 0, 0, 15, 15)\n--sys.sleep(math.huge)\n\n-- Done Generating Images","ExportApp.lua":"print('Generating Installer Stubs!')\nlocal FileTable = {}\n\nfunction requireFromRoot(File)\n local Handle, err = io.open(\"..\/\"..File..\".lua\")\n local String, Funct = \"\", nil\n if Handle then\n String = \"require = requireFromRoot\\n\"..Handle:read(\"*a\")\n Handle:close()\n Funct = load(String)\n end\n --local Funct, err = loadfile(\"..\"..File..\".lua\")\n if Funct then\n local var1 = Funct()\n require = Require\n return var1 or true\n else\n print(err)\n end\nend\n\nlfs = require \"lfs\"\n\nJSON = require(\"JSON\")\nlocal files = sys.dir()\n\nfunction lfs.isDirectory(Path)\n return lfs.attributes(Path, \"mode\") == \"directory\"\nend\n\nfor k, v in ipairs(files) do\n if v ~= \".\" and v ~= \"..\" and v ~= \"InstallStub\" and v~= \"SavedData\" and v~= \"Resources\" then\n if lfs.isDirectory(v) then\n local sub = sys.dir(v)\n for k2, v2 in ipairs(sub) do\n if v2 ~= \".\" and v2 ~= \"..\" and string.sub(v, -8)~=\"stub.lua\" then\n files[#files + 1] = v..\"\/\"..v2\n end\n end\n end\n end\nend\n\nfor k, v in ipairs(files) do\n if v ~= \".\" and v ~= \"..\" and string.sub(v, -8)~=\"stub.lua\" then\n local file = io.open(v)\n if file then\n FileTable[v] = file:read(\"*a\")\n file:close()\n end\n end\nend\n\n\nlocal String = JSON.EncodeJSON(FileTable)\nprint(#String..\" bytes\")\n\nif not lfs.isDirectory(\"InstallStub\") then\n lfs.mkdir(\"InstallStub\")\nend\n\nprint(\"Saving...\")\nlocal Chunk = 8192*16\nfor i=1, math.ceil(#String\/Chunk) do\n file = io.open(\"InstallStub\/TouchLuaBuilder\".. i..\"stub.lua\", \"w\")\n file:write(string.sub(String, ((i - 1)*Chunk) + 1, math.min(i*Chunk, #String)))\n file:close()\nend\nprint(\"Done!\")","drawblocks.lua":"print(\"Loading Blocks...\")\n\n-- Used in the string calculation to draw the correct image for each block. Also used for a fallback to show a name for unnamed blocks.\ndrawblock = {\"\", \"Stone\", \"Cobblestone\", \"Dirt\", \"Grass\", \"Wood\", \"Leaves\", \"Water\", \"Lava\", \"CoalOre\", \"IronOre\", \"SapphireOre\", \"RubyOre\", \"EmeraldOre\", \"TraceOre\", \"UraniumOre\", \"LapisOre\", \"Coal\", \"Iron\", \"Sapphire\", \"Ruby\", \"Emerald\", \"Trace\", \"Uranium\", \"Lapis\", \"WoodPlanks\", \"CraftingTable\", \"Furnance\", \"RubberTree\", \"RubberTreeSpot\", \"WoodPickaxe\", \"WoodAxe\", \"WoodSword\", \"WoodHoe\", \"StonePickaxe\", \"StoneAxe\", \"StoneSword\", \"StoneHoe\", \"IronPickaxe\", \"IronAxe\", \"IronSword\", \"IronHoe\", \"IronCable\", \"TinCable\", \"Computer\", \"Generator\", \"SolarPanel\", \"LavaGenerator\", \"WaterMill\", \"Windmill\", \"BatteryBox\", \"StorageBlock\", \"NTSU\", \"ElectricFurnance\", \"Extractor\", \"Macerator\", \"Compressor\", \"Chest\"}\n\n-- The actual names that each block will be called by in the game.\nblocknames = {\"Air\", \"Stone\"}\n\n-- This code caches images used when drawing blocks.\ndrawblocksz = {}\nfor k, v in ipairs(drawblock) do\n drawblocksz[k] = draw.cacheimage( \"@resources\/Block\" .. v..\".png\")\nend","LuaApp.lua":"-- This is a script used for Lua App Manager.\nTouch Lua Builder\nTouch Lua Builder\nExplore the infinite ranges of the two dimentional world.\nIndev 0.1.1\nAuthor\nmain\nicon.png","blockmenus.lua":"if not terrain then require \"main\" end\n\n-- Touch event functions for chestmenu.\nfunction cbegintouch(x, y)\n local selectkey = tappedinventorybutton(invscroll, 0, 0, scrx*.5 - 48, scry, x, y)\n if selectkey then\n movingicon = selectkey\n movex, movey = x, y\n else\n selectkey = tappedinventorybutton(invscroll, scrx*.5, 0, scrx - 48, scry, x, y)\n if selectkey then\n movingicon = {selectkey}\n movex, movey = x, y\n end\n end\n oldy = y\nend\n\nfunction ctouch(x, y)\n if movingicon then\n movex, movey = x, y\n elseif oldy then\n invscroll = invscroll + (y - oldy)\n oldy = y\n end\nend\n\nfunction cendtouch(x, y)\n if x > scrx - 128 and y > scry - 48 then\n returntogame = true\n end\n if movingicon then\n replaceobject = tappedinventorybutton(invscroll, 0, 0, scrx*.5 - 48, scry, x, y)\n if not replaceobject then\n replaceobject = {tappedinventorybutton(invscroll, scrx*.5, 0, scrx - 48, scry, x, y) or 1}\n end\n end\n movex, movey = nil, nil\n oldy = nil\nend\n\nfunction chestmenu(blockx, blocky)\n local chunk = terrain[math.floor(blocky\/16)][math.floor(blockx\/16)]\n local block = chunk[blocky - (math.floor(blocky\/16)*16) + 1][blockx - (math.floor(blockx\/16)*16) + 1]\n if block[1] ~= 58 then\n error(\"block at y:\"..blocky..\" x:\"..blockx..\" is not a valid chest. (blockID is \"..block[1]..\")\", 2)\n end\n if not block[KeyChest] then\n block[KeyMetadata] = true\n block[KeyChest] = {}\n for k=1, 40 do\n block[KeyChest][k] = {0, 0, 0}\n end\n end\n invscroll = 0\n while true do\n draw.tracktouches(cbegintouch, ctouch, cendtouch)\n draw.doevents()\n if replaceobject and movingicon then\n if type(replaceobject) == \"table\" then\n if type(movingicon) == \"table\" then\n local blockitem = block[KeyChest][replaceobject[1]]\n block[KeyChest][replaceobject[1]] = block[KeyChest][movingicon[1]]\n block[KeyChest][movingicon[1]] = blockitem\n movingicon = nil\n replaceobject = nil\n else\n local blockitem = block[KeyChest][replaceobject[1]]\n block[KeyChest][replaceobject[1]] = inventory[movingicon]\n inventory[movingicon] = blockitem\n movingicon = nil\n replaceobject = nil\n end\n elseif type(replaceobject) == \"number\" then\n if type(movingicon) == \"table\" then\n local blockitem = inventory[replaceobject]\n inventory[replaceobject] = block[KeyChest][movingicon[1]]\n block[KeyChest][movingicon[1]] = blockitem\n movingicon = nil\n replaceobject = nil\n else\n local blockitem = inventory[replaceobject]\n inventory[replaceobject] = inventory[movingicon]\n inventory[movingicon] = blockitem\n movingicon = nil\n replaceobject = nil\n end\n end\n end\n -- Draw the frame.\n draw.beginframe()\n draw.clear(draw.black)\n draw.stringinrect(\"Furnance at y:\"..blocky..\" x:\"..blockx, 0, 16, scrx, 48, draw.white)\n drawinventoryinbox(invscroll, 0, 0, scrx*.5 - 48, scry)\n drawinventoryinbox(invscroll, scrx*.5, 0, scrx - 48, scry, block[KeyChest])\n if movex then\n if type(movingicon) == \"number\" then\n drawitemslot(inventory[movingicon], movex, movey, true)\n elseif type(movingicon) == \"table\" then\n drawitemslot(block[KeyChest][movingicon[1]], movex, movey, true)\n end\n end\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n draw.endframe()\n -- Check if we need to return to the game.\n if returntogame then\n returntogame = false\n return\n end\n end\nend\n\nfunction batteryboxmenu(blockx, blocky)\n local chunk = terrain[math.floor(blocky\/16)][math.floor(blockx\/16)]\n local block = chunk[blocky - (math.floor(blocky\/16)*16) + 1][blockx - (math.floor(blockx\/16)*16) + 1]\n while true do\n draw.tracktouches(fbegintouch, ftouch, fendtouch)\n draw.doevents()\n -- Draw the frame.\n draw.beginframe()\n draw.clear(draw.black)\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n draw.string(\"Energy: \"..block[4], 48, 48, draw.white)\n draw.stringinrect(\"BatteryBox at y:\"..blocky..\" x:\"..blockx, 0, 16, scrx, 48, draw.white)\n draw.endframe()\n -- Check if we need to return to the game.\n if returntogame then\n returntogame = false\n return\n end\n end\nend\n\n-- Touch event functions for furnancemenu.\nfunction fbegintouch(x, y)\n local selectkey = tappedinventorybutton(invscroll, 0, 0, scrx*.5, scry, x, y)\n if selectkey then\n movingicon = selectkey\n end\n oldy = y\nend\n\nfunction ftouch(x, y)\n if movingicon then\n movex, movey = x, y\n elseif oldy then\n invscroll = invscroll + (y - oldy)\n oldy = y\n end\nend\n\nfunction fendtouch(x, y)\n if x > scrx - 128 and y > scry - 48 then\n returntogame = true\n end\n if movingicon then\n if x > scrx - 128 and x < scrx - 128 + 48 and y > scry*.5 - 48 and y < scry*.5 then\n replaceitem = KeySmeltItem\n elseif x > scrx - 128 and x < scrx - 128 + 48 and y > scry*.5 + 48 and y < scry*.5 + (48*2) then\n replaceitem = KeyFuelItem\n else\n movingicon = false\n end\n end\n oldy = nil\n movex, movey = nil, nil\nend\n\nfunction furnancemenu(blockx, blocky)\n local chunk = terrain[math.floor(blocky\/16)][math.floor(blockx\/16)]\n local block = chunk[blocky - (math.floor(blocky\/16)*16) + 1][blockx - (math.floor(blockx\/16)*16) + 1]\n invscroll = 0\n while true do\n draw.tracktouches(fbegintouch, ftouch, fendtouch)\n draw.doevents()\n if replaceitem == KeySmeltItem then\n if block[KeySmeltItem][3] <= 0 then\n block[KeySmeltItem] = inventory[movingicon]\n inventory[movingicon] = {0, 0, 0}\n movingicon = nil\n else\n local blockitem = block[KeySmeltItem]\n block[KeySmeltItem] = inventory[movingicon]\n inventory[movingicon] = blockitem\n movingicon = nil\n end\n elseif replaceitem == KeyFuelItem then\n if block[KeyFuelItem][3] <= 0 then\n block[KeyFuelItem] = inventory[movingicon]\n inventory[movingicon] = {0, 0, 0}\n movingicon = nil\n end\n end\n replaceitem = nil\n -- Draw the frame.\n draw.beginframe()\n draw.clear(draw.black)\n drawbutton(\"Back\", scrx - 128, scry - 48, scrx, scry)\n if block[1] == 28 then -- Furnance\n draw.setclip(scrx - 128, 0, scrx - 128 + ((block[KeyProgress]\/100)*48), scry)\n draw.fillrect(scrx - 128, scry*.5 - 24, scrx, scry*.5 + 24, draw.white)\n draw.clearclip()\n drawitemslot(block[KeySmeltItem], scrx - 128, scry*.5 - 48)\n drawitemslot(block[KeyFuelItem], scrx - 128, scry*.5 + 48)\n drawitemslot(block[KeyOutputItem], scrx - 64, scry*.5)\n else -- Electric Furnance\n draw.setclip(scrx - 128, 0, scrx - 128 + ((block[KeyProgress]\/100)*48), scry)\n draw.fillrect(scrx - 128, scry*.5 - 24, scrx, scry*.5 + 24, draw.white)\n draw.clearclip()\n drawitemslot(block[KeySmeltItem], scrx - 128, scry*.5 - 48)\n drawitemslot(block[KeyFuelItem], scrx - 128, scry*.5 + 48)\n drawitemslot(block[KeyOutputItem], scrx - 64, scry*.5)\n draw.string(\"Energy: \"..block[KeyEnergy], 48, 48, draw.white)\n end\n draw.stringinrect(\"Furnance at y:\"..blocky..\" x:\"..blockx, 0, 16, scrx, 48, draw.white)\n drawinventoryside(invscroll)\n if movex then\n drawitemslot(inventory[movingicon], movex, movey, true)\n end\n draw.endframe()\n -- Check if we need to return to the game.\n if returntogame then\n returntogame = false\n return\n end\n end\nend","ComROM\/BIOS.lua":"print('Hello World!')\n","blockdata.lua":"if not terrain then require \"main\" end\n\n-- Local Key values\nKeyDamage = 2\nKeyFuel = 3\nKeyProgress = 4\nKeySmeltItem = 5\nKeyFuelItem = 6\nKeyOutputItem = 7\nKeyChest = 8\nKeySidesConn = 9\nKeyIsEnergyBlock = 10\nKeyEnergy = 11\nKeyEnergyLimit = 12\nKeyMetadata = 13\nKeyLightVal = 14\nKeySunlightBlocked = 15\n\n-- Shortcuts\nlocal KeyOutput = KeyOutputItem\nlocal IsEnergyBlock = KeyIsEnergyBlock\n\n-- Block Information\nitemdamagelimit = {\n [5] = 10\n}\ncraftingitems = {\n\n}\nsmeltingitems = {\n [3] = 2, -- Cobblestone = Stone\n}\n\nfunction regenlighting(chunkx, chunky)\n local ypos = chunky*16\n local chunk = terrain[chunky][chunkx]\n local ceilchunk = skylight[chunkx]\n for y, v in ipairs(chunk) do\n for x, v2 in ipairs(v) do\n if y + ypos > ceilchunk[x] then\n -- Lighting is blocked\n v2[KeyLightVal] = math.max(math.floor(15 - math.abs((y + ypos) - ceilchunk[x])), 0)\n elseif (y + ypos) < ceilchunk[x] and v2[1] > 1 then\n -- Lighting is now blocked\n ceilchunk[x] = y + ypos\n --print(chunkx*16 + x..\" is now blocked at \"..ceilchunk[x])\n elseif (y + ypos) == ceilchunk[x] and v2[1] < 2 then\n -- Lighting is now unblocked\n ceilchunk[x] = y + ypos + 1\n --print(chunkx*16 + x..\" is now unblocked at \"..ceilchunk[x])\n else\n -- Lighting is not blocked\n v2[KeyLightVal] = 15\n end\n end\n end\nend\n\n-- Functions for handling a block\nhandleblock = {}\n\n-- Handle Furnance\nhandleblock[28] = function(v2, chunk, chx, chy, x, y)\n if not v2[KeyFuel] then\n v2[KeyFuel] = 800\n v2[KeyProgress] = 0\n v2[KeySmeltItem] = {0, 0, 0}\n v2[KeyFuelItem] = {0, 0, 0}\n v2[KeyOutputItem] = {0, 0, 0}\n end\n if v2[KeySmeltItem][3] > 0 and v2[KeyOutputItem][3] <= 0 then\n if smeltingitems[v2[KeySmeltItem][1]] then\n v2[KeyOutputItem] = {smeltingitems[v2[KeySmeltItem][1]], 0, 0}\n end\n end\n if v2[KeyProgress] > 100 and v2[KeySmeltItem][3] > 1 then\n -- Smelting is complete\n v2[KeyProgress] = 0\n v2[KeyOutput][3] = v2[KeyOutput][3] + 1\n v2[KeySmeltItem][3] = v2[KeySmeltItem][3] - 1\n elseif v2[KeyOutput][3] > 1 then\n -- Smelting is not complete, add progress\n v2[KeyProgress] = v2[KeyProgress] + 1\n end\nend\n\n-- Handle All Wires\nfunction HandleWire(v2, chunk, chx, chy, x, y)\n if not v2[KeyEnergy] then\n v2[KeyEnergy] = 0\n v2[KeyIsEnergyBlock] = true\n end\n if v2[KeyEnergy] > 0 then\n if chunk[y + 1] then -- Go Down\n if chunk[y + 1][x] then\n if chunk[y + 1][x][IsEnergyBlock] == true then\n chunk[y + 1][x][KeyEnergy] = chunk[y + 1][x][KeyEnergy] + 1\n v2[KeyEnergy] = v2[KeyEnergy] - 1\n end\n end\n elseif terrain[chy + 1][chx] then\n if terrain[chy + 1][chx][1][x][IsEnergyBlock] == true then\n terrain[chy + 1][chx][1][x][KeyEnergy] = terrain[chy + 1][chx][1][x][KeyEnergy] + 1\n v2[KeyEnergy] = v2[KeyEnergy] - 1\n end\n end\n if chunk[y - 1] then -- Go Up\n if chunk[y - 1][x] then\n if chunk[y - 1][x][IsEnergyBlock] == true then\n chunk[y - 1][x][KeyEnergy] = chunk[y - 1][x][KeyEnergy] + 1\n v2[KeyEnergy] = v2[KeyEnergy] - 1\n end\n end\n elseif terrain[chy - 1][chx] then\n if terrain[chy - 1][chx][1][x][IsEnergyBlock] == true then\n terrain[chy - 1][chx][1][x][KeyEnergy] = terrain[y - 1][chx][1][x][KeyEnergy] + 1\n v2[KeyEnergy] = v2[KeyEnergy] - 1\n end\n end\n if chunk[y][x - 1] then -- Go Left\n if chunk[y][x - 1][IsEnergyBlock] == true then\n chunk[y][x - 1][KeyEnergy] = chunk[y][x - 1][KeyEnergy] + 1\n v2[KeyEnergy] = v2[KeyEnergy] - 1\n end\n end\n if chunk[y][x + 1] then -- Go Right\n if chunk[y][x + 1][IsEnergyBlock] == true then\n chunk[y][x + 1][KeyEnergy] = chunk[y][x + 1][KeyEnergy] + 1\n v2[KeyEnergy] = v2[KeyEnergy] - 1\n end\n end\n end\nend\n\nfunction HandleElecFurn(v2, chunk, chx, chy, x, y, convtab)\n if not v2[KeyEnergy] then\n v2[KeyEnergy] = 0\n v2[KeyProgress] = 0\n v2[KeyIsEnergyBlock] = true\n v2[KeySmeltItem] = {0, 0, 0}\n v2[KeyFuelItem] = {0, 0, 0}\n v2[KeyOutputItem] = {0, 0, 0}\n end\n if v2[KeySmeltItem][3] > 0 and v2[KeyOutputItem][3] <= 0 then\n if convtab[v2[KeySmeltItem][1]] then\n v2[KeyOutputItem] = {convtab[v2[KeySmeltItem][1]], 0, 0}\n end\n end\n if v2[KeyEnergy] > 0 then\n if v2[KeyProgress] > 100 and v2[KeySmeltItem][3] > 1 then\n -- Smelting is complete\n v2[KeyProgress] = 0\n v2[KeyOutput][3] = v2[KeyOutput][3] + 1\n v2[KeySmeltItem][3] = v2[KeySmeltItem][3] - 1\n else\n -- Smelting is not complete, add progress\n v2[KeyProgress] = v2[KeyProgress] + 1\n v2[KeyEnergy] = v2[KeyEnergy] - 1\n end\n else\n end\nend\n\n-- Handle Wire\nhandleblock[43] = function(v2, chunk, chx, chy, x, y)\n HandleWire(v2, chunk, chx, chy, x, y)\nend\n\n-- Handle Solar Panel\nhandleblock[47] = function(v2, chunk, chx, chy, x, y)\n if not v2[KeyEnergy] then\n v2[KeyEnergy] = 0\n end\n v2[KeyEnergy] = math.min(v2[KeyEnergy] + 1, 280)\n HandleWire(v2, chunk, chx, chy, x, y)\nend\n\n-- Handle Electric Furnance\nhandleblock[54] = function(v2, chunk, chx, chy, x, y)\n HandleElecFurn(v2, chunk, chx, chy, x, y, smeltingitems)\nend\n\n-- Handle Chest\nhandleblock[58] = function(v2, chunk, chx, chy, x, y)\n if not v2[KeyChest] then\n -- Generate empty chest contents\n v2[KeyMetadata] = true\n v2[KeyChest] = {}\n for k=1, 40 do\n v2[KeyChest][k] = {0, 0, 0}\n end\n end\nend","main.lua":"-- This game requires the draw library.\n-- Initalize variables.\nversion = \"Indev 0.1.3\"\nterrain = {}\nskylight = {}\nposx, posy = 0, -3874\nblocksize = 64\nchunkloading = 20\nautosavetime = 60\nautosaveselected = 2\nautosave = {[0] = 0, [1] = 10, [2] = 60, [3] = 300, [4] = 900, [5] = 1800, [6] = 3600}\nsavingenabled = false\nsavedisabledbygame = true\nsavetofolder = \"NewWorld\"\nbuildmode = true\nmaxjump = 12\ncurjump = 0\nlocal fps = 30\n\n-- Set the approot location so we can correctly acess the saved data location.\napproot = approot or \"\"\n\n-- Set the function used to get real-world time.\ngettime = os.clock\n\n-- Require the enhanced lfs library.\nlfs = require \"lfsplus\"\n\n-- Switch to graphics screen.\ndraw.setscreen(1)\ndraw.settitle(\"Block Game Test\")\nscrx, scry = draw.getport()\n\n-- Automaticly create the required resources for running the game.\nif not lfs.isDirectory(approot..\"SavedData\") then\n lfs.mkdir(approot..\"SavedData\")\n lfs.mkdir( approot .. \"SavedData\/\"..savetofolder)\n require \"blocktextures\"\nend\n\n-- Set some variables used when generating terrain.\nterrainflat = false\nmaxheight = 128 --128*2048\nwaterheight = 64\nseed = math.random()*(2^52)\nmath.randomseed(seed)\n\ngametime = 0\nplayerhealth = 20\nplayermaxhealth = 20\ninventory = {{4, 0, 100}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}\nwhile #inventory < 40 do\n inventory[#inventory + 1] = {0,0,0}\nend\nselected = 2\n\n-- Load Settings file from disk\nlocal file = io.open(approot..\"SavedData\/Settings.txt\")\nif file then\n savingenabled = file:read() == \"true\"\n chunkloading = tonumber(file:read())\n autosaveselected = tonumber(file:read())\n autosavetime = autosave[autosaveselected]\n file:close()\nend\n\n-- Create local variables to increase speed.\nlocal math = math\nlocal draw = draw\nlocal transformedimage = draw.transformedimage\nlocal pairs, ipairs = pairs, ipairs\n\n-- This function is used to draw a loading screen.\nfunction drawloadingscreen()\n draw.beginframe()\n draw.clear(draw.black)\n draw.transformedimage(\"@resources\/BlockSaving.png\", scrx*.5, scry*.5, 3, gettime()*math.pi)\n draw.endframe()\nend\n\n-- Draw a loading screen while the player is forced to wait.\ndrawloadingscreen()\ndraw.cacheimage(\"@resources\/BlockSaving.png\")\n\n-- Require other modules used in the game.\nrequire \"drawblocks\"\nrequire \"drawmain\"\nrequire \"menus\"\nrequire \"blockmenus\"\nrequire \"saveload\"\nrequire \"computer\"\nrequire \"blockdata\"\nJSON = require \"JSON\"\nkeyboard = require \"keyboard\"\n\nlocal drawblock = drawblock\nlocal handleblock = handleblock\n\n-- This function checks if the time the player set before autosaving has expired, then when it expires it will automaticly autosave.\nfunction handleautosave()\n if autosavetime > 0 then\n if not timetonextautosave then\n timetonextautosave = gettime() + autosavetime\n end\n if savingenabled then\n if gettime() > timetonextautosave then\n -- Automaticly save the world.\n print(\"Autosaving World...\")\n saveworld()\n -- Set the time to next autosave.\n timetonextautosave = gettime() + autosavetime\n end\n end\n end\nend\n\nfunction handlechunk(x, y)\n local chunk = terrain[y][x]\n for y2, v in ipairs(chunk) do\n for x2, v2 in ipairs(v) do\n if handleblock[v2[1]] then\n handleblock[v2[1]](v2,chunk,x,y, x2,y2)\n end\n end\n end\nend\n\n-- This function is used to handle gameplay.\nfunction handlegame()\n local ccx, ccy = math.floor(posx\/16\/blocksize), math.floor(posy\/16\/blocksize)\n -- Handle terrain chunk streaming.\n -- Remember, the y comes first before x!\n for y = ccy - (chunkloading + 2), ccy + chunkloading + 2 do\n if y > ccy - chunkloading and y < ccy + chunkloading then\n if not terrain[y] then\n terrain[y] = {}\n end\n for x = ccx - (chunkloading + 2), ccx + chunkloading + 2 do\n if x > ccx - chunkloading and x < ccx + chunkloading then\n if not terrain[y][x] then\n loadterrain(x, y)\n else\n handlechunk(x, y)\n end\n else\n if terrain[y][x] then\n saveterrain(x, y)\n terrain[y][x] = nil\n skylight[x] = nil\n end\n end\n end\n elseif terrain[y] then\n for x = ccx - (chunkloading + 2), ccx + chunkloading + 2 do\n saveterrain(x, y)\n terrain[y][x] = nil\n end\n end\n end\n -- Handle block placement.\n if btx then -- If the player held a block.\n local chunk = terrain[math.floor(bty\/16)][math.floor(btx\/16)]\n if chunk then\n local blx, bly = (btx - math.floor(btx\/16)*16) + 1, (bty - math.floor(bty\/16)*16) + 1\n -- Attempt to place a block.\n if buildmode then\n if chunk[bly][blx][1] ~= inventory[selected][1] then\n chunk[bly][blx] = {inventory[selected][1]}\n regenlighting(math.floor(btx\/16), math.floor(bty\/16))\n end\n else -- If in survival mode\n if chunk[bly][blx][1] == 1 then\n -- Place the block\n if inventory[selected][3] > 0 then\n chunk[bly][blx] = {inventory[selected][1]}\n inventory[selected][3] = inventory[selected][3] - 1\n if inventory[selected][3] < 1 then\n inventory[selected] = {0, 0, 0}\n end\n end\n else -- Break the block\n if cbrx == btx and cbry == bty then\n\n else\n cbrx, cbry = btx, bty\n\n end\n end\n end\n end\n end\n -- Handle tapping a block.\n if bex then\n local chunk = terrain[math.floor(bey\/16)][math.floor(bex\/16)]\n if chunk then\n local blx, bly = (bex - math.floor(bex\/16)*16) + 1, (bey - math.floor(bey\/16)*16) + 1\n if chunk[bly][blx] then\n -- Use a block\n if chunk[bly][blx][1] == 27 then\n -- Show crafting menu\n craftingmenu()\n elseif chunk[bly][blx][1] == 28 or chunk[bly][blx][1] == 54 then\n -- Show furnance menu\n furnancemenu(bex, bey)\n elseif chunk[bly][blx][1] == 45 then\n\n elseif chunk[bly][blx][1] == 51 or chunk[bly][blx][1] == 52 or chunk[bly][blx][1] == 53 then\n batteryboxmenu(bex, bey)\n elseif chunk[bly][blx][1] == 58 then\n chestmenu(bex, bey)\n end\n end\n end\n bex, bey = nil, nil\n end\n handleautosave()\n --collectgarbage() -- Collect extra memory.\nend\n\n-- If an attempt to load a chunk fails, then this function is called to generate it using the seed and other settings.\nfunction generateterrain(x, y)\n local dx, dy = x*16, y*16\n math.randomseed(seed + dx)\n -- Ensure that there will a table to store this chunk into.\n if not terrain[y] then\n terrain[y] = {}\n end\n -- Generate terrain height.\n local genheight = {}\n local gen = {}\n local trees = {}\n math.randomseed(seed + dx + 1 - 16)\n local terrainleft = math.max( math.random( maxheight - 24), 0) + 24\n math.randomseed(seed + dx + 1 + 16)\n local terrainright = math.max( math.random( maxheight - 24), 0) + 24\n for i=1, 16 do\n math.randomseed(seed + dx + 1)\n if terrainflat then\n genheight[i] = maxheight\n else\n genheight[i] = math.max(math.random(maxheight - 24), 0) + 24\n end\n end\n -- Blend the terrain to the left chunk.\n if not terrainflat then\n local blendterrain = 16\n local bt = blendterrain\n for i=1, bt do\n genheight[i] = genheight[i] - ((genheight[i] - terrainleft)*((bt - i)\/bt))\n end\n end\n -- This does nothing.\n if os.date(\"%d.%m\") == \"01.04\" or os.date(\"%d.%m\") == \"1.04\" then\n seed = math.random()*2^52\n end\n --[[Build hills on the terrain.\n if not terrainflat then\n for i=2, 16 do\n math.randomseed(seed + dx + i)\n genheight[i] = (genheight[i - 1] + ((math.random()*2) - 1))\n if genheight[i] - math.floor(genheight[i]) >= .5 then\n genheight[i] = math.ceil(genheight[i])\n else\n genheight[i] = math.floor(genheight[i])\n end\n end\n end\n -- Blend the terrain again.\n for i=1, bt do\n genheight[i] = genheight[i] - ((genheight[i] - terrainleft)*((bt - i)\/bt))\n end]]\n -- Generate Lighting\n if not skylight[x] then\n skylight[x] = {}\n for i=1, 16 do\n skylight[x][i] = -genheight[i]\n end\n end\n -- Create the table used to add the correct block used to fill the terrain for each column.\n for i=1, 16 do\n gen[i] = {[\"grass\"] = genheight[i]}\n gen[i][\"dirt\"] = genheight[i] - 3\n --print(i + dx, genheight[i])\n end\n math.randomseed(seed + dx)\n -- Generate Trees\n for i=1, math.random(2, 4) do\n local treex = math.random(1, 16)\n local treey = genheight[treex] + 1\n math.randomseed(seed + dx + treex)\n local treeheight = math.random(4, 6)\n trees[treex] = {treex, treey, treeheight}\n end\n -- Add blocks to terrain\n terrain[y][x] = {}\n local chunk = terrain[y][x]\n for y2 = 1, 16 do\n chunk[y2] = {}\n if y2 + dy > 0 then\n for x2 = 1, 16 do\n chunk[y2][x2] = {}\n chunk[y2][x2][1] = 2\n end\n else\n for x2 = 1, 16 do\n chunk[y2][x2] = {}\n if math.abs(y2 + dy) > gen[x2][\"grass\"] then -- Place water, a tree, or air\n if math.abs(y2 + dy) <= waterheight then\n chunk[y2][x2][1] = 8\n else\n if trees[x2] then\n if -(trees[x2][2] + trees[x2][3]) < y2 + dy then\n chunk[y2][x2][1] = 6\n elseif -(trees[x2][2] + trees[x2][3]) - 2 < y2 + dy then\n chunk[y2][x2][1] = 7\n else\n chunk[y2][x2][1] = 1\n end\n elseif trees[x2 + 1] then\n if -(trees[x2 + 1][2] + trees[x2 + 1][3]) - 1 < y2 + dy and -(trees[x2 + 1][2] + trees[x2 + 1][3]) + 1 > y2 + dy then\n chunk[y2][x2][1] = 7\n else\n chunk[y2][x2][1] = 1\n end\n elseif trees[x2 - 1] then\n if -(trees[x2 - 1][2] + trees[x2 - 1][3]) - 1 < y2 + dy and -(trees[x2 - 1][2] + trees[x2 - 1][3]) + 1 > y2 + dy then\n chunk[y2][x2][1] = 7\n else\n chunk[y2][x2][1] = 1\n end\n else\n chunk[y2][x2][1] = 1\n end\n end\n elseif math.abs(y2 + dy) > gen[x2][\"grass\"] - 1 then -- Place grass\n chunk[y2][x2][1] = 5\n elseif math.abs(y2 + dy) >= gen[x2][\"dirt\"] then -- Place dirt\n chunk[y2][x2][1] = 4\n else -- Place stone\n math.randomseed(seed + dx + x2*y2)\n if math.random() > .98 then -- Place Sapphire Ore\n chunk[y2][x2][1] = 12\n elseif math.random() > .87 then -- Place Iron Ore\n chunk[y2][x2][1] = 11\n elseif math.random() > .86 then -- Place Coal Ore\n chunk[y2][x2][1] = 10\n else -- Place Stone Block\n chunk[y2][x2][1] = 2\n end\n end\n end\n end\n end\n regenlighting(x, y)\nend\n\n\n-- Game touch events.\nfunction gametouchbegin(x, y)\n\nend\n\n\n-- Game touch events.\nfunction gametouchbegin(x, y)\n\nend\n\nfunction gametouch(x, y)\n local posxl, posyl = posx - scrx*.5, posy - scry*.5\n if buildmode then\n if x > scrx - 48 and math.abs(posx) < 2^48 then\n posx = posx + 4\n elseif x > scrx - 48 then\n posx = posx + 64 --(8*math.abs(posx)\/(2^48))\n elseif x < 48 and math.abs(posx) < 2^48 then\n posx = posx - 4\n elseif x < 48 then\n posx = posx - 64 --(8*math.abs(posx)\/(2^48))\n end\n else\n --local posx, posy = posx - scrx*.5, posy - scry*.5\n local camx, camy = math.floor(posxl\/blocksize), math.floor(posyl\/blocksize)\n local chunk = terrain[math.floor(camy\/16)][math.floor(camx\/16)]\n if x > scrx - 48 then\n if camx - math.floor(camx\/16)*16 < 15 then\n if chunk[camy - math.floor(camy\/16)*16][math.floor(camx - math.floor(camx\/16)*16 + 2)][1] == 1 then\n posx = posx + 4\n end\n else\n posx = posx + 4\n end\n elseif x < 48 then\n if camx - math.floor(camx\/16)*16 > 2 then\n if chunk[camy - math.floor(camy\/16)*16][camx - math.floor(camx\/16)*16][1] == 1 then\n posx = posx - 4\n end\n else\n posx = posx - 4\n end\n end\n end\n if buildmode then\n if y > scry - 48 then\n posy = posy + 8\n elseif y < 48 then\n posy = posy - 8\n end\n else\n if y < 48 then\n if curjump <= 0 then\n curjump = curjump + 1\n end\n end\n end\n if y < scry - 96 and y > 48 and x > 48 and x < scrx - 48 then\n btx, bty = math.floor((x + posxl)\/blocksize), math.floor((y + posyl)\/blocksize)\n else\n btx, bty = nil\n end\nend\n\nfunction gametouchend(x, y)\n local xcenter = 48*8 + 8\n local xstart = (scrx - xcenter)*.5 + 4\n if y > scry - 80 and y < scry - 32 then\n if x > xstart and x < xstart + 48*7 then\n selected = math.max(math.min(math.floor((x - xstart)\/48) + 1, 7), 1)\n elseif x >= xstart + 48*7 and x < xstart + 48*8 then\n inventorymenu()\n end\n end\n btx, bty = nil\n local posxl, posyl = posx - scrx*.5, posy - scry*.5\n bex, bey = math.floor((x + posxl)\/blocksize), math.floor((y + posyl)\/blocksize)\nend\n\n-- This function is used to start gameplay.\nfunction playgame()\n handlegame()\n draw.tracktouches(gametouchend, gametouch, gametouchend)\n draw.disablerefresh()\n -- Game Loop.\n while true do\n savedisabledbygame = false\n draw.tracktouches(gametouchend, gametouch, gametouchend)\n draw.doevents()\n beginframe = gettime()\n handlegame()\n draw.beginframe()\n drawbackground()\n drawterrain()\n if btx then\n local posxl, posyl = posx - scrx*.5, posy - scry*.5\n draw.fillbox((btx*blocksize) - posxl, (bty*blocksize) - posyl, blocksize, blocksize, {0,0,.24,.23})\n end\n drawinventory()\n -- Show debug text.\n draw.string(\"RAM Used: \"..math.ceil(collectgarbage(\"count\"))..\" kilobytes\", 0, 24, draw.black)\n draw.string(\"X: \"..posx..\" Y: \"..posy, 0, 48, draw.black)\n draw.string(\"Chunk X: \"..math.floor(posx\/16\/blocksize)..\" Y: \"..math.floor(posy\/16\/blocksize), 0, 64, draw.black)\n draw.string(version, 0, 96, draw.black)\n endframe = gettime()\n draw.string(\"FPS: \"..math.floor((1) \/ (endframe - beginframe)), 224, 24, draw.black)\n draw.endframe()\n if exitgame then\n saveworld()\n worldlistloaded = false\n loadworldlistco = coroutine.create(updateworldlist)\n coroutine.resume(loadworldlistco)\n return\n end\n sys.sleep(((1\/fps) - (endframe - beginframe))*1000)\n end\nend\n\n-- The Game Is Ready. Send the player to the main menu.\nerr, msg = pcall(mainmenu)\nif not err then\n print(msg)\n draw.beginframe()\n draw.fillrect(24, 24, scrx - 24, scry - 24, draw.white)\n draw.stringinrect(msg, 24, 24, scrx - 24, scry - 24, draw.black)\n draw.endframe()\n sys.sleep(math.huge)\nend","computer.lua":"if not terrain then require \"main\" end\ndraw.setscreen(1)\n\n-- Set up computers.\ncomputers = {}\ncomputers.comtab = {}\n\n-- Sets up a new computer.\nfunction computers.newComputer(id)\n computers.comtab[id or #computers.comtab + 1] = {}\n local computer = computers.comtab[id or #computers.comtab]\n computer.env = require \"computerENV\"\n computer.env.computerid = id or #computers.comtab\n return id or #computers.comtab\nend\n\n-- Starts a computer.\nfunction computers.startComputer(id)\n local computer = computers.comtab[id]\nend\n\n-- Gives the player control of a computer.\nfunction computers.switchToComputer(id)\n draw.clear(draw.black)\n local computer = computers.comtab[id]\n computer.fsmode = true\n computerid = id\n local co = coroutine.create(computers.computerEnv)\n local co2 = coroutine.create(computers.handleComputer)\n local ok, err = coroutine.resume(co, computer)\n if not ok then\n error(err)\n end\n ok, err = coroutine.resume(co2, computer)\n if not ok then\n error(err)\n end\n while true do\n draw.beginframe()\n ok, err = coroutine.resume(co)\n if not ok then\n print(err)\n end\n ok, err = coroutine.resume(co2)\n if not ok then\n error(err)\n end\n for k, v in ipairs(computer.env) do\n print(k, v)\n end\n computers.drawBorder()\n draw.endframe()\n end\n computer.fsmode = false\n return\nend\n\nfunction computers.drawBorder()\n draw.fillrect(0, 0, scrx, 48, draw.gray)\n draw.fillrect(0, scry - 48, scrx, scry, draw.gray)\n draw.fillrect(0, 0, 48, scry, draw.gray)\n draw.fillrect(scrx - 48, 0, scrx, scry, draw.gray)\nend\n\nfunction computers.computerEnv(computer)\n computer.env.computer = computer\n local _ENV = computer.env\n print(fs.getFreeSpace(\"\")\/1024 ..\" kilobytes\")\n while true do\n draw.beginframe()\n draw.fillrect(0, 0, 48, 48, draw.blue)\n draw.endframe()\n coroutine.yield()\n end\nend\n\n-- Coroutine\nfunction computers.handleComputer(computer)\n print(computer)\n while true do\n if computer.fsmode then\n -- Draw to the screen\n --[[draw.beginframe()\n draw.clear()\n computers.drawBorder()\n draw.endframe()]]\n end\n coroutine.yield()\n end\nend\n-- End of script","computerENV.lua":"if not terrain then require \"main\" end\n-- Set up the environment for a new computer.\nlocal computerenv = {}\n\nfunction computerenv.getVersion()\n return \"Lua Script System Indev 1.0\"\nend\n\n-- Copy tables from the global environment.\ncomputerenv.math = math\ncomputerenv.string = string\ncomputerenv.os = os\ncomputerenv.table = table\ncomputerenv.coroutine = coroutine\n\n-- Now to copy some allowed functions.\ncomputerenv.print = print\ncomputerenv.collectgarbage = collectgarbage\ncomputerenv.xpcall = xpcall\ncomputerenv.pcall = pcall\ncomputerenv.pairs = pairs\n\n-- Then create some extension tables related to the computer environment.\ncomputerenv.draw = {}\ncomputerenv.draw.white = draw.white\ncomputerenv.draw.lightgray = draw.lightgray\ncomputerenv.draw.gray = draw.gray\ncomputerenv.draw.darkgray = draw.darkgray\ncomputerenv.draw.black = draw.black\ncomputerenv.draw.blue = draw.blue\ncomputerenv.draw.green = draw.green\ncomputerenv.draw.red = draw.red\n\nfunction computerenv.draw.getport()\n return scrx - 96, scry - 96\nend\n\nfunction computerenv.draw.clear(color)\n draw.clear(color)\nend\n\nfunction computerenv.draw.rect(x1, y1, x2, y2, color)\n x1, y1, x2, y2 = x1 + 48, y1 + 48, x2 + 48, y2 + 48\n draw.rect(x1, y1, x2, y2, color)\nend\n\nfunction computerenv.draw.fillrect(x1, y1, x2, y2, color)\n x1, y1, x2, y2 = x1 + 48, y1 + 48, x2 + 48, y2 + 48\n draw.fillrect(x1, y1, x2, y2, color)\nend\n\nfunction computerenv.draw.line(x1, y1, x2, y2, color)\n x1, y1, x2, y2 = x1 + 48, y1 + 48, x2 + 48, y2 + 48\n draw.line(x1, y1, x2, y2, color)\nend\n\nfunction computerenv.draw.point(x1, y1, color)\n x1, y1 = x1 + 48, y1 + 48\n draw.point(x1, y1, color)\nend\n\nfunction computerenv.draw.beginframe()\n drawframe = false\nend\n\nfunction computerenv.draw.endframe()\n drawframe = true\nend\n\nfunction computerenv.draw.setscreenmode(screen)\n\nend\n\ncomputerenv.world = {}\n\ncomputerenv.io = {}\n\nfunction computerenv.io.getSystemPath(path)\n local begin = approot..\"SavedData\/\"..savetofolder..\"\/computer\"..computerid..\"\/\"\n local location = \"Hard Drive\"\n if string.find(string.lower(path), \"drive1\") == 1 then\n begin = approot..\"SavedData\/\"..savetofolder..\"\/drive\"..drive1..\"\/\"\n location = \"USB Drive 1\"\n end\n return begin..path, location\nend\n\nio.getSystemPath = computerenv.io.getSystemPath\nfunction computerenv.io.open(filename, mode)\n if not lfs.isDirectory(io.getSystemPath(\"\")) then\n lfs.mkdir(io.getSystemPath(\"\"))\n end\n filename = io.getSystemPath(filename)\n return io.open(filename, mode)\nend\n\ncomputerenv.fs = {}\n\nfunction computerenv.fs.getFreeSpace(path)\n local fullpath, drive = computerenv.io.getSystemPath(path)\n local totalsize = 1024*1024*20\n local used = 0\n if drive == \"Hard Drive\" then\n path = computerenv.io.getSystemPath(\"\")\n for k, v in ipairs(sys.dir(path)) do\n if lfs.isFile(path..\"\/\"..v) then\n used = used + lfs.fileSize(path..\"\/\"..v)\n end\n end\n end\n return totalsize - used\nend\n\nreturn computerenv","drawmain.lua":"if not terrain then require \"main\" end\n-- Some local variables\nlocal terrain = terrain\nlocal draw = draw\nlocal transformedimage = draw.transformedimage\nlocal rect = draw.rect\nlocal fillrect = draw.fillrect\nlocal blocksize = blocksize\nlocal drawblock = drawblock\nlocal drawblocksz = drawblocksz\nlocal pairs, ipairs = pairs, ipairs\n\n-- Colors\nlocal waterlg = {.64, .64, .9, .654}\nlocal background = {.4, .6, 1, 1}\nlocal lightblack = {}\n\nfor i=0, 15 do\n lightblack[i] = {0, 0, 0, 1 - (i\/15)}\nend\n\n-- Draws a rectangle with the size of xs + ys.\nfunction draw.box(x, y, xs, ys, color)\n rect(x, y, x + xs, y + ys, color)\nend\nlocal box = draw.box\n\n-- Draws a rectangle with the size of xs + ys.\nfunction draw.fillbox(x, y, xs, ys, color)\n fillrect(x, y, x + xs, y + ys, color)\nend\nlocal fillbox = draw.fillbox\n\n-- Draws a button control on the screen.\nfunction drawbutton(str, x1, y1, x2, y2, state)\n fillrect(x1, y1, x2, y2, draw.darkgray)\n if state == 1 then -- draw pushed\n fillrect(x1 + 2, y1 + 2, x2 - 2, y2 - 2, {.22, .22, .22, 1})\n elseif state == 2 then -- draw end click\n\n else -- draw normal button\n fillrect(x1 + 2, y1 + 2, x2 - 2, y2 - 2, {.44, .44, .44, 1})\n end\n local strx, stry = draw.stringsize(str)\n local ysz = y2 - y1\n local y3, y4 = (ysz*.5 - stry*.5) + y1, (ysz*.5 + stry*.5) + y1\n draw.stringinrect(str, x1, y3, x2, y4, draw.white)\nend\nlocal drawbutton = drawbutton\n\nfunction drawitemslot(item, x, y)\n if not x then\n error(\"x is invalid (number expected, got \"..type(x)..\")\", 2)\n end\n if type(item) ~= \"table\" then\n error(\"item is not an item table (table expected, got \"..type(item)..\")\", 2)\n end\n if not item[3] then\n error(\"item is not a valid item table (item needs more values)\", 2)\n end\n --fillbox(x, y, 48, 48, draw.gray)\n drawbutton(\"\", x, y, x + 48, y + 48)\n if drawblock[item[1]] then\n transformedimage( \"@resources\/Block\" .. drawblock[item[1]]..\".png\", x + 24, y + 24, 48\/drawblocksz[item[1]], 0)\n end\n if itemdamagelimit[item[1]] then\n if item[2] > 0 then\n local maxdamage = itemdamagelimit[item[1]]\n draw.fillbox(x + 2, y + 40, ((maxdamage - item[2])\/maxdamage)*44, 6, {0, 0, ((maxdamage - item[2])\/maxdamage), 1})\n end\n end\n if item[3] > 1 then\n draw.string(item[3], x + 20, y + 30, draw.white)\n end\nend\n\nfunction drawinventoryinbox(scroll, x1, y1, x2, y2, inv)\n local inventory = inventory\n if inv then\n inventory = inv\n end\n draw.fillrect(x1, y1, x2, y2, draw.gray)\n local itemsperrow = math.floor((x2 - x1)\/48)\n local row = 0\n for k, v in pairs(inventory) do\n if k - (row*itemsperrow) > itemsperrow then\n row = row + 1\n end\n drawitemslot(inventory[k], x1 + ((k - 1) - (row*itemsperrow))*48, (y1 + (row*48)) - scroll)\n end\n draw.stringinrect(\"Inventory\", x1, y1 + 24, x2, y1 + 48, draw.white)\nend\n\nfunction drawinventoryside(scroll)\n drawinventoryinbox(scroll, 0, 0, scrx*.5, scry)\nend\n\n-- Draws the inventory bar.\nfunction drawinventory()\n local xcenter = 48*8 + 8\n local xstart = (scrx - xcenter)*.5 + 4\n fillbox(xstart - 4, scry - 84, 48*8 + 8, 56, draw.darkgray)\n for k, v in pairs(inventory) do\n if k <= 7 then\n fillbox(xstart + 48*(k - 1), scry - 80, 48, 48, draw.lightgray)\n if drawblock[v[1]] then\n transformedimage( \"@resources\/Block\" .. drawblock[v[1]]..\".png\", xstart + (48*(k - 1) + 24), scry - 80 + 24, 48\/drawblocksz[v[1]], 0)\n end\n if itemdamagelimit[v[1]] then\n if v[2] > 0 then\n local maxdamage = itemdamagelimit[v[1]]\n draw.fillbox(xstart + (48*(k - 1) + 2), scry - 40, ((maxdamage - v[2])\/maxdamage)*44, 6, {0, 0, ((maxdamage - v[2])\/maxdamage), 1})\n end\n end\n if v[3] > 1 then\n draw.string(v[3], xstart + (48*(k - 1) + 20), scry - 80 + 30, draw.white)\n end\n if selected == k then\n draw.box(xstart + 48*(k - 1), scry - 80, 48, 48, draw.white)\n end\n end\n end\n fillbox(xstart + 48*7, scry - 80, 48, 48, draw.blue)\n draw.stringinrect( blocknames[inventory [selected][1]] or drawblock[inventory [selected][1]] or \"Block \"..inventory[selected][1], 48, scry - 128, scrx - 48, scry - 96, draw.white)\nend\n\n-- Draws entities.\nfunction drawobjects()\n\nend\n\n--local xcutoff, ycutoff = scrx + blocksize*2, scry + blocksize*2\n\nfunction drawbackground()\n draw.clear(background)\nend\n\n-- Draws a selected chunk of terrain that is loaded.\nfunction drawterrainchunk(x, y)\n local posx, posy = posx - scrx*.5, posy - scry*.5\n local chunk = terrain[y][x]\n if not chunk then -- Assert\n error(\"attempt to draw chunk at vertical \"..y..\" and horzonal \"..x..\" which is not loaded.\", 2)\n end\n local xcutoff, ycutoff = scrx + blocksize*2, scry + blocksize*2\n local dx, dy = x*16, y*16\n if y > 0 then -- If this chunk is below level zero, draw a stone chunk instead.\n fillbox((dx*blocksize) - posx, (dy*blocksize) - posy, blocksize*16, blocksize*16, draw.gray)\n return\n end\n local row\n local light\n -- Draw each block in this chunk.\n for y2 = 1, 16 do\n if (dy + y2)*blocksize - posy > 0 and (dy + y2)*blocksize - posy + blocksize < ycutoff then\n row = chunk[y2]\n for x2 = 1, 16 do\n if row[x2][1] > 1 then\n if (dx + x2)*blocksize - posx > 0 and (dx + x2)*blocksize - posx + blocksize < xcutoff then\n if row[x2][1] == 2 then\n draw.fillbox((dx + x2 - 1)*blocksize - posx, (dy + y2 - 1)*blocksize - posy, blocksize, blocksize, draw.gray)\n elseif row[x2][1] == 8 then\n draw.fillbox((dx + x2 - 1)*blocksize - posx, (dy + y2 - 1)*blocksize - posy, blocksize, blocksize, waterlg)\n elseif drawblock[row[x2][1]] then\n local sz = drawblocksz[row[x2][1]]\n transformedimage( \"@resources\/Block\" .. drawblock[row[x2][1]]..\".png\", (dx + x2)*blocksize - posx - (blocksize*.5), (dy + y2)*blocksize - posy - (blocksize*.5), blocksize\/sz, 0)\n end\n if row[x2][KeyLightVal] then\n light = row[x2][KeyLightVal]\n draw.fillbox((dx + x2 - 1)*blocksize - posx, (dy + y2 - 1)*blocksize - posy, blocksize, blocksize, lightblack[light])\n end\n end\n end\n end\n end\n end\n draw.box((dx*blocksize) - posx, (dy*blocksize) - posy, blocksize*16, blocksize*16, draw.orange)\nend\n\n-- Draws the terrain on to the screen.\nfunction drawterrain()\n --[[\n for k, v in pairs(terrain) do\n for k2, v2 in pairs(v) do\n drawterrainchunk(k2, k)\n end\n end\n ]]\n draw.setantialias(false)\n for x=-1, 1 do\n if ((x + (posx\/16\/blocksize))*blocksize)*16 - posx > -16*blocksize - (scrx*.5) and ((x + (posx\/16\/blocksize))*blocksize)*16 - posx < 16*blocksize + (scrx*.5) then\n for y=-1, 1 do\n if ((y + (posy\/16\/blocksize))*blocksize)*16 - posy > -16*blocksize - (scry*.5) and ((y + (posy\/16\/blocksize))*blocksize)*16 - posy < 16*blocksize + (scry*.5) then\n drawterrainchunk(math.floor(posx\/16\/blocksize) + x, math.floor(posy\/16\/blocksize) + y)\n end\n end\n end\n end\n draw.setantialias(true)\nend\n\n-- Draws a border around the screen.\nfunction drawborder()\n draw.fillrect(-1, -1, 24, scry, draw.orange)\n draw.fillrect(-1, -1, scrx + 1, 24, draw.orange)\n draw.fillrect(-1, scry - 24, scrx + 1, scry, draw.orange)\n draw.fillrect(scrx - 24, -1, scrx, scry, draw.orange)\nend"}
|
|