Advertisement
billysback

CGE

Oct 8th, 2012
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.53 KB | None | 0 0
  1.  
  2. local map = {}
  3. local sprites = {}
  4. local gravity = {}
  5.  
  6. --CREDIT TO marumaru
  7. function getColor ( mctag )
  8.         if mctag == "&0" then
  9.                 return 32768
  10.         elseif mctag == "&f" then
  11.                 return 1
  12.         elseif mctag == "&e" then
  13.                 return 16
  14.         elseif mctag == "&a" then
  15.                 return colors.lime
  16.         elseif mctag == "&b" then
  17.                 return colors.lightBlue
  18.         elseif mctag == "&c" then
  19.                 return colors.red
  20.         elseif mctag == "&d" then
  21.                 return colors.pink
  22.         elseif mctag == "&1" then
  23.                 return colors.blue
  24.         elseif mctag == "&2" then
  25.                 return colors.green
  26.         elseif mctag == "&3" then
  27.                 return colors.cyan
  28.         elseif mctag == "&4" then
  29.                 return colors.red
  30.         elseif mctag == "&5" then
  31.                 return colors.purple
  32.         elseif mctag == "&6" then
  33.                 return colors.orange
  34.         elseif mctag == "&7" then
  35.                 return colors.lightGray
  36.         elseif mctag == "&8" then
  37.                 return colors.gray
  38.         elseif mctag == "&9" then
  39.                 return colors.cyan
  40.         else
  41.                 return 1
  42.         end
  43. end
  44.  
  45. -- CREIDT TO marumaru
  46. function setPixel ( pix, piy, mcTag )
  47.         oldx, oldy = term.getCursorPos()
  48.         term.setCursorPos(pix,piy)
  49.         term.setBackgroundColor(getColor(mcTag))
  50.         write(" ")
  51.         term.setBackgroundColor(getColor("&0"))
  52.         term.setCursorPos(oldx,oldy)
  53. end
  54.  
  55. function getLines(dir)
  56.     if fs.exists(dir) then
  57.         local lines = {}
  58.         local cur = 1
  59.         local file = fs.open(dir, "r")
  60.         local line = file.readLine()
  61.         while line ~= nil do
  62.             lines[cur] = line
  63.             line = file.readLine()
  64.         end
  65.         file.close()
  66.         return lines
  67.     else
  68.         return nil
  69.     end
  70. end
  71.  
  72. function split(str, pat)
  73.     local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  74.     if str ~= nil then
  75.        local fpat = "(.-)" .. pat
  76.        local last_end = 1
  77.        local s, e, cap = str:find(fpat, 1)
  78.        while s do
  79.           if s ~= 1 or cap ~= "" then
  80.          table.insert(t,cap)
  81.           end
  82.           last_end = e+1
  83.           s, e, cap = str:find(fpat, last_end)
  84.        end
  85.        if last_end <= #str then
  86.           cap = str:sub(last_end)
  87.           table.insert(t, cap)
  88.        end
  89.     else
  90.         print("##CGE ERROR failed to split ["..str.."] by:"..pat)
  91.     end
  92.     return t
  93. end
  94.  
  95. function getTableSize(table)
  96.     local cur = 0
  97.     for i,v in ipairs(table) do
  98.         cur = i
  99.     end
  100.     return cur
  101. end
  102.  
  103. function addGravity(x, y, force)
  104.     gravity[(#gravity)+1] = x..","..y..","..force
  105. end
  106.  
  107. function removeGravity(grav)
  108.     local splt = split(grav, ",")
  109.     removeGravity(tonumber(splt[1]), tonumber(splt[2]), tonumber(splt[3]))
  110. end
  111.  
  112. function removeGravity(x, y, force)
  113.     local ngravity = {}
  114.     local cur = 1
  115.     for i,v in ipairs(gravity) do
  116.         if v == x..","..y then else
  117.             ngravity[cur] = v
  118.             cur = cur + 1
  119.         end
  120.     end
  121. end
  122.  
  123. function getGravityPoints()
  124.     return gravity
  125. end
  126.  
  127. function updateGravity(sprite, smart)
  128.     local nsprite = {}
  129.     local cur = 1
  130.     local ok = true
  131.     for j,k in ipairs(sprite) do
  132.         local splt = split(v, ":")
  133.         local x = splt[1]
  134.         local y = splt[2]
  135.         local type = splt[3]
  136.         local name = splt[4]
  137.         local maxani = splt[5]
  138.         local curani = splt[6]
  139.         local curv = splt[7]
  140.         for i,v in ipairs(gravity) do
  141.             local splt2 = split(v, ",")
  142.             local px = tonumber(splt2[1])
  143.             local py = tonumber(splt2[2])
  144.             local force = tonumber(splt2[3])
  145.             local distx = 0
  146.             local disty = 0
  147.             if px < x then distx = x - px else distx = px - x end
  148.             if py < y then disty = y - py else disty = py - y end
  149.             if (distx + disty)/2 <= force and ok then
  150.                 local xdif = 0
  151.                 local ydif = 0
  152.                 if px < x then xdif = -1 else xdif = 1 end
  153.                 if py < y then ydif = -1 else ydif = 1 end
  154.                 x = x + xdif
  155.                 y = y + ydif
  156.             else
  157.                 if ok then else
  158.                     ok = false
  159.                 end
  160.             end
  161.         end
  162.         nsprite[cur] = (x)..":"..(y)..":"..type..":"..name..":"..maxani..":"..curani..":"..curv
  163.         cur = cur + 1
  164.     end
  165.    
  166.     if checkCollision(nsprite, sprites) and smart then
  167.         nsprite = sprite
  168.     end
  169.    
  170.     if ok then else
  171.         nsprite = sprite
  172.     end
  173.     return nsprite
  174. end
  175.  
  176. function readMap(dir)
  177.     local lines = getLines(dir)
  178.     local map = nil
  179.     if lines ~= nil then
  180.         map = constructMap(lines)
  181.     end
  182.     return map
  183. end
  184.  
  185. function readSprite(sx, sy, dir, name, maxani, colored)
  186.     local plines = getLines(dir)
  187.     local lines = {}
  188.     local lcur = 1
  189.     for i,v in ipairs(plines) do
  190.         if colored then
  191.             local nnline = string.gsub(v, "&", "")
  192.             lines[lcur] = string.gsub(nnline, " ", "")
  193.         else
  194.             lines[lcur] = v
  195.         end
  196.         lcur = lcur + 1
  197.     end
  198.     local nsprite = {}
  199.     local cur = 1
  200.     if lines ~= nil then
  201.         for i,v in ipairs(lines) do
  202.             local y = i
  203.             local line = v
  204.             for x=1,string.len(line),1 do
  205.                 local type = string.sub(line, x, x)
  206.                 if colored then type = "&"..type end
  207.                 if type ~= " " then
  208.                     nsprite[cur] = (sx+x)..":"..(sy+y)..":"..type..":"..name..":"..maxani..":"..(1)..":".."0,0,0"
  209.                     cur = cur + 1
  210.                 end
  211.             end
  212.         end
  213.     end
  214.     return nsprite
  215. end
  216.  
  217. function readAnimatedSprite(sx, sy, dirs, name, maxani, colored)
  218.     local xtable = {}
  219.     local ytable = {}
  220.     local ttable = {}
  221.     for i,v in ipairs(dirs) do
  222.         local cur = 1
  223.         local plines = getLines(v)
  224.         local lines = {}
  225.         local lcur = 1
  226.         for i,v in ipairs(plines) do
  227.             if colored then
  228.                 local nnline = string.gsub(v, "&", "")
  229.                 lines[lcur] = string.gsub(nnline, " ", "")
  230.             else
  231.                 lines[lcur] = v
  232.             end
  233.             lcur = lcur + 1
  234.         end
  235.         if lines ~= nil then
  236.             for j,k in ipairs(lines) do
  237.                 local y = j
  238.                 for x=1,#lines,1 do
  239.                     if xtable[cur] == nil then xtable[cur] = x+sx end
  240.                     if ytable[cur] == nil then ytable[cur] = y+sy end
  241.                     local type = string.sub(k, x, x)
  242.                     if colored then type = "&"..type end
  243.                     if ttable[cur] == nil then
  244.                         ttable[cur] = type
  245.                     else
  246.                         ttable[cur] = ttable[cur]..","..type
  247.                     end
  248.                 end
  249.                 cur = cur + 1
  250.             end
  251.         end
  252.     end
  253.     return createSprite(xtable, ytable, ttable, name, maxani)
  254. end
  255.  
  256. function constructMap(mtable)
  257.     local nmap = {}
  258.     local cur = 1
  259.     for i,v in ipairs(mtable) do
  260.         local y = i
  261.         local line = v
  262.         for x=1,string.len(line),1 do
  263.             local type = string.sub(line, x, x)
  264.             nmap[cur] = x..":"..y..":"..type
  265.             cur = cur + 1
  266.         end
  267.     end
  268.     return nmap
  269. end
  270.  
  271. function constructSprite(sx, sy, stable, name, maxani)
  272.     if maxani == nil then maxani = 1 end
  273.     local nsprite = {}
  274.     local cur = 1
  275.     for i,v in ipairs(stable) do
  276.         local y = i
  277.         local line = v
  278.         for x=1,string.len(line),1 do
  279.             local type = string.sub(line, x, x)
  280.             if type ~= " " then
  281.                 nsprite[cur] = (sx+x)..":"..(sy+y)..":"..type..":"..name..":"..maxani..":"..(1)..":".."0,0,0"
  282.                 cur = cur + 1
  283.             end
  284.         end
  285.     end
  286.     return nsprite
  287. end
  288.  
  289. function createSprite(xtable, ytable, ttable, name, maxani)
  290.     if maxani == nil then maxani = 1 end
  291.     local sprite = nil
  292.     local xsz = getTableSize(xtable)
  293.     local ysz = getTableSize(ytable)
  294.     local tsz = getTableSize(ttable)
  295.     if xsz == ysz and xsz == tsz then
  296.         local i = 1
  297.         local cur = 1
  298.         sprite = {}
  299.         for i=1,xsz,1 do
  300.             sprite[cur] = (xtable[i])..":"..(ytable[i])..":"..(ttable[i])..":"..name..":"..maxani..":"..(1)..":".."0,0,0"
  301.             cur = cur + 1
  302.         end
  303.     end
  304.     return sprite
  305. end
  306.  
  307. function changeSprite(sprite, nsprite)
  308.     if sprite ~= nsprite then
  309.         local nsprites = sprites
  310.         for i,v in ipairs(sprites) do
  311.             if v == sprite then
  312.                 nsprites[i] = nsprite
  313.             end
  314.         end
  315.         sprites = nsprites
  316.     end
  317. end
  318.  
  319. function getSpriteCode(sprite)
  320.     local line = ""
  321.     for i,v in ipairs(sprite) do
  322.         if i == 1 then
  323.             line = v
  324.         else
  325.             line = line.."#~#"..v
  326.         end
  327.     end
  328.     return line
  329. end
  330.  
  331. function readSpriteCode(code)
  332.     local nsprite = {}
  333.     local cur = 1
  334.     local splt = split(code, "#~#")
  335.     for i,v in ipairs(splt) do
  336.         nsprite[cur] = v
  337.         cur = cur + 1
  338.     end
  339.     return nsprite
  340. end
  341.  
  342. function addSprite(sprite)
  343.     local sz = getTableSize(sprites)
  344.     sprites[sz+1] = sprite
  345. end
  346.  
  347. function deleteSprite(sprite)
  348.     local nsprites = {}
  349.     for i,v in ipairs(sprites) do
  350.         if v == sprite then else
  351.             nsprites[i] = v
  352.         end
  353.     end
  354.     sprites = nsprites
  355. end
  356.  
  357. function getSprites()
  358.     return sprites
  359. end
  360.  
  361. function addSprites(nsprites)
  362.     local sz = getTableSize(sprites)
  363.     for i,v in ipairs(nsprites) do
  364.         sprites[sz+1] = v
  365.         sz = sz + 1
  366.     end
  367. end
  368.  
  369. function setSprites(nsprites)
  370.     sprites = nsprites
  371. end
  372.  
  373. function getMap()
  374.     return map
  375. end
  376.  
  377. function setMap(nmap)
  378.     map = nmap
  379. end
  380.  
  381. function setMapLoc(x, y, type)
  382.     for i,v in ipairs(map) do
  383.         local splt = split(v, ":")
  384.         local cx = splt[1]
  385.         local cy = splt[2]
  386.         local ctype = splt[3]
  387.         if cx == x and cy == y then
  388.             map[i] = x..":"..y..":"..type
  389.         end
  390.     end
  391. end
  392.  
  393. function getSpriteBounds(sprite)
  394.     local upx = -1
  395.     local upy = -1
  396.     local downx = -1
  397.     local downy = -1
  398.     for i,v in ipairs(sprite) do
  399.         local splt = split(v, ":")
  400.         local x = splt[1]
  401.         local y = splt[2]
  402.         if upx == -1 then upx = x else
  403.             if x > upx then upx = x end
  404.         end
  405.         if upy == -1 then upy = y else
  406.             if y > upx then upy = y end
  407.         end
  408.         if downx == -1 then downx = x else
  409.             if x > downx then downx = x end
  410.         end
  411.         if downy == -1 then downy = y else
  412.             if y > downy then downy = y end
  413.         end
  414.     end
  415.     return {upx, upy, downx, downy}
  416. end
  417.  
  418. function flipSprite(sprite, flipx, flipy)
  419.     local nsprite = {}
  420.     local cur = 1
  421.     local bounds = getSpriteBounds(sprite)
  422.     for i,v in ipairs(sprite) do
  423.         local splt = split(v, ":")
  424.         local x = splt[1]
  425.         local y = splt[2]
  426.         local type = splt[3]
  427.         local name = splt[4]
  428.         local maxani = splt[5]
  429.         local curani = splt[6]
  430.         local curv = splt[7]
  431.        
  432.         if flipx and bounds[1] ~= -1 and bounds[3] ~= -1 then
  433.             local difx = x-bounds[1]
  434.             local difx2 = bounds[3]-bounds[1]
  435.             local nx = difx2-difx
  436.             x = nx+bounds[1]
  437.         end
  438.         if flipy and bounds[2] ~= -1 and bounds[4] ~= -1 then
  439.             local dify = y-bounds[2]
  440.             local dify2 = bounds[4]-bounds[2]
  441.             local ny = dify2-dify
  442.             y = ny+bounds[2]
  443.         end
  444.         nsprite[cur] = (x)..":"..(y)..":"..type..":"..name..":"..maxani..":"..curani..":"..curv
  445.         cur = cur + 1
  446.     end
  447.    
  448.     return nsprite
  449. end
  450.  
  451. function getSprite(name)
  452.     local csprite = nil
  453.     for i,v in ipairs(sprites) do
  454.         local sprite = v
  455.         for j,k in ipairs(sprite) do
  456.             local splt = split(k, ":")
  457.             local cname = splt[4]
  458.             if cname == name and csprite == nil then
  459.                 csprite = sprite
  460.             end
  461.         end
  462.     end
  463.     return csprite
  464. end
  465.  
  466. function moveSprite(sprite, dirx, diry, smart)
  467.     local bkup = sprite
  468.     local nsprite = {}
  469.     local cur = 1
  470.     for i,v in ipairs(sprite) do
  471.         local splt = split(v, ":")
  472.         local x = splt[1]
  473.         local y = splt[2]
  474.         local type = splt[3]
  475.         local name = splt[4]
  476.         local maxani = splt[5]
  477.         local curani = splt[6]
  478.         local curv = splt[7]
  479.         nsprite[cur] = (x+dirx)..":"..(y+diry)..":"..type..":"..name..":"..maxani..":"..curani..":"..curv
  480.         cur = cur + 1
  481.     end
  482.    
  483.     if smart then
  484.         local checksprites = sprites
  485.         for i,v in ipairs(sprites) do
  486.             if v == sprites then else
  487.                 checksprites[i] = v
  488.             end
  489.         end
  490.         if checkCollision(nsprite, checksprites) then
  491.             nsprite = bkup
  492.         end
  493.     end
  494.    
  495.     return nsprite
  496. end
  497.  
  498. function getCollision(sprite, sprites)
  499.         for i,v in ipairs(sprites) do
  500.         local cursprite = v
  501.         if cursprite ~= sprite then
  502.             for k,j in ipairs(cursprite) do
  503.                 local splt1 = split(j, ":")
  504.                 local cx = splt1[1]
  505.                 local cy = splt1[2]
  506.                 local tsplt = split(splt1[3], ",")
  507.                 local ctype = tsplt[tonumber(splt1[6])]
  508.                
  509.                 for m,n in ipairs(sprite) do
  510.                     local splt2 = split(n, ":")
  511.                     local sx = splt2[1]
  512.                     local sy = splt2[2]
  513.                     local stsplt = split(splt2[3], ",")
  514.                     local stype = stsplt[tonumber(splt2[6])]
  515.                     if sx == cx and sy == cy then
  516.                         if ctype == " " or stype == " " then else
  517.                             return cursprite
  518.                         end
  519.                     end
  520.                 end
  521.             end
  522.         end
  523.     end
  524.     return nil
  525. end
  526.  
  527. function checkCollision(sprite, sprites)
  528.     for i,v in ipairs(sprites) do
  529.         local cursprite = v
  530.         if cursprite ~= sprite then
  531.             for k,j in ipairs(cursprite) do
  532.                 local splt1 = split(j, ":")
  533.                 local cx = splt1[1]
  534.                 local cy = splt1[2]
  535.                 local tsplt = split(splt1[3], ",")
  536.                 local ctype = tsplt[tonumber(splt1[6])]
  537.                
  538.                 for m,n in ipairs(sprite) do
  539.                     local splt2 = split(n, ":")
  540.                     local sx = splt2[1]
  541.                     local sy = splt2[2]
  542.                     local stsplt = split(splt2[3], ",")
  543.                     local stype = stsplt[tonumber(splt2[6])]
  544.                     if sx == cx and sy == cy then
  545.                         if ctype == " " or stype == " " then else
  546.                             return true
  547.                         end
  548.                     end
  549.                 end
  550.             end
  551.         end
  552.     end
  553.     return false
  554. end
  555.  
  556. function setVelocity(sprite, dir, momentum)
  557.     local nsprite = sprite
  558.     local cur = 1
  559.     for i,v in ipairs(sprite) do
  560.         local splt = split(v, ":")
  561.         local x = tonumber(splt[1])
  562.         local y = tonumber(splt[2])
  563.         local type = splt[3]
  564.         local name = splt[4]
  565.         local maxani = tonumber(splt[5])
  566.         local curani = tonumber(splt[6])
  567.         local curv = momentum
  568.         for i,v in ipairs(dir) do
  569.             curv = curv..","..v
  570.         end
  571.         nsprite[cur] = (x)..":"..(y)..":"..type..":"..name..":"..maxani..":"..curani..":"..curv
  572.     end
  573.     return nsprite
  574. end
  575.  
  576. function getVelocity(sprite)
  577.     local sz = getTableSize(sprite)
  578.     local curv = nil
  579.     if sz > 0 then
  580.         local cplt = split(sprite[1], ":")
  581.         if cplt ~= nil then
  582.             curv = cplt[7]
  583.         end
  584.     end
  585.     return curv
  586. end
  587.  
  588. function updateVelocity(sprite, resistance, smart)
  589.     local bkup = sprite
  590.     local nsprite = {}
  591.     local cur = 1
  592.     for i,v in ipairs(sprite) do
  593.         local splt = split(v, ":")
  594.         local x = tonumber(splt[1])
  595.         local y = tonumber(splt[2])
  596.         local type = splt[3]
  597.         local name = splt[4]
  598.         local maxani = tonumber(splt[5])
  599.         local curani = tonumber(splt[6])
  600.         local curv = splt[7]
  601.         local splt2 = split(curv, ",")
  602.         local mom = tonumber(splt2[1])
  603.         local res = 0
  604.         local dir = {tonumber(splt2[2]), tonumber(splt2[3])}
  605.         if mom > 0 then res = 1 end
  606.         x = x + (res*dir[1])
  607.         y = y + (res*dir[2])
  608.         if mom > 0 then
  609.             mom = mom - resistance
  610.         end
  611.         curv = mom..","..dir[1]..","..dir[2]
  612.         nsprite[cur] = (x)..":"..(y)..":"..type..":"..name..":"..maxani..":"..curani..":"..curv
  613.         cur = cur + 1
  614.     end
  615.    
  616.     if smart then
  617.         local checksprites = sprites
  618.         for i,v in ipairs(sprites) do
  619.             if v == sprite then else
  620.                 checksprites[i] = v
  621.             end
  622.         end
  623.         if checkCollision(nsprite, checksprites) then
  624.             nsprite = bkup
  625.         end
  626.     end
  627.     if nsprite == {} or nsprite == nil then nsprite = bkup end
  628.     return nsprite
  629. end
  630.  
  631. function getCurAnimation(sprite)
  632.     local sz = getTableSize(sprite)
  633.     local curani = -1
  634.     if sz > 0 then
  635.         local cplt = split(sprite[1], ":")
  636.         if cplt ~= nil then
  637.             curani = splt[6]
  638.         end
  639.     end
  640.     return curani
  641. end
  642.  
  643. function animateSprite(sprite, forwards)
  644.     local nsprite = sprite
  645.     local cur = 1
  646.     for i,v in ipairs(sprite) do
  647.         local splt = split(v, ":")
  648.         local x = tonumber(splt[1])
  649.         local y = tonumber(splt[2])
  650.         local type = splt[3]
  651.         local name = splt[4]
  652.         local maxani = tonumber(splt[5])
  653.         local curani = tonumber(splt[6])
  654.         local curv = splt[7]
  655.         if forwards then
  656.             curani = curani + 1
  657.         else
  658.             curani = curani - 1
  659.         end
  660.         if curani > maxani then
  661.             curani = 1
  662.         elseif curani < 1 then
  663.             curani = maxani
  664.         end
  665.        
  666.         nsprite[cur] = (x)..":"..(y)..":"..type..":"..name..":"..maxani..":"..curani..":"..curv
  667.         cur = cur + 1
  668.     end
  669.     return nsprite
  670. end
  671.  
  672. function animateSprites(sprites, forwards)
  673.     local nsprites = sprites
  674.     local cur = 1
  675.     for i,v in ipairs(sprites) do
  676.         local nsprite = animateSprite(v, forwards)
  677.         if nsprite ~= nil then
  678.             nsprites[cur] = nsprite
  679.             cur = cur + 1
  680.         end
  681.     end
  682.     return nsprites
  683. end
  684.  
  685.  
  686.  
  687. function setSpriteAnimationFrame(sprite, frame)
  688.     local nsprite = sprite
  689.     local cur = 1
  690.     for i,v in ipairs(sprite) do
  691.         local splt = split(v, ":")
  692.         local x = tonumber(splt[1])
  693.         local y = tonumber(splt[2])
  694.         local type = splt[3]
  695.         local name = splt[4]
  696.         local maxani = tonumber(splt[5])
  697.         local curv = splt[7]
  698.         local curani = frame
  699.         if curani > maxani then
  700.             curani = 1
  701.         elseif curani < 1 then
  702.             curani = maxani
  703.         end
  704.        
  705.         nsprite[cur] = (x)..":"..(y)..":"..type..":"..name..":"..maxani..":"..curani..":"..curv
  706.         cur = cur + 1
  707.     end
  708.     return nsprite
  709. end
  710.  
  711.  
  712.  
  713. function draw(offx, offy)
  714.     local positions = {}
  715.     local curp = 1
  716.     for i,v in ipairs(map) do
  717.         local splt = split(v, ":")
  718.         local x = splt[1]
  719.         local y = splt[2]
  720.         local type = splt[3]
  721.         local isok = true
  722.         --for j, k in ipairs(positions) do
  723.         --  local splt2 = split(k, ":")
  724.         --  local cx = splt2[1]
  725.         --  local cy = splt2[2]
  726.         --  if cx == x and cy == y then
  727.         --      isok = false
  728.         --  end
  729.         --end
  730.         if isok then
  731.             term.setCursorPos(offx+x, offy+y)
  732.             term.write(type)
  733.         end
  734.     end
  735.     for m,n in ipairs(sprites) do
  736.         local sprite = n
  737.         for j,k in ipairs(sprite) do
  738.             local splt = split(k, ":")
  739.             local x = splt[1]
  740.             local y = splt[2]
  741.            
  742.             local tsplt = split(splt[3], ",")
  743.             local curani = tonumber(splt[6])
  744.             local type = tsplt[curani]
  745.             local isok = true
  746. --          for i, v in ipairs(positions) do
  747. --              local splt2 = split(v, ":")
  748. --              local cx = splt2[1]
  749. --              local cy = splt2[2]
  750. --              if cx == x and cy == y then
  751. --                  isok = false
  752. --              end
  753. --          end
  754.             if isok and type ~= nil and type ~= " " then
  755.                 term.setCursorPos(offx+x, offy+y)
  756.                 term.write(type)
  757.                 positions[curp] = x..":"..y
  758.                 curp = curp + 1
  759.             end
  760.         end
  761.     end
  762. end
  763.  
  764. function colorDraw(offx, offy)
  765.     local positions = {}
  766.     local curp = 1
  767.     for i,v in ipairs(map) do
  768.         local splt = split(v, ":")
  769.         local x = splt[1]
  770.         local y = splt[2]
  771.         local type = splt[3]
  772.         local isok = true
  773.         --for j, k in ipairs(positions) do
  774.         --  local splt2 = split(k, ":")
  775.         --  local cx = splt2[1]
  776.         --  local cy = splt2[2]
  777.         --  if cx == x and cy == y then
  778.         --      isok = false
  779.         --  end
  780.         --end
  781.         if isok then
  782.             if string.sub(type, 1, 1) == "&" and string.len(type) > 1 then
  783.                 setPixel(offx+x, offy+y, type)
  784.             else
  785.                 term.setCursorPos(offx+x, offy+y)
  786.                 term.write(type)
  787.             end
  788.         end
  789.     end
  790.     for m,n in ipairs(sprites) do
  791.         local sprite = n
  792.         for j,k in ipairs(sprite) do
  793.             local splt = split(k, ":")
  794.             local x = splt[1]
  795.             local y = splt[2]
  796.            
  797.             local tsplt = split(splt[3], ",")
  798.             local curani = tonumber(splt[6])
  799.             local type = tsplt[curani]
  800.             local isok = true
  801. --          for i, v in ipairs(positions) do
  802. --              local splt2 = split(v, ":")
  803. --              local cx = splt2[1]
  804. --              local cy = splt2[2]
  805. --              if cx == x and cy == y then
  806. --                  isok = false
  807. --              end
  808. --          end
  809.             if isok and type ~= nil and type ~= " " then
  810.                 if string.sub(type, 1, 1) == "&" and string.len(type) > 1 then
  811.                     setPixel(offx+x, offy+y, type)
  812.                 else
  813.                     term.setCursorPos(offx+x, offy+y)
  814.                     term.write(type)
  815.                     positions[curp] = x..":"..y
  816.                     curp = curp + 1
  817.                 end
  818.             end
  819.         end
  820.     end
  821. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement