Advertisement
nitrogenfingers

snakemaze

Aug 23rd, 2014
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 33.92 KB | None | 0 0
  1. --[[
  2.     Snake Maze
  3.     Inspired by Snake, Snake's Alive and a few other simple games.
  4.    
  5.     Navigate the maze searching for bird eggs, then head to the exit
  6.    
  7.     Written By: Nitrogen Fingers
  8. ]]--
  9.  
  10. local w,h = term.getSize()
  11.  
  12. local map = { }
  13. local scenew,sceneh = 51, 18
  14. local currx, curry = 1, 1
  15. local levelname = 'level.nfp'
  16.  
  17. local start = { mx = 1, my = 1, x = 5, y = 5 }
  18.  
  19. local snake = { }
  20. local addSegments = 8
  21. local score = 0
  22. local snakefx = 1
  23. local snakefy = 0
  24.  
  25. local energy = 1000
  26. local tflip = 1
  27.  
  28. local fb = 0
  29. local flaming = false
  30. local fbcx,fbcy = 0,0
  31. local fbx,fby = 0,0
  32.  
  33. local baseTimer = 0.25
  34. local timerLength = 0.2
  35. local timerID = -1
  36. local gameOver = false
  37. local exiting = false
  38. local paused = false
  39.  
  40. local showScores = false
  41. local inSplash = false
  42.  
  43. local bgfmin = 8
  44. local bgfmax = 25
  45. local bgnext = 0
  46.  
  47. local eggtotal = 0
  48. local eggcount = 0
  49.  
  50. local shfmin = 50
  51. local shfmax = 100
  52. local shnext = 0
  53.  
  54. local regex = "^"
  55.  
  56. --some display consts.
  57. local scw, sch = 34, 14
  58. local scxoff,scyoff = math.floor(w/2 - scw/2), math.floor(h/2 - sch/2)+1
  59.  
  60. local hs = {}
  61.  
  62. local sncol = {
  63.     {
  64.         index = 1,
  65.         body = colours.lime,
  66.         scales = colours.green,
  67.         eyes = colours.red
  68.     },
  69.     {
  70.         index = 2,
  71.         body = colours.cyan,
  72.         scales = colours.blue,
  73.         eyes = colours.red
  74.     },
  75.     {
  76.         index = 3,
  77.         body = colours.pink,
  78.         scales = colours.purple,
  79.         eyes = colours.red
  80.     },
  81.     {
  82.         index = 4,
  83.         body = colours.lightGrey,
  84.         scales = colours.grey,
  85.         eyes = colours.black
  86.     },
  87.     {
  88.         index = 5,
  89.         body = colours.white,
  90.         scales = colours.black,
  91.         eyes = colours.black
  92.     }
  93. }
  94. local selcol = sncol[math.random(1,3)]
  95. if not term.isColour() then selcol = sncol[5] end
  96.  
  97. local function setBG(col, bwcol)
  98.     if term.isColour() then
  99.         term.setBackgroundColour(col)
  100.     else
  101.         term.setBackgroundColour(bwcol)
  102.     end
  103. end
  104.  
  105. local function setTX(col, bwcol)
  106.     if term.isColour() then
  107.         term.setTextColour(col)
  108.     else
  109.         term.setTextColour(bwcol)
  110.     end
  111. end
  112.  
  113. local function drawFooter()
  114.     term.setCursorPos(3, h)
  115.     setBG(colours.blue, colours.black)
  116.     setTX(colours.white, colours.white)
  117.     term.clearLine()
  118.     term.write("Energy: ")
  119.     if energy > 800 then setTX(colours.green, colours.white)
  120.     elseif energy > 600 then setTX(colours.yellow, colours.white)
  121.     elseif energy > 400 then setTX(colours.orange, colours.white)
  122.     elseif energy > 200 or tflip == 1 then setTX(colours.red, colours.white)
  123.     end
  124.     pzero = ''
  125.     if energy % 10 == 0 then pzero = '.0' end
  126.     term.write((energy / 10)..pzero.."%")
  127.     tflip = (tflip + 1) % 2
  128.     setTX(colours.white, colours.white)
  129.     term.setCursorPos(21, h)
  130.     term.write("Score: "..score.."    ")
  131.     setTX(colours.yellow, colours.white)
  132.     term.setCursorPos(w-15, h)
  133.     term.write("Eggs: ")
  134.     setTX(colours.white, colours.white)
  135.     term.write(eggcount.."/"..eggtotal)
  136. end
  137.  
  138. local function drawSegment(i)
  139.     if i == 1 and exiting then return end
  140.     local v = snake[i]
  141.     if inSplash and showScores and v.x > scxoff-1 and v.x <= scxoff + scw - 1 and
  142.         v.y > scyoff - 1 and v.y <= scyoff + sch - 1 then return end
  143.    
  144.     term.setCursorPos(v.x, v.y)
  145.     if energy <= 0 then selcol = sncol[4] end
  146.     term.setBackgroundColour(selcol.body)
  147.     local schar = ' '
  148.     if i == 1 then
  149.         term.setTextColour(selcol.eyes)
  150.         if fb > 0 then setBG(colours.orange, selcol.body) end
  151.         if gameOver then
  152.             if snakefx > 0 then schar = 'X'
  153.             else schar = '*' end
  154.         elseif snakefx == 1 then schar = ':'
  155.         elseif snakefx == -1 then schar = ':'
  156.         elseif snakefy == 1 then schar = '_'
  157.         elseif snakefy == -1 then schar = '^'
  158.         end
  159.     elseif i < #snake then
  160.         vdx = snake[i-1].x - snake[i+1].x
  161.         vdy = snake[i-1].y - snake[i+1].y
  162.         term.setTextColour(selcol.scales)
  163.         if math.abs(vdx) == 2 then schar = '-'
  164.         elseif math.abs(vdy) == 2 then schar = '|'
  165.         elseif vdx == vdy then schar = '\\'
  166.         else schar = '/'
  167.         end
  168.     else
  169.         vb = snake[i-1]
  170.         term.setTextColour(selcol.scales)
  171.         if math.abs(vb.x - v.x) == 1 then schar = '-'
  172.         elseif math.abs(vb.y - v.y) == 1 then schar = '|' end
  173.     end
  174.     term.write(schar)
  175. end
  176.  
  177. local function drawSnake()
  178.     for i = 1, #snake do
  179.         drawSegment(i)
  180.     end
  181. end
  182.  
  183. local function updateMap(mx, my, x, y)
  184.     if mx ~= currx or my ~= curry then return end
  185.     local scene = map[my][mx]
  186.     for i,v in ipairs(snake) do
  187.         if v.mx == mx and v.my == my and v.x == x and v.y == y then
  188.             drawSegment(i)
  189.             return
  190.         end
  191.     end
  192.    
  193.     local val = scene[y][x]
  194.     term.setCursorPos(x, y)
  195.     if val == nil then
  196.         setBG(colours.grey, colours.black)
  197.         term.write(' ')
  198.     elseif val == 0 then
  199.         setBG(colours.lightGrey, colours.white)
  200.         term.write(" ")
  201.     elseif val == 1 then
  202.         setBG(colours.yellow, colours.white)
  203.         term.write(" ")
  204.     elseif val == 2 then
  205.         setBG(colours.orange, colours.white)
  206.         term.write(" ")
  207.     elseif val == 3 then
  208.         setBG(colours.red, colours.white)
  209.         term.write(" ")
  210.     elseif val == 'e' then
  211.         setBG(colours.grey, colours.black)
  212.         setTX(colours.yellow, colours.white)
  213.         term.write("0")
  214.     elseif val == 't' then
  215.         setBG(colours.grey, colours.black)
  216.         setTX(colours.purple, colours.white)
  217.         term.write(string.char(166))
  218.     elseif val == 'b' then
  219.         setBG(colours.grey, colours.black)
  220.         setTX(colours.green, colours.white)
  221.         term.write('*')
  222.     elseif val == 'B' then
  223.         setBG(colours.grey, colours.black)
  224.         setTX(colours.orange, colours.white)
  225.         term.write('+')
  226.     elseif val == 'X' then
  227.         setBG(colours.grey, colours.black)
  228.         setTX(colours.blue, colours.white)
  229.         term.write('@')
  230.     elseif val == 'F' then
  231.         setBG(colours.grey, colours.black)
  232.         setTX(colours.red, colours.white)
  233.         term.write('&')
  234.     elseif val == '@' and eggcount == eggtotal then
  235.         setBG(colours.blue, colours.white)
  236.         setTX(colours.lightBlue, colours.black)
  237.         term.write('@')
  238.     end
  239. end
  240.  
  241. local function updateFire()
  242.     local fcy, fcx = curry, currx
  243.     local scene = map[fcy][fcx]
  244.     setBG(colours.black, colours.black)
  245.     setTX(colours.white, colours.white)
  246.     if snakefx ~= 0 then
  247.         local ffx = snake[1].x + snakefx
  248.         while map[fcy] and map[fcy][fcx] and type(map[fcy][fcx][snake[1].y][ffx]) ~= "number" do
  249.             map[fcy][fcx][snake[1].y][ffx] = nil
  250.             for i,v in ipairs(snake) do
  251.                 if v.mx == fcx and v.my == fcy and v.x == ffx and v.y ==
  252.                 snake[1].y then
  253.                     gameOver = true
  254.                     break
  255.                 end
  256.             end
  257.            
  258.             if fcy == curry and fcx == currx then
  259.                 term.setCursorPos(ffx, snake[1].y)
  260.                 term.write("=")
  261.             end
  262.            
  263.             ffx = ffx + snakefx
  264.             if ffx < 0 then
  265.                 fcx = fcx - 1
  266.                 ffx = ffx + scenew
  267.             elseif ffx > scenew then
  268.                 fcx = fcx + 1
  269.                 ffx = ffx - scenew
  270.             end
  271.         end
  272.         if map[fcy][fcx] then
  273.             fbx = ffx
  274.             fby = snake[1].y
  275.             fbcx = fcx
  276.             fbcy = fcy
  277.         else
  278.             fbx = -1
  279.             fby = -1
  280.             fbcx = -1
  281.             fbcy = -1
  282.         end
  283.     else
  284.         local ffy = snake[1].y + snakefy
  285.         while map[fcy] and map[fcy][fcx] and type(map[fcy][fcx][ffy][snake[1].x]) ~= "number" do
  286.             map[fcy][fcx][ffy][snake[1].x] = nil
  287.             for i,v in ipairs(snake) do
  288.                 if v.mx == fcx and v.my == fcy and v.x == snake[1].x and v.y ==
  289.                 ffy then
  290.                     gameOver = true
  291.                     break
  292.                 end
  293.             end
  294.             if fcy == curry and fcx == currx then
  295.                 term.setCursorPos(snake[1].x, ffy)
  296.                 term.write("|")
  297.             end
  298.             ffy = ffy + snakefy
  299.             if ffy < 0 then
  300.                 fcy = fcy - 1
  301.                 ffy = ffy + sceneh
  302.             elseif ffy > sceneh then
  303.                 fcy = fcy + 1
  304.                 ffy = ffy - sceneh
  305.             end
  306.         end
  307.         if map[fcy][fcx] then
  308.             fbx = snake[1].x
  309.             fby = ffy
  310.             fbcx = fcx
  311.             fbcy = fcy
  312.         else
  313.             fbx = -1
  314.             fby = -1
  315.             fbcx = -1
  316.             fbcy = -1
  317.         end
  318.     end
  319. end
  320.  
  321. local function lookup(x,y)
  322.     if y < 1 or y > sceneh or x < 1 or x > scenew then return 0 end
  323.     return map[curry][currx][y][x]
  324. end
  325.  
  326. local function drawMap()
  327.     local scene = map[curry][currx]
  328.     for y = 1, sceneh do
  329.         for x = 1, scenew do
  330.             updateMap(currx, curry, x, y)
  331.         end
  332.     end
  333. end
  334.  
  335. local function parseValue(mx, my, x, y, lchar)
  336.     if not map[my][mx][y] then map[my][mx][y] = {} end
  337.     if tonumber(lchar, 16) then
  338.         lchar = math.pow(2, tonumber(lchar,16))
  339.        
  340.         if lchar == colours.white then
  341.             map[my][mx][y][x] = 0
  342.         elseif lchar == colours.yellow then
  343.             map[my][mx][y][x] = 'e'
  344.             eggtotal = eggtotal + 1
  345.         elseif lchar == colours.purple then
  346.             map[my][mx][y][x] = 't'
  347.         elseif lchar == colours.lime then
  348.             start = { mx = mx, my = my, x = x, y = y }
  349.         elseif lchar == colours.blue then
  350.             map[my][mx][y][x] = '@'
  351.         elseif lchar == colours.pink then
  352.             map[my][mx][y][x] = 'F'
  353.         end
  354.     else
  355.         table.insert(map[my][mx].whitespace, {x = x, y = y})
  356.     end
  357. end
  358.  
  359.  
  360.  
  361. local function writeHS()
  362.     local f = io.open(shell.resolve(".").."/stuff/hs", "w")
  363.    
  364.     for i,v in ipairs(hs) do
  365.         f:write(v.name..regex..v.snake..regex..v.eggs..regex..v.score)
  366.         if i < #hs then f:write("\n") end
  367.     end
  368.    
  369.     f:close()
  370. end
  371.  
  372. local function loadHS()
  373.     hs = {}
  374.     if not fs.exists(shell.resolve(".").."/stuff/hs") then
  375.         print("Error: stuff/hs missing! Rewriting...")
  376.         os.pullEvent("key")
  377.         writeHS()
  378.         return
  379.     end
  380.     local f = fs.open(shell.resolve(".").."/stuff/hs", "r")
  381.    
  382.     local line = f:readLine()
  383.  
  384.     while line do
  385.         local vals = split(line, regex)
  386.         if #vals ~= 4 and not tonumber(vals[2]) and not tonumber(vals[3]) and not tonumber(vals[4]) then
  387.             print("Error: stuff/hs invalid! Rewriting...")
  388.             os.pullEvent("key")
  389.             f:close()
  390.             writeHS()
  391.             return
  392.         end
  393.         table.insert(hs, { name = vals[1], snake = tonumber(vals[2]),
  394.                 eggs = tonumber(vals[3]), score = tonumber(vals[4]) })
  395.         if #hs == 10 then break end
  396.         line = f:readLine()
  397.     end
  398.     f:close()
  399. end
  400.  
  401. local function addHighScore()
  402.     name = displayInputDialogue("You got a new high score! Enter your name:", 8, colours.blue, colours.white)
  403.     local entry = { name = name, snake = selcol.index, score = score,
  404.             eggs = eggcount }
  405.     local place = 1
  406.     for i=1,#hs do
  407.         if hs[place].score < entry.score then
  408.             break
  409.         end
  410.         place = i + 1
  411.     end
  412.     table.insert(hs, place, entry)
  413.     while #hs > 10 do
  414.         table.remove(hs, #hs)
  415.     end
  416.     writeHS()
  417. end
  418.  
  419. local function loadMap(_sPath)
  420.     if not fs.exists(_sPath) then
  421.         return false
  422.     end
  423.     mx, my = 1,1
  424.     lineno = 1
  425.  
  426.     eggtotal = 0
  427.  
  428.     local file = fs.open(_sPath, 'r')
  429.     local line = file:readLine()
  430.  
  431.     map = {}
  432.  
  433.     while line do
  434.         if not map[my] then map[my] = { } end
  435.         for i=1,#line do
  436.             mx = math.floor((i-1)/scenew)+1
  437.             if not map[my][mx] then map[my][mx] = { whitespace = {} } end
  438.             local lchar = string.sub(line,i,i)
  439.             local x =
  440.             parseValue(mx, my, i-((mx-1)*scenew), lineno-((my-1)*sceneh), lchar)
  441.         end
  442.         line = file:readLine()
  443.         my = math.floor(lineno / sceneh) + 1
  444.         lineno = lineno + 1
  445.     end
  446.     file:close()
  447.     maxGoldCount = goldCount
  448.     titleLoaded = false
  449.     return true
  450. end
  451.  
  452. local function spawnBug()
  453.     bgnext = math.random(bgfmin, bgfmax)
  454.     bugplaced = false
  455.     while not bugplaced do
  456.         local ran = math.random(1, #map[currx][curry].whitespace)
  457.         local ws = map[currx][curry].whitespace[ran]
  458.         if map[curry][currx][ws.y][ws.x]  == nil then
  459.             bugtype = math.random(1,8)
  460.             bug = ''
  461.             if bugtype <= 5 then bug = 'b'
  462.             elseif bugtype <=7 then bug = 'B'
  463.             else bug = 'X' end
  464.             map[curry][currx][ws.y][ws.x] = bug
  465.             updateMap(currx, curry, ws.x, ws.y)
  466.             bugplaced = true
  467.         end
  468.     end
  469. end
  470.  
  471. local function spawnShroom()
  472.     shnext = math.random(shfmin, shfmax)
  473.     shroomplaced = false
  474.     while not shroomplaced do
  475.         local ran = math.random(1, #map[currx][curry].whitespace)
  476.         local ws = map[currx][curry].whitespace[ran]
  477.         if map[curry][currx][ws.y][ws.x] == nil then
  478.             map[curry][currx][ws.y][ws.x] = 't'
  479.         end
  480.         updateMap(currx, curry, ws.x, ws.y)
  481.         shroomplaced = true
  482.     end
  483. end
  484.  
  485. local function initSnake()
  486.     -- Hardcoded. Lazy but easy.
  487.     snake = {}
  488.     addSegments = 8
  489.     eggcount = 0
  490.     energy = 1000
  491.     score = 0
  492.     gameOver = false
  493.     paused = false
  494.     exiting = false
  495.     snakefx = 1
  496.     snakefy = 0
  497.     snake[1] = { mx = start.mx, my = start.my, x = start.x, y = start.y }
  498.     currx = snake[1].mx
  499.     curry = snake[1].my
  500.    
  501.     drawSnake()
  502.     drawMap(currx, curry)
  503. end
  504.  
  505. local function updateSnake()
  506.     energy = energy - 2
  507.    
  508.     if (addSegments > 0) then
  509.         addSegments = addSegments - 1
  510.     else
  511.         local val = snake[#snake]
  512.         table.remove(snake, #snake)
  513.         behindscores = inSplash and showScores and val.x > scxoff - 1 and val.x <= scxoff + scw - 1 and val.y > scyoff - 1 and val.y <= scyoff + sch - 1
  514.    
  515.         if currx == val.mx and curry == val.my and not behindscores then
  516.             updateMap(currx, curry, val.x, val.y)
  517.         end
  518.     end
  519.    
  520.     if exiting then
  521.         score = score + 5
  522.         if #snake == 1 then
  523.             drawFooter()
  524.             gameOver = true
  525.             return
  526.         end
  527.     end
  528.    
  529.     local ox,oy = currx,curry
  530.     nx = snake[1].x + snakefx
  531.     ny = snake[1].y + snakefy
  532.     if nx <= 0 then
  533.         currx = currx - 1
  534.         nx = nx + scenew
  535.     elseif nx > scenew then
  536.         currx = currx + 1
  537.         nx = nx - scenew
  538.     elseif ny <= 0 then
  539.         curry = curry - 1
  540.         ny = ny + sceneh
  541.     elseif ny > sceneh then
  542.         curry = curry + 1
  543.         ny = ny - sceneh
  544.     end
  545.     if currx ~= ox or curry ~= oy then
  546.         if not map[curry] or not map[curry][currx] then
  547.             gameOver = true
  548.             return
  549.         else
  550.             if not map[curry][currx].visited then
  551.                 for i=1,5 do spawnBug() end
  552.                 map[curry][currx].visited = true
  553.             end
  554.             drawMap()
  555.         end
  556.     end
  557.     if not exiting then
  558.         table.insert(snake, 1, {
  559.             mx = currx, my = curry,
  560.             x = nx, y = ny})
  561.     end
  562.    
  563.     local terr = map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x]
  564.     if type(terr) == "number" then
  565.         --collision code
  566.         map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x] = nil
  567.         drawSegment(2)
  568.         term.setCursorPos(snake[1].x, snake[1].y)
  569.         setBG(colours.lightGrey, colours.white)
  570.         setTX(colours.brown, colours.black)
  571.         term.write("@")
  572.         gameOver = true
  573.         return
  574.     elseif terr == 'e' then
  575.         map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x] = nil
  576.         table.insert(map[snake[1].my][snake[1].mx].whitespace,
  577.             { x = snake[1].x, y = snake[1].y })
  578.         energy = energy + 200
  579.         addSegments = addSegments + 5
  580.         score = score + 200
  581.         eggcount = eggcount + 1
  582.     elseif terr == 't' then
  583.         map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x] = nil
  584.         energy = energy - 50
  585.         addSegments = addSegments + 3
  586.         score = score - 50
  587.     elseif terr == 'b' then
  588.         map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x] = nil
  589.         energy = energy + 20
  590.         addSegments = addSegments + 1
  591.         score = score + 10
  592.     elseif terr == 'B' then
  593.         map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x] = nil
  594.         energy = energy + 40
  595.         addSegments = addSegments + 2
  596.         score = score + 20
  597.     elseif terr == 'X' then
  598.         map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x] = nil
  599.         energy = energy + 100
  600.         addSegments = addSegments + 3
  601.         score = score + 50
  602.     elseif terr == 'F' then
  603.         map[snake[1].my][snake[1].mx][snake[1].y][snake[1].x] = nil
  604.         fb = fb + 8
  605.         score = score + 50
  606.     elseif terr == "@" and eggcount == eggtotal and not exiting then
  607.         exiting = true
  608.         score = score + 2000
  609.         timerLength = 0.05
  610.     end
  611.    
  612.     if energy < 0 then
  613.         gameOver = true
  614.         drawSnake()
  615.         return
  616.     end
  617.     if energy > 1000 then
  618.         energy = 1000
  619.     end
  620.    
  621.     for i=4,#snake do
  622.         local v = snake[i]
  623.         if v.mx == snake[1].mx and v.my == snake[1].my and
  624.                 v.x == snake[1].x and v.y == snake[1].y then
  625.             gameOver = true
  626.             drawSegment(2)
  627.             term.setCursorPos(snake[1].x, snake[1].y)
  628.             term.setBackgroundColour(selcol.body)
  629.             setTX(colours.red, colours.black)
  630.             term.write("@")
  631.             return
  632.         end
  633.     end
  634.    
  635.     if snake[#snake].mx == currx and snake[#snake].my == curry then
  636.         drawSegment(#snake)
  637.     end
  638.     if snake[2].mx == currx and snake[2].my == curry then
  639.         drawSegment(2)
  640.     end
  641.     drawSegment(1)
  642. end
  643.  
  644. function readInput(lim)
  645.     sleep(0.1)
  646.     term.setCursorBlink(true)
  647.  
  648.     local inputString = ""
  649.     local ox,oy = term.getCursorPos()
  650.     term.write(" ")
  651.     term.setCursorPos(ox, oy)
  652.     if not lim or type(lim) ~= "number" or lim < 1 then lim = w - ox end
  653.    
  654.     while true do
  655.         local id,key = os.pullEvent()
  656.        
  657.         if id == "key" and key == 14 and #inputString > 0 then
  658.             inputString = string.sub(inputString, 1, #inputString-1)
  659.             term.setCursorPos(ox + #inputString,oy)
  660.             term.write(" ")
  661.         elseif id == "key" and key == 28 and inputString ~= string.rep(" ", #inputString) then
  662.             break
  663.         elseif id == "char" and #inputString < lim and key ~= regex then
  664.             inputString = inputString..key
  665.         end
  666.         term.setCursorPos(ox,oy)
  667.         term.write(inputString)
  668.         term.setCursorPos(ox + #inputString, oy)
  669.     end
  670.    
  671.     while string.sub(inputString, 1, 1) == " " do
  672.         inputString = string.sub(inputString, 2, #inputString)
  673.     end
  674.     while string.sub(inputString, #inputString, #inputString) == " " do
  675.         inputString = string.sub(inputString, 1, #inputString-1)
  676.     end
  677.     term.setCursorBlink(false)
  678.    
  679.     return inputString
  680. end
  681.  
  682. function wprintOffCenter(msg, height, width, offset)
  683.     local inc = 0
  684.     local ops = 1
  685.     while #msg - ops > width do
  686.         local nextspace = 0
  687.         while string.find(msg, " ", ops + nextspace) and
  688.                 string.find(msg, " ", ops + nextspace) - ops < width do
  689.             nextspace = string.find(msg, " ", nextspace + ops) + 1 - ops
  690.         end
  691.         local ox,oy = term.getCursorPos()
  692.         term.setCursorPos(width/2 - (nextspace)/2 + offset, height + inc)
  693.         inc = inc + 1
  694.         term.write(string.sub(msg, ops, nextspace + ops - 1))
  695.         ops = ops + nextspace
  696.     end
  697.     term.setCursorPos(width/2 - #string.sub(msg, ops)/2 + offset, height + inc)
  698.     term.write(string.sub(msg, ops))
  699.    
  700.     return inc + 1
  701. end
  702.  
  703. function displayConfirmDialogue(msg, offset, backColour, textColour)
  704.     local dialogoffset = 10
  705.     if not offset then offset = 8 end
  706.     if not backColour or not term.isColour() then backColour = colours.white end
  707.     if not textColour or not term.isColour() then textColour = colours.black end
  708.     setBG(backColour, backColour)
  709.     setTX(textColour, textColour)
  710.     --We actually print twice- once to get the lines, second time to print proper. Easier this way.
  711.     local lines = wprintOffCenter(msg, offset, w - (dialogoffset+2) * 2, dialogoffset + 2)
  712.    
  713.     --This cluster of statements prints a nice box with the message the NPC has for the player in it.
  714.     for i=offset-1,offset+lines do
  715.         term.setCursorPos(dialogoffset, i)
  716.         term.write(" "..string.rep(" ", w - (dialogoffset) * 2 - 2).." ")
  717.     end
  718.     --term.setCursorPos(dialogoffset, 10 + lines + 1)
  719.     --term.write(string.rep(" ", w - (dialogoffset) * 2))
  720.     wprintOffCenter(msg, offset, w - (dialogoffset+2) * 2, dialogoffset + 2)
  721. end
  722.  
  723. function displayInputDialogue(msg, offset, backColour, textColour, prompt)
  724.     if not prompt then prompt = ">" end
  725.    
  726.     local dialogoffset = 10
  727.     if not backColour or not term.isColour() then backColour = colours.white end
  728.     if not textColour or not term.isColour() then textColour = colours.black end
  729.     setBG(backColour, backColour)
  730.     setTX(textColour, textColour)
  731.  
  732.     --We actually print twice- once to get the lines, second time to print proper. Easier this way.
  733.     local lines = wprintOffCenter(msg, offset, w - (dialogoffset+2) * 2, dialogoffset + 2)
  734.    
  735.     --This cluster of statements prints a nice box with the message the NPC has for the player in it.
  736.     for i=offset-1,offset+2+lines do
  737.         term.setCursorPos(dialogoffset, i)
  738.         term.write("*"..string.rep(" ", w - (dialogoffset) * 2 - 2).."*")
  739.     end
  740.     wprintOffCenter(msg, offset, w - (dialogoffset+2) * 2, dialogoffset + 2)
  741.    
  742.     term.setCursorPos(dialogoffset + 1, offset + 2 + lines)
  743.     term.write(" "..prompt)
  744.    
  745.     --We get our input here
  746.     local input = readInput(10)
  747.    
  748.     return input
  749. end
  750.  
  751. local function drawSelect(x,y,word,charl,charr)
  752.     term.setCursorPos(x,y)
  753.     term.write(charl)
  754.     term.setCursorPos(x+#word+1,y)
  755.     term.write(charr)
  756. end
  757.  
  758. local function initTimers()
  759.     bgnext = math.random(bgfmin, bgfmax)
  760.     shnext = math.random(shfmin, shfmax)
  761.     timerID = os.startTimer(timerLength)
  762. end
  763.  
  764. local function drawScores(sel)
  765.     local noff,soff,eoff = 1,25,31
  766.     local ntoff,stoff,etoff = 5,20,28
  767.     local opt = {"New Game", "Quit"}
  768.    
  769.     setBG(colours.blue, colours.black)
  770.     setTX(colours.white, colours.white)
  771.     term.setCursorPos(scxoff,scyoff)
  772.     term.write(string.rep(" *", scw/2))
  773.     for i=1,12 do
  774.         term.setCursorPos(scxoff,scyoff+i)
  775.         if (i%2) == 1 then
  776.             term.write("*"..string.rep(" ",scw-2).." ")
  777.         else
  778.             term.write(" "..string.rep(" ",scw-2).."*")
  779.         end
  780.     end
  781.     term.setCursorPos(scxoff,scyoff + sch - 1)
  782.     term.write(string.rep("* ", scw/2))
  783.     term.setCursorPos(scxoff + ntoff,scyoff+1)
  784.     term.write("Name")
  785.     term.setCursorPos(scxoff + stoff,scyoff+1)
  786.     term.write("Score")
  787.     term.setCursorPos(scxoff + etoff,scyoff+1)
  788.     setTX(colours.yellow, colours.white)
  789.     term.write("Eggs")
  790.    
  791.     for i,v in ipairs(hs) do
  792.         term.setCursorPos(scxoff + noff,scyoff+1+i)
  793.         setBG(sncol[v.snake].body, colours.white)
  794.         setTX(sncol[v.snake].scales, colours.black)
  795.         term.write("-- "..v.name.." -")
  796.         setTX(sncol[v.snake].eyes, colours.black)
  797.         term.write(":")
  798.         term.setCursorPos(scxoff + soff - #tostring(v.score), scyoff+1+i)
  799.         setBG(colours.blue, colours.black)
  800.         setTX(colours.white, colours.white)
  801.         term.write(tostring(v.score))
  802.         term.setCursorPos(scxoff + eoff - #tostring(v.eggs), scyoff+1+i)
  803.         setTX(colours.yellow, colours.white)
  804.         term.write(tostring(v.eggs))
  805.     end
  806.    
  807.     term.setCursorPos(scxoff + scw/4 - #opt[1]/2 - 1, scyoff + sch-2)
  808.     setTX(colours.white, colours.white)
  809.     if sel == 1 then term.write("<"..opt[1]..">")
  810.     else term.write(" "..opt[1].." ") end
  811.     term.setCursorPos(scxoff + (3*scw)/4 - #opt[2]/2 - 1, scyoff + sch-2)
  812.     if sel == 2 then term.write("<"..opt[2]..">")
  813.     else term.write(" "..opt[2].." ") end
  814. end
  815.  
  816. local function prepareRandomScene()
  817.     gameOver = false
  818.     currx = math.random(1,#map[1])
  819.     curry = math.random(1,#map)
  820.     addSegments = 12
  821.     energy = 1000
  822.     local s = map[curry][currx].whitespace[math.random(1,#map[curry][currx].whitespace)]
  823.     snake = {}
  824.     snake[1] = { mx = currx, my = curry, x = s.x, y = s.y}
  825.     selcol = sncol[math.random(1,3)]
  826.     if not term.isColour() then selcol = sncol[5] end
  827.     drawMap(currx, curry)
  828.     drawSnake()
  829. end
  830.  
  831. local function runSplash()
  832.     inSplash = true
  833.     exiting = false
  834.     flaming = false
  835.     paused = false
  836.     fb = 0
  837.     loadMap(shell.resolve(".").."/stuff/"..levelname)
  838.     prepareRandomScene()
  839.     local sel = 1
  840.     local splashOver = false
  841.     local msg = ""
  842.     if not showScores then
  843.         displayConfirmDialogue("Snake Maze", 8, colours.blue, colours.white)
  844.         displayConfirmDialogue("By NitrogenFingers", 10, colours.blue, colours.white)
  845.         msg = "Press a key to begin"
  846.     else
  847.         drawScores(sel)
  848.         msg = "Use arrows to move and enter to select"
  849.     end
  850.     term.setCursorPos(w/2 - #msg/2,h)
  851.     setTX(colours.white, colours.white)
  852.     setBG(colours.blue, colours.black)
  853.     term.clearLine()
  854.     term.write(msg)
  855.     local splashTimer = os.startTimer(timerLength)
  856.     while not splashOver do
  857.         local klist = {}
  858.         local head = snake[1]
  859.         local insertOK = true
  860.         if lookup(head.x + 1, head.y) ~= 0 then
  861.             for i = 2,#snake do
  862.                 v = snake[i]
  863.                 if v.x == head.x + 1 and v.y == head.y then
  864.                     insertOK = false
  865.                     break
  866.                 end
  867.             end
  868.             if insertOK then table.insert(klist, { fx = 1, fy = 0 }) end
  869.         end
  870.         insertOK = true
  871.         if lookup(head.x - 1, head.y) ~= 0 then
  872.             for i = 2,#snake do
  873.                 v = snake[i]
  874.                 if v.x == head.x - 1 and v.y == head.y then
  875.                     insertOK = false
  876.                     break
  877.                 end
  878.             end
  879.             if insertOK then table.insert(klist, { fx = -1, fy = 0 }) end
  880.         end
  881.         insertOK = true
  882.         if lookup(head.x, head.y + 1) ~= 0 then
  883.             for i = 2,#snake do
  884.                 v = snake[i]
  885.                 if v.x == head.x and v.y == head.y + 1 then
  886.                     insertOK = false
  887.                     break
  888.                 end
  889.             end
  890.             if insertOK then table.insert(klist, { fx = 0, fy = 1 }) end
  891.         end
  892.         insertOK = true
  893.         if lookup(head.x, head.y - 1) ~= 0 then
  894.             for i = 2,#snake do
  895.                 v = snake[i]
  896.                 if v.x == head.x and v.y == head.y - 1 then
  897.                     insertOK = false
  898.                     break
  899.                 end
  900.             end
  901.             if insertOK then table.insert(klist, { fx = 0, fy = -1 }) end
  902.         end
  903.         if #klist > 0 then
  904.             local rk = klist[math.random(1,#klist)]
  905.             snakefx = rk.fx
  906.             snakefy = rk.fy
  907.         end
  908.        
  909.         local id, key = os.pullEvent()
  910.         if id == "key" then
  911.             if not showScores then
  912.                 showScores = true
  913.                 drawScores(sel)
  914.                 local msg = "Use arrows to move and enter to select"
  915.                 term.setCursorPos(w/2 - #msg/2,h)
  916.                 setTX(colours.white, colours.white)
  917.                 setBG(colours.blue, colours.black)
  918.                 term.clearLine()
  919.                 term.write(msg)
  920.             elseif key == keys.enter then
  921.                 inSplash = false
  922.                 return sel
  923.             elseif key == keys.left and sel == 2 then
  924.                 sel = 1
  925.                 drawScores(sel)
  926.             elseif key == keys.right and sel == 1 then
  927.                 sel = 2
  928.                 drawScores(sel)
  929.             end
  930.         elseif id == "timer" and key == splashTimer then
  931.             local ox,oy = currx,curry
  932.             updateSnake()
  933.             if ox ~= currx or oy ~= curry then
  934.                 if not showScores then
  935.                     displayConfirmDialogue("Snake Maze", 8, colours.blue, colours.white)
  936.                     displayConfirmDialogue("By NitrogenFingers", 10, colours.blue, colours.white)
  937.                 else
  938.                     drawScores(sel)
  939.                 end
  940.             end
  941.             if gameOver then
  942.                 prepareRandomScene()
  943.                 if showScores then drawScores(sel) end
  944.             end
  945.             if not showScores then
  946.                 displayConfirmDialogue("Snake Maze", 8, colours.blue, colours.white)
  947.                 displayConfirmDialogue("By NitrogenFingers", 10, colours.blue, colours.white)
  948.             end
  949.             splashTimer = os.startTimer(timerLength)
  950.         end
  951.     end
  952. end
  953.  
  954. local function runMenu()
  955.     gameOver = false
  956.     exiting = false
  957.     paused = false
  958.     flaming = false
  959.     fb = 0
  960.     currx = 1
  961.     curry = 1
  962.     local menw,menh = 26,14
  963.     local xoff,yoff = math.floor(w/2-menw/2), math.floor(h/2-menh/2)
  964.     local sm, mo = 1,1
  965.     local spsel, snsel = 2, 1
  966.     local spop = { "Slow", "Medium", "Fast", "Fiendish" }
  967.     local spopl,spopt,spopy = xoff + 2, xoff + 5, yoff + 4
  968.     local snop = { "Sammy", "Clyde", "Joss " }
  969.     local snopl,snopt,snopy = xoff + menw - 2, xoff + menw - 4 - #snop[1], yoff + 3
  970.     local bot = "Play Snake Maze"
  971.     local bott,boty = xoff + (menw/2 - #bot/2) + 1, yoff + 13
  972.    
  973.     for i=1,#hs do
  974.         if hs[i].eggs == 16 then
  975.             table.insert(snop, "Bones")
  976.             snopy = snopy - 1
  977.             break
  978.         end
  979.     end
  980.    
  981.     if not term.isColour() then
  982.         snop = {}
  983.         spopl = spopl + 5
  984.         spopt = spopt + 5
  985.     end
  986.    
  987.     setBG(colours.grey, colours.black)
  988.     term.clear()
  989.     setBG(colours.blue, colours.black)
  990.     setTX(colours.white, colours.white)
  991.     for i=1,menh do
  992.         term.setCursorPos(xoff,yoff+i)
  993.         term.write(string.rep(" ", menw))
  994.     end
  995.     term.setCursorPos(spopl + 1, yoff + 2)
  996.     term.write("Speed")
  997.     if term.isColour() then term.write(string.rep(" ",9).."Snake") end
  998.     for i=1,#spop do
  999.         term.setCursorPos(spopl, spopy + i*2 - 2)
  1000.         if i == spsel then
  1001.             setBG(colours.lime, colours.black)
  1002.             setTX(colours.lime, colours.white)
  1003.         else
  1004.             setBG(colours.red, colours.black)
  1005.             setTX(colours.red, colours.black)
  1006.         end
  1007.         term.write("X")
  1008.         setBG(colours.blue, colours.black)
  1009.         setTX(colours.white, colours.white)
  1010.         term.write("  "..spop[i])
  1011.     end
  1012.     for i=1,#snop do
  1013.         setBG(colours.blue, colours.black)
  1014.         setTX(colours.white, colours.white)
  1015.         term.setCursorPos(snopt, snopy + i*2)
  1016.         term.write(snop[i].."  ")
  1017.         if i == snsel then
  1018.             setBG(colours.lime, colours.black)
  1019.             setTX(colours.lime, colours.white)
  1020.         else
  1021.             setBG(colours.red, colours.black)
  1022.             setTX(colours.red, colours.black)
  1023.         end
  1024.         term.write("X")
  1025.     end
  1026.     setBG(colours.blue, colours.black)
  1027.     setTX(colours.white, colours.white)
  1028.     term.setCursorPos(bott, boty)
  1029.     term.write(bot)
  1030.     local snstx = xoff + math.random(2,menw - 1)
  1031.     local snsty = yoff + menh + 1
  1032.     snakefx = 1
  1033.     snakefy = 0
  1034.     snake = {}
  1035.     for i=1,70 do
  1036.         snstx = snstx + snakefx
  1037.         snsty = snsty + snakefy
  1038.         if snstx == xoff + menw and snsty == yoff + menh + 1 then
  1039.             snakefx = 0
  1040.             snakefy = -1
  1041.         elseif snstx == xoff + menw and snsty == yoff then
  1042.             snakefx = -1
  1043.             snakefy = 0
  1044.         elseif snstx == xoff - 1 and snsty == yoff then
  1045.             snakefx = 0
  1046.             snakefy = 1
  1047.         elseif snstx == xoff - 1 and snsty == yoff + menh + 1 then
  1048.             snakefx = 1
  1049.             snakefy = 0
  1050.         end
  1051.         table.insert(snake, 1, {mx = 1, my = 1, x = snstx, y = snsty })
  1052.     end
  1053.     if term.isColour() then
  1054.         selcol = sncol[snsel]
  1055.     else
  1056.         selcol = sncol[5]
  1057.     end
  1058.     drawSnake()
  1059.     timerLength = baseTimer - (spsel-1)*0.05
  1060.     local menutimer = os.startTimer(timerLength)
  1061.     local inMenu = true
  1062.     while inMenu do
  1063.         setTX(selcol.body, selcol.body)
  1064.         setBG(colours.blue, colours.black)
  1065.         if sm == 1 then
  1066.             drawSelect(spopt - 1, spopy + mo*2 - 2, spop[mo], "<", ">")
  1067.         elseif sm == 2 then
  1068.             drawSelect(snopt - 1, snopy + mo*2, snop[mo], "<", ">")
  1069.         else
  1070.             drawSelect(bott - 1, boty, bot, "<", ">")
  1071.         end
  1072.         local id,key = os.pullEvent()
  1073.        
  1074.         if id == "timer" and key == menutimer then
  1075.             local head = snake[1]
  1076.             if head.x == xoff + menw and head.y == yoff + menh + 1 then
  1077.                 snakefx = 0
  1078.                 snakefy = -1
  1079.             elseif head.x == xoff + menw and head.y == yoff then
  1080.                 snakefx = -1
  1081.                 snakefy = 0
  1082.             elseif head.x == xoff - 1 and head.y == yoff then
  1083.                 snakefx = 0
  1084.                 snakefy = 1
  1085.             elseif head.x == xoff - 1 and head.y == yoff + menh + 1 then
  1086.                 snakefx = 1
  1087.                 snakefy = 0
  1088.             end
  1089.             setBG(colours.grey, colours.black)
  1090.             term.setCursorPos(snake[#snake].x, snake[#snake].y)
  1091.             term.write(" ")
  1092.             table.remove(snake, #snake)
  1093.             table.insert(snake, 1, { mx = 1, my = 1, x = head.x + snakefx, y =
  1094.                     head.y + snakefy} )
  1095.             drawSegment(1)
  1096.             drawSegment(2)
  1097.             menutimer = os.startTimer(timerLength)
  1098.         elseif id == "key" then
  1099.             if key == keys.left and sm == 2 then
  1100.                 drawSelect(snopt - 1, snopy + mo*2, snop[mo], " ", " ")
  1101.                 sm = 1
  1102.                 if mo > #spop then mo = #spop end
  1103.             elseif key == keys.right and sm == 1 and term.isColour() then
  1104.                 drawSelect(spopt - 1, spopy + mo*2 - 2, spop[mo], " ", " ")
  1105.                 sm = 2
  1106.                 if mo > #snop then mo = #snop end
  1107.             elseif key == keys.down then
  1108.                 if sm == 1 then
  1109.                     drawSelect(spopt - 1, spopy + mo*2 - 2, spop[mo], " ", " ")
  1110.                     if mo == #spop then
  1111.                         mo = 1
  1112.                         sm = 3
  1113.                     else mo = mo + 1 end
  1114.                 elseif sm == 2 then
  1115.                     drawSelect(snopt - 1, snopy + mo*2, snop[mo], " ", " ")
  1116.                     if mo == #snop then
  1117.                         mo = 1
  1118.                         sm = 3
  1119.                     else mo = mo + 1 end
  1120.                 elseif sm == 3 then
  1121.                     drawSelect(bott - 1, boty, bot, " ", " ")
  1122.                     sm = 1
  1123.                     mo = 1
  1124.                 end
  1125.             elseif key == keys.up then
  1126.                 if sm == 1 then
  1127.                     drawSelect(spopt - 1, spopy + mo*2 - 2, spop[mo], " ", " ")
  1128.                     if mo == 1 then
  1129.                         mo = 1
  1130.                         sm = 3
  1131.                     else mo = mo - 1 end
  1132.                 elseif sm == 2 then
  1133.                     drawSelect(snopt - 1, snopy + mo*2, snop[mo], " ", " ")
  1134.                     if mo == 1 then
  1135.                         mo = 1
  1136.                         sm = 3
  1137.                     else mo = mo - 1 end
  1138.                 elseif sm == 3 then
  1139.                     drawSelect(bott - 1, boty, bot, " ", " ")
  1140.                     sm = 1
  1141.                     mo = #spop
  1142.                 end
  1143.             elseif key == keys.enter then
  1144.                 if sm == 1 then
  1145.                     term.setCursorPos(spopl, spopy + spsel*2 - 2)
  1146.                     setBG(colours.red, colours.black)
  1147.                     setTX(colours.red, colours.black)
  1148.                     term.write("X")
  1149.                     spsel = mo
  1150.                     timerLength = baseTimer - (spsel-1)*0.05
  1151.                     term.setCursorPos(spopl, spopy + spsel*2 - 2)
  1152.                     setBG(colours.lime, colours.black)
  1153.                     setTX(colours.lime, colours.white)
  1154.                     term.write("X")
  1155.                 elseif sm == 2 then
  1156.                     term.setCursorPos(snopl, snopy + snsel*2)
  1157.                     setBG(colours.red, colours.black)
  1158.                     setTX(colours.red, colours.black)
  1159.                     term.write("X")
  1160.                     snsel = mo
  1161.                     selcol = sncol[snsel]
  1162.                     term.setCursorPos(snopl, snopy + snsel*2)
  1163.                     setBG(colours.lime, colours.black)
  1164.                     setTX(colours.lime, colours.white)
  1165.                     term.write("X")
  1166.                     drawSnake()
  1167.                 elseif sm == 3 then
  1168.                     inMenu = false
  1169.                 end
  1170.             end
  1171.         end
  1172.     end
  1173. end
  1174.  
  1175. local function runGame()
  1176.     loadMap(shell.resolve(".").."/stuff/"..levelname)
  1177.     initSnake()
  1178.     initTimers()
  1179.     drawFooter()
  1180.     while not gameOver do
  1181.         local id,key = os.pullEvent()
  1182.         if id == 'timer' and key == timerID and not paused then
  1183.             drawFooter()
  1184.             bgnext = bgnext - 1
  1185.             if bgnext <= 0 then
  1186.                 spawnBug()
  1187.             end
  1188.             shnext = shnext - 1
  1189.             if shnext <= 0 then
  1190.                 spawnShroom()
  1191.             end
  1192.             if flaming then
  1193.                 if map[fbcy] and map[fbcy][fbcx] then
  1194.                     map[fbcy][fbcx][fby][fbx] = map[fbcy][fbcx][fby][fbx] + 1
  1195.                     if map[fbcy][fbcx][fby][fbx] == 4 then
  1196.                         map[fbcy][fbcx][fby][fbx] = nil
  1197.                         updateFire()
  1198.                     else
  1199.                         updateMap(fbcx,fbcy,fbx,fby)
  1200.                     end
  1201.                 end
  1202.                 fb = fb - 1
  1203.                 if fb == 0 then
  1204.                     flaming = false
  1205.                     drawMap()
  1206.                 end
  1207.             end
  1208.             updateSnake()
  1209.             timerID = os.startTimer(timerLength)
  1210.         elseif id == 'key' and #snake > 1 then
  1211.             local xdiff = snake[2].x - snake[1].x
  1212.             local ydiff = snake[2].y - snake[1].y
  1213.             if not paused then
  1214.                 if key == keys.left and xdiff ~= -1 and
  1215.                         not flaming and not exiting then
  1216.                     snakefx = -1
  1217.                     snakefy = 0
  1218.                     drawSegment(1)
  1219.                 elseif key == keys.right and xdiff ~= 1 and not flaming then
  1220.                     snakefx = 1
  1221.                     snakefy = 0
  1222.                     drawSegment(1)
  1223.                 elseif key == keys.up and ydiff ~= -1 and not flaming then
  1224.                     snakefx = 0
  1225.                     snakefy = -1
  1226.                     drawSegment(1)
  1227.                 elseif key == keys.down and ydiff ~= 1 and not flaming then
  1228.                     snakefx = 0
  1229.                     snakefy = 1
  1230.                     drawSegment(1)
  1231.                 elseif key == keys.space and fb > 0 and not flaming then
  1232.                     flaming = true
  1233.                     updateFire()
  1234.                 elseif key ~= keys.left and key ~= keys.right and key ~= keys.up
  1235.                         and key ~= keys.down and key ~= keys.space then
  1236.                     displayConfirmDialogue("Paused", 8, colours.blue, colours.white)
  1237.                     displayConfirmDialogue("Press \'Q\' to quit, any other key to continue", 10, colours.blue, colours.white)
  1238.                     paused = true
  1239.                 end            
  1240.             elseif key == keys.q then
  1241.                 gameOver = true
  1242.                 os.pullEvent()
  1243.             else
  1244.                 drawMap(currx,curry)
  1245.                 timerID = os.startTimer(timerLength)
  1246.                 paused = false
  1247.             end
  1248.         end
  1249.     end
  1250.    
  1251.     if not paused then     
  1252.         term.setCursorPos(3,h)
  1253.         setBG(colours.blue, colours.white)
  1254.         setTX(colours.white, colours.black)
  1255.         term.write("Game Over!    ")
  1256.         os.pullEvent("key")
  1257.        
  1258.         --high scores here
  1259.         if #hs < 10 or score > hs[10].score then
  1260.             addHighScore()
  1261.         end
  1262.     else
  1263.         paused = false
  1264.     end
  1265. end
  1266.  
  1267. function split(str, pattern)
  1268.   local t = { }
  1269.   local fpat = "(.-)" .. pattern
  1270.   local last_end = 1
  1271.   local s, e, cap = str:find(fpat, 1)
  1272.   while s do
  1273.     if s ~= 1 or cap ~= "" then
  1274.       table.insert(t,cap)
  1275.     end
  1276.     last_end = e+1
  1277.     s, e, cap = str:find(fpat, last_end)
  1278.   end
  1279.   if last_end <= #str then
  1280.     cap = str:sub(last_end)
  1281.     table.insert(t, cap)
  1282.   end
  1283.   return t
  1284. end
  1285.  
  1286. local tArgs = {...}
  1287. if tArgs[1] == "-o" then
  1288.     scenew = 50
  1289.     levelname = "levelo.nfp"
  1290. end
  1291.  
  1292. loadHS()
  1293. --So this is lazy... but whatever
  1294. local v = runSplash()
  1295. while v == 1 do
  1296.     runMenu()
  1297.     runGame()
  1298.     v = runSplash()
  1299. end
  1300. setBG(colours.black, colours.black)
  1301. shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement