Advertisement
CaptainSpaceCat

SpaceTeam

May 21st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.33 KB | None | 0 0
  1. if not fs.exists("space.nfp") then
  2.   oFile = fs.open("space.nfp", "w")
  3.   oFile.writeLine(" 000000")
  4.   oFile.writeLine(" 00 00")
  5.   oFile.writeLine("000 00")
  6.   oFile.flush()
  7.   oFile.close()
  8. end
  9.  
  10. if not fs.exists("dial.nfp") then
  11.   oFile = fs.open("dial.nfp", "w")
  12.   oFile.writeLine(" 777 ")
  13.   oFile.writeLine("77777")
  14.   oFile.writeLine("77777")
  15.   oFile.writeLine(" 777 ")
  16.   oFile.flush()
  17.   oFile.close()
  18. end
  19.  
  20. if not fs.exists("buttonOn.nfp") then
  21.   oFile = fs.open("buttonOn.nfp", "w")
  22.   oFile.writeLine("77777")
  23.   oFile.writeLine("7eee7")
  24.   oFile.writeLine("7eee7")
  25.   oFile.writeLine("77777")
  26.   oFile.flush()
  27.   oFile.close()
  28. end
  29.  
  30. if not fs.exists("buttonOff.nfp") then
  31.   oFile = fs.open("buttonOff.nfp", "w")
  32.   oFile.writeLine("77777")
  33.   oFile.writeLine("78887")
  34.   oFile.writeLine("78887")
  35.   oFile.writeLine("77777")
  36.   oFile.flush()
  37.   oFile.close()
  38. end
  39.  
  40. if not fs.exists("sliderX.nfp") then
  41.   oFile = fs.open("sliderX.nfp", "w")
  42.   oFile.writeLine("878")
  43.   oFile.flush()
  44.   oFile.close()
  45. end
  46.  
  47. if not fs.exists("sliderY.nfp") then
  48.   oFile = fs.open("sliderY.nfp", "w")
  49.   oFile.writeLine("8")
  50.   oFile.writeLine("7")
  51.   oFile.writeLine("8")
  52.   oFile.flush()
  53.   oFile.close()
  54. end
  55.  
  56. rednet.open("back")
  57. function spacewrite(string, x, y, txtcol, bakcol)
  58.   if txtcol then
  59.     term.setTextColor(txtcol)
  60.   end
  61.   if bakcol then
  62.     term.setBackgroundColor(bakcol)
  63.   end
  64.   term.setCursorPos(x, y)
  65.   term.write(string)
  66. end
  67. w, h = term.getSize()
  68. term.setBackgroundColor(colors.black)
  69. term.clear()
  70. local logo = paintutils.loadImage("space.nfp")
  71. local dial = paintutils.loadImage("dial.nfp")
  72. local sliderX = paintutils.loadImage("sliderX.nfp")
  73. local sliderY = paintutils.loadImage("sliderY.nfp")
  74. local buttonOn = paintutils.loadImage("buttonOn.nfp")
  75. local buttonOff = paintutils.loadImage("buttonOff.nfp")
  76. paintutils.drawImage(logo, 10, 2)
  77. spacewrite("SpaceTeam", 9, 5, colors.white, colors.black)
  78. --spacewrite("Start Game", 9, h, colors.white, colors.black)
  79. local start = false
  80. local x = nil
  81. local y = nil
  82. local tempX = nil
  83. local tempY = nil
  84. clickables = {}
  85.  
  86. ------======DEFINES DIALS======------
  87. function defDial(dialX, dialY, dialName)
  88.   term.setTextColor(colors.white)
  89.   clickables[#clickables + 1] = {}
  90.     clickables[#clickables][1] = dialX
  91.     clickables[#clickables][2] = dialY
  92.     clickables[#clickables][3] = dialName
  93.     clickables[#clickables][4] = "Dial"
  94.     clickables[#clickables][5] = 1
  95.   paintutils.drawImage(dial, dialX, dialY)
  96.   term.setCursorPos(dialX, dialY + 3)
  97.   term.setBackgroundColor(colors.lightGray)
  98.   term.write("/")
  99.   term.setBackgroundColor(colors.black)
  100.   term.setCursorPos(dialX - 1, dialY + 4)
  101.   term.write("1")
  102.   term.setCursorPos(dialX - 2, dialY + 1)
  103.   term.write("2")
  104.   term.setCursorPos(dialX - 1, dialY - 1)
  105.   term.write("3")
  106.   term.setCursorPos(dialX + 2, dialY - 2)
  107.   term.write("4")
  108.   term.setCursorPos(dialX + 5, dialY - 1)
  109.   term.write("5")
  110.   term.setCursorPos(dialX + 6, dialY + 1)
  111.   term.write("6")
  112.   term.setCursorPos(dialX + 5, dialY + 4)
  113.   term.write("7")
  114.   term.setCursorPos(dialX - #dialName / 2 + 3, dialY + 5)
  115.   term.write(dialName)
  116. end
  117.  
  118.  
  119. ------======DEFINES SWITCHES======------
  120. function defSwitch(switchX, switchY, switchDir, switchState, switchName)
  121.   clickables[#clickables + 1] = {}
  122.     clickables[#clickables][1] = switchX
  123.     clickables[#clickables][2] = switchY
  124.     clickables[#clickables][3] = switchName
  125.     clickables[#clickables][4] = "Switch"
  126.     clickables[#clickables][5] = switchState
  127.     clickables[#clickables][6] = switchDir
  128.   term.setCursorPos(switchX, switchY)
  129.   term.setBackgroundColor(colors.gray)
  130.   term.write(" ")
  131.   term.setBackgroundColor(colors.lightGray)
  132.   if switchDir == "X" then
  133.     if switchState == true then
  134.       term.setCursorPos(switchX + 1, switchY)
  135.       term.write("   ")
  136.     else
  137.       term.setCursorPos(switchX - 3, switchY)
  138.       term.write("   ")
  139.     end
  140.     term.setBackgroundColor(colors.black)
  141.     term.setTextColor(colors.white)
  142.     term.setCursorPos(switchX + 4, switchY)
  143.     term.write("O")
  144.     term.setCursorPos(switchX - 4, switchY)
  145.     term.write("X")
  146.     term.setCursorPos(switchX - #switchName / 2 + 1, switchY + 1)
  147.     term.write(switchName)
  148.   elseif switchDir == "Y" then
  149.     if switchState == true then
  150.       for i = 3, 1, -1 do
  151.         term.setCursorPos(switchX, switchY - i)
  152.         term.write(" ")
  153.       end
  154.     else
  155.       for i = 1, 3 do
  156.         term.setCursorPos(switchX, switchY + i)
  157.         term.write(" ")
  158.       end
  159.     end
  160.     term.setBackgroundColor(colors.black)
  161.     term.setTextColor(colors.white)
  162.     term.setCursorPos(switchX, switchY - 4)
  163.     term.write("O")
  164.     term.setCursorPos(switchX, switchY + 4)
  165.     term.write("X")
  166.     term.setCursorPos(switchX - #switchName / 2 + 1, switchY + 5)
  167.     term.write(switchName)
  168.   end
  169. end
  170.  
  171. ------======DEFINES BUTTONS======------
  172. function defButton(butX, butY, butState, butName)
  173.   term.setBackgroundColor(colors.black)
  174.   term.setTextColor(colors.white)
  175.   clickables[#clickables + 1] = {}
  176.     clickables[#clickables][1] = butX
  177.     clickables[#clickables][2] = butY
  178.     clickables[#clickables][3] = butName
  179.     clickables[#clickables][4] = "Button"
  180.     clickables[#clickables][5] = butState
  181.   term.setCursorPos(butX - #butName / 2 + 3, butY + 5)
  182.   term.write(butName)
  183.   if butState == true then
  184.     paintutils.drawImage(buttonOn, butX, butY)
  185.   else
  186.     paintutils.drawImage(buttonOff, butX, butY)
  187.   end
  188. end
  189.  
  190. ------======DEFINES SLIDERS======------
  191. function defSlider(slideX, slideY, slideDir, slideName)
  192.   term.setBackgroundColor(colors.black)
  193.   term.setTextColor(colors.white)
  194.   clickables[#clickables + 1] = {}
  195.     clickables[#clickables][1] = slideX
  196.     clickables[#clickables][2] = slideY
  197.     clickables[#clickables][3] = slideName
  198.     clickables[#clickables][4] = "Slider"
  199.     clickables[#clickables][5] = 0
  200.     clickables[#clickables][6] = slideDir
  201.   if slideDir == "X" then
  202.     for i = 0, 6 do
  203.       term.setCursorPos(slideX + i, slideY)
  204.       term.write("-")
  205.     end
  206.     term.setCursorPos(slideX + 2, slideY - 1)
  207.     term.write("0 1 2 3")
  208.     paintutils.drawImage(sliderX, slideX - 1, slideY)
  209.     term.setBackgroundColor(colors.black)
  210.     term.setTextColor(colors.white)
  211.     term.setCursorPos(slideX, slideY + 1)
  212.     term.write(slideName)
  213.   elseif slideDir == "Y" then
  214.     for i = 0, 6 do
  215.       term.setCursorPos(slideX, slideY + i)
  216.       term.write("|")
  217.     end
  218.     for i = 0, 3 do
  219.       term.setCursorPos(slideX - 1, slideY + 6 - i * 2)
  220.       term.write(i)
  221.     end
  222.     paintutils.drawImage(sliderY, slideX, slideY + 5)
  223.     term.setBackgroundColor(colors.black)
  224.     term.setTextColor(colors.white)
  225.     term.setCursorPos(slideX - #slideName / 2 + 1, slideY + 8)
  226.     term.write(slideName)
  227.   end
  228. end
  229.  
  230. ------======CHECKS SWITCHES======------
  231. function checkSwitch(switchX, switchY)
  232.   if e == "mouse_click" then
  233.     tempX = x
  234.     tempY = y
  235.   end
  236.   if clickables[num][6] == "X" then
  237.     if clickables[num][5] == true then
  238.       if m == 1 and (tempX >= switchX + 1 and tempX <= switchX + 3 and tempY == switchY) and (x >= switchX - 3 and x <= switchX - 1 and y == switchY) then
  239.         clickables[num][5] = false
  240.         response = false
  241.       end
  242.     else
  243.       if m == 1 and (tempX >= switchX - 3 and tempX <= switchX - 1 and tempY == switchY) and (x >= switchX + 1 and x <= switchX + 3 and y == switchY) then
  244.         clickables[num][5] = true
  245.         response = true
  246.       end
  247.     end
  248.     term.setCursorPos(switchX - 3, switchY)
  249.     if clickables[num][5] == true then
  250.       term.setBackgroundColor(colors.black)
  251.     else
  252.       term.setBackgroundColor(colors.lightGray)
  253.     end
  254.     term.write("   ")
  255.     term.setCursorPos(switchX + 1, switchY)
  256.     if clickables[num][5] == true then
  257.       term.setBackgroundColor(colors.lightGray)
  258.     else
  259.       term.setBackgroundColor(colors.black)
  260.     end
  261.     term.write("   ")
  262.   elseif clickables[num][6] == "Y" then
  263.     if clickables[num][5] == true then
  264.       if m == 1 and (tempY >= switchY - 3 and tempY <= switchY - 1 and tempX == switchX) and (y >= switchY + 1 and y <= switchY + 3 and x == switchX) then
  265.         clickables[num][5] = false
  266.         response = false
  267.       end
  268.     else
  269.       if m == 1 and (tempY >= switchY + 1 and tempY <= switchY + 3 and tempX == switchX) and (y >= switchY - 3 and y <= switchY - 1 and x == switchX) then
  270.         clickables[num][5] = true
  271.         response = true
  272.       end
  273.     end
  274.     if clickables[num][5] == true then
  275.       term.setBackgroundColor(colors.lightGray)
  276.     else
  277.       term.setBackgroundColor(colors.black)
  278.     end
  279.     for i = 3, 1, -1 do
  280.       term.setCursorPos(switchX, switchY - i)
  281.       term.write(" ")
  282.     end
  283.     if clickables[num][5] == true then
  284.       term.setBackgroundColor(colors.black)
  285.     else
  286.       term.setBackgroundColor(colors.lightGray)
  287.     end
  288.     for i = 1, 3 do
  289.       term.setCursorPos(switchX, switchY + i)
  290.       term.write(" ")
  291.     end
  292.   end
  293. end
  294.  
  295. ------======CHECKS BUTTONS======------
  296. function checkButton(butX, butY)
  297.   if clickables[num][5] == true then
  298.     clickables[num][5] = false
  299.     term.setCursorPos(butX, butY)
  300.     paintutils.drawImage(buttonOff, butX, butY)
  301.     response = false
  302.   else
  303.     clickables[num][5] = true
  304.     term.setCursorPos(butX, butY)
  305.     paintutils.drawImage(buttonOn, butX, butY)
  306.     response = true
  307.   end
  308. end
  309.  
  310. ------======CHECKS SLIDERS======------
  311. function checkSlider(slideX, slideY)
  312.   term.setBackgroundColor(colors.black)
  313.   if clickables[num][6] == "X" and m == 1 and (x >= clickables[num][1] + clickables[num][5] * 2 - 1 and x <= clickables[num][1] + clickables[num][5] * 2 + 1) and (x >= clickables[num][1] and x <= clickables[num][1] + 6) and y == clickables[num][2] and e == "mouse_drag" then
  314.     for i = 0, 6 do
  315.       term.setCursorPos(slideX + i, slideY)
  316.       term.write("-")
  317.     end
  318.     term.setCursorPos(slideX - 1, slideY)
  319.     term.write(" ")
  320.     term.setCursorPos(slideX + 7, slideY)
  321.     term.write(" ")
  322.     paintutils.drawImage(sliderX, x - 1, y)
  323.     clickables[num][5] = (x - slideX) / 2
  324.     response = (x - slideX) / 2
  325.   elseif clickables[num][6] == "Y" and m == 1 and (y <= clickables[num][2] + 6 - (clickables[num][5] * 2 - 1) and y >= clickables[num][2] + 6 - (clickables[num][5] * 2 + 1)) and (y >= clickables[num][2] and y <= clickables[num][2] + 6) and x == clickables[num][1] and e == "mouse_drag" then
  326.     for i = 0, 6 do
  327.       term.setCursorPos(slideX, slideY + i)
  328.       term.write("|")
  329.     end
  330.     term.setCursorPos(slideX, slideY - 1)
  331.     term.write(" ")
  332.     term.setCursorPos(slideX, slideY + 7)
  333.     term.write(" ")
  334.     paintutils.drawImage(sliderY, x, y - 1)
  335.     clickables[num][5] = (slideY + 6 - y) / 2
  336.     response = (slideY + 6 - y) / 2
  337.   end
  338. end
  339.  
  340. ------======CLEARS AND CHECKS DIALS======------
  341. local dialXPos = nil
  342. local dialYPos = nil
  343. function checkDial(dialX, dialY)
  344.   dialXPos, dialYPos = nil, nil
  345.   if clickables[num][5] == 1 then
  346.     dialXPos, dialYPos = dialX, dialY + 3
  347.   elseif clickables[num][5] == 2 then
  348.     dialXPos, dialYPos = dialX - 1, clickables[num][6] --
  349.   elseif clickables[num][5] == 3 then
  350.     dialXPos, dialYPos = dialX, dialY
  351.   elseif clickables[num][5] == 4 then
  352.     dialXPos, dialYPos = clickables[num][6], dialY - 1 ---
  353.   elseif clickables[num][5] == 5 then
  354.     dialXPos, dialYPos = dialX + 4, dialY
  355.   elseif clickables[num][5] == 6 then
  356.     dialXPos, dialYPos = dialX + 5, clickables[num][6] --
  357.   elseif clickables[num][5] == 7 then
  358.     dialXPos, dialYPos = dialX + 4, dialY + 3
  359.   end
  360.   mark = nil
  361.   if x >= dialXPos - 1 and x <= dialXPos + 1 and y >= dialYPos - 1 and y <= dialYPos + 1 then
  362.     if x <= dialX and y >= dialY + 3 then
  363.       xPos, yPos = dialX, dialY + 3
  364.       mark = "/"
  365.       clickables[num][5] = 1
  366.       clickables[num][6] = nil
  367.       response = 1
  368.     elseif x < dialX and y > dialY and y < dialY + 3 then --
  369.       xPos, yPos = dialX - 1, y
  370.       mark = "-"
  371.       clickables[num][5] = 2
  372.       clickables[num][6] = y
  373.       response = 2
  374.     elseif x <= dialX and y <= dialY then
  375.       xPos, yPos = dialX, dialY
  376.       mark = "\\"
  377.       clickables[num][5] = 3
  378.       clickables[num][6] = nil
  379.       response = 3
  380.     elseif x > dialX and x < dialX + 4 and y < dialY then ---
  381.       xPos, yPos = x, dialY - 1
  382.       mark = "|"
  383.       clickables[num][5] = 4
  384.       clickables[num][6] = x
  385.       response = 4
  386.     elseif x >= dialX + 4 and y <= dialY then
  387.       xPos, yPos = dialX + 4, dialY
  388.       mark = "/"
  389.       clickables[num][5] = 5
  390.       clickables[num][6] = nil
  391.       response = 5
  392.     elseif x > dialX + 4 and y < dialY + 3 then --
  393.       xPos, yPos = dialX + 5, y
  394.       mark = "-"
  395.       clickables[num][5] = 6
  396.       clickables[num][6] = y
  397.       response = 6
  398.     elseif x >= dialX + 4 and y >= dialY + 3 then
  399.       xPos, yPos = dialX + 4, dialY + 3
  400.       mark = "\\"
  401.       clickables[num][5] = 7
  402.       clickables[num][6] = nil
  403.       response = 7
  404.     end
  405.     if mark then
  406.       term.setBackgroundColor(colors.black)
  407.       term.setCursorPos(dialX, dialY + 3)
  408.       term.write(" ")
  409.       term.setCursorPos(dialX - 1, dialY + 2)
  410.       term.write(" ")
  411.       term.setCursorPos(dialX - 1, dialY + 1)
  412.       term.write(" ")
  413.       term.setCursorPos(dialX, dialY)
  414.       term.write(" ")
  415.       term.setCursorPos(dialX + 1, dialY - 1)
  416.       term.write(" ")
  417.       term.setCursorPos(dialX + 2, dialY - 1)
  418.       term.write(" ")
  419.       term.setCursorPos(dialX + 3, dialY - 1)
  420.       term.write(" ")
  421.       term.setCursorPos(dialX + 4, dialY)
  422.       term.write(" ")
  423.       term.setCursorPos(dialX + 5, dialY + 1)
  424.       term.write(" ")
  425.       term.setCursorPos(dialX + 5, dialY + 2)
  426.       term.write(" ")
  427.       term.setCursorPos(dialX + 4, dialY + 3)
  428.       term.write(" ")
  429.       term.setBackgroundColor(colors.lightGray)
  430.       term.setCursorPos(xPos, yPos)
  431.       term.write(mark)
  432.     end
  433.   end
  434. end
  435.  
  436. ------======CHECKS ALL 4 TYPES EVERY TIME THERE IS A CLICK======------
  437. function clickCheck()
  438.   response = nil
  439.   --print(x, " ", y, " ", m, " ", i)
  440.   if m == 1 and x >= clickables[num][1] - 1 and x <= clickables[num][1] + 5 and y >= clickables[num][2] - 1 and y <= clickables[num][2] + 4 then
  441.     if clickables[num][4] == "Dial" and e == "mouse_drag" then
  442.       checkDial(clickables[num][1], clickables[num][2])
  443.     elseif clickables[num][4] == "Button" and e == "mouse_click" then
  444.       checkButton(clickables[num][1], clickables[num][2])
  445.     end
  446.   end
  447.   if clickables[num][4] == "Switch" then
  448.     checkSwitch(clickables[num][1], clickables[num][2])
  449.   elseif clickables[num][4] == "Slider" and e == "mouse_drag" then
  450.     checkSlider(clickables[num][1], clickables[num][2])
  451.   end
  452. end
  453.  
  454. function click()
  455.   e, m, x, y = os.pullEvent("mouse_click")
  456. end
  457.  
  458. function drag()
  459.   e, m, x, y = os.pullEvent("mouse_drag")
  460. end
  461.  
  462. ------======START MENU======------
  463. --defSwitch(5, 11, "X", false, "StartX")
  464. --defSwitch(11, 10, "Y", true, "StartY")
  465. --defSlider(11, 8, "X", "StartX")
  466. --defSlider(11, 12, "Y", "StartY")
  467. --defButton(11, 10, false, "Start")
  468. defDial(11, 10, "Start")
  469. while not start do
  470.   e, m, x, y = nil, nil, nil, nil
  471.   parallel.waitForAny(click, drag)
  472.   num = 1
  473.   for i = 1, #clickables do
  474.     clickCheck()
  475.     num = num + 1
  476.     if response == 7 then
  477.       start = true
  478.     end
  479.   end
  480. end
  481.  
  482. sleep(.3)
  483. term.setBackgroundColor(colors.black)
  484. term.clear()
  485. sleep(.3)
  486. term.setBackgroundColor(colors.gray)
  487. term.clear()
  488. sleep(.3)
  489. term.setBackgroundColor(colors.lightGray)
  490. term.clear()
  491. sleep(.3)
  492. term.setBackgroundColor(colors.white)
  493. term.clear()
  494. sleep(.3)
  495.  
  496.  
  497. ------======COMPUTERS CONNECT======------
  498. term.setBackgroundColor(colors.black)
  499. term.clear()
  500. spacewrite("Searching for signals...", 2, 1, colors.white, colors.black)
  501. clickables = {}
  502. response = nil
  503. local id = nil
  504. local host = nil
  505. local cast = "ping"
  506. local connected = false
  507. while not connected do
  508.   rednet.broadcast(cast)
  509.   spacewrite("Searching for signals...", 2, 1, colors.white, colors.black)
  510.   local randX = math.random(1, w)
  511.   local randY = math.random(2, h)
  512.   local randMark = math.random(1, 2)
  513.   if randMark == 1 then
  514.     spacewrite("*", randX, randY, colors.white, colors.black)
  515.   else
  516.     spacewrite(" ", randX, randY, colors.white, colors.black)
  517.   end
  518.   --print(cast .. "...")
  519.   otherID, response = rednet.receive(.01)
  520.   if response == "ping" or response == "ready" then
  521.     id = otherID
  522.     host = true
  523.     --print("Ping Recieved")
  524.   end
  525.   if id then cast = "ready" end
  526.   if response == "ready" and id then
  527.     rednet.send(id, "ready")
  528.     connected = true
  529.     term.clear()
  530.     term.setCursorPos(1, 1)
  531.     --print("Connected to id: " ..id)
  532.   end
  533. end
  534.  
  535. term.setBackgroundColor(colors.black)
  536. term.clear()
  537. for i = w, -8, -1 do
  538.   term.setBackgroundColor(colors.white)
  539.   term.clear()
  540.   spacewrite("Team Up!", i, 10, colors.lightBlue, colors.white)
  541.   sleep(.01)
  542.   term.setBackgroundColor(colors.black)
  543.   term.clear()
  544.   spacewrite("Team Up!", i, 10, colors.orange, colors.black)
  545.   sleep(.01)
  546. end
  547.  
  548. function receive()
  549.   e, id, message = os.pullEvent("rednet_message")
  550. end
  551.  
  552. function key()
  553.   e, string = os.pullEvent("char")
  554.   --rednet.send(id, string)
  555. end
  556.  
  557.  
  558. ------======TICK======------
  559. local toggle = false
  560. local tickcount = 0
  561. function tick()
  562.   countnum = countnum - .4
  563.   spacewrite("  ", done + 2, 1, colors.white, colors.lightGray)
  564.   tickcount = tickcount + 1
  565.   if tickcount >= 1 then
  566.     if toggle then
  567.       toggle = false
  568.       term.setBackgroundColor(colors.blue)
  569.     else
  570.       toggle = true
  571.       term.setBackgroundColor(colors.lightBlue)
  572.     end
  573.     tickcount = 0
  574.   end
  575.   term.setCursorPos(done + 1, 1)
  576.   term.write(" ")
  577.   rednet.send(id, taskwrite)
  578.   --sleep(.1)
  579.   os.startTimer(.4)
  580. end
  581.  
  582.  
  583. ------======PANEL GENERATOR======------
  584. names = {"Quark", "Zions", "Alias", "Zen", "Quigo", "Zefyr", "Plag", "Swurt", "Fork", "Arp", "Dilk", "Frazz", "Cacim", "Mcalk", "Rish", "Vilin", "Pagel", "Entio", "Ishop", "Takil", "Rouk", "Pon", "Lapor", "Xylph", "V-net", "X-gab", "F-win", "L-map", "D-op", "W-yam", "Geysu", "Gick", "Pflap", "Aport"}
  585. function generateConsole()
  586. local genX = 2
  587. local genY = 7
  588. local genW = 0
  589. local genH = 0
  590. local genDir = 0
  591. local genDirMax = 0
  592. local genName = nil
  593. local genState = nil
  594. local topGenW = 0
  595.   term.setBackgroundColor(colors.black)
  596.   term.clear()
  597.   clickables = {}
  598.   genNameUsed = {}
  599.   while true do
  600.     genName = math.random(1, #names)
  601.     if not genNameUsed[genName] then
  602.       genNameUsed[genName] = true
  603.       genName = names[genName]
  604.       genMax = 0
  605.       if w - genX >= 11 then
  606.         genMax = 4
  607.       elseif w - genX >= 7 then
  608.         genMax = 3
  609.       elseif w - genX < 7 then
  610.         --generation completed
  611.         break
  612.       end
  613.       if w - genX < 9 then
  614.         genDirMax = 1
  615.       else
  616.         genDirMax = 2
  617.       end
  618.       type = math.random(1, genMax)
  619.       if type == 1 then
  620.         type = "Button"
  621.         genW = 7
  622.         genH = 8
  623.         genState = math.random(0, 1)
  624.         if genState == 1 then
  625.           genState = true
  626.         elseif genState == 0 then
  627.           genState = false
  628.         end
  629.       elseif type == 2 then
  630.         type = "Slider"
  631.         genDir = math.random(1, genDirMax)
  632.         if genDir == 1 then
  633.           genDir = "Y"
  634.           genW = 7
  635.           genH = 11
  636.         elseif genDir == 2 then
  637.           genDir = "X"
  638.           genW = 9
  639.           genH = 5
  640.         end
  641.       elseif type == 3 then
  642.         type = "Switch"
  643.         genDir = math.random(1, 2)
  644.         if genDir == 1 then
  645.           genDir = "Y"
  646.           genW = 7
  647.           genH = 13
  648.         elseif genDir == 2 then
  649.           genDir = "X"
  650.           genW = 11
  651.           genH = 5
  652.         end
  653.         genState = math.random(0, 1)
  654.         if genState == 1 then
  655.           genState = true
  656.         elseif genState == 0 then
  657.           genState = false
  658.         end
  659.       elseif type == 4 then
  660.         type = "Dial"
  661.         genW = 11
  662.         genH = 10
  663.       end
  664.       if genY == 7 then
  665.         topGenW = genW
  666.       end
  667.       if genY + genH > h then
  668.         genX = genX + topGenW
  669.         genY = 7
  670.       else
  671.         if type == "Button" then
  672.           defButton(genX + 1, genY + 1, genState, genName)
  673.         elseif type == "Slider" then
  674.           if genDir == "X" then
  675.             defSlider(genX + 1, genY + 2, genDir, genName)
  676.           elseif genDir == "Y" then
  677.             defSlider(genX + 3, genY + 1, genDir, genName)
  678.           end
  679.         elseif type == "Switch" then
  680.           if genDir == "X" then
  681.             defSwitch(genX + 5, genY + 2, genDir, genState, genName)
  682.           elseif genDir == "Y" then
  683.             defSwitch(genX + 3, genY + 5, genDir, genState, genName)
  684.           end
  685.         elseif type == "Dial" then
  686.           defDial(genX + 3, genY + 3, genName)
  687.         end
  688.         --term.setCursorPos(genX, genY)
  689.         --term.write("x")
  690.         --genX = genX + genW
  691.         genY = genY + genH
  692.         --term.setCursorPos(genX, genY)
  693.         --term.write("y")
  694.       end
  695.     end
  696.   end
  697. end
  698.  
  699. ------======ACTUAL GAME======------
  700. keys = {"q","w","e","r","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"}
  701. done = 0
  702. sector = 1
  703. countnum = nil
  704. newtask = nil
  705. taskwrite = nil
  706. local alive = true
  707. local event = {}
  708. initialized = false
  709. countnum = 13 - sector
  710. generateConsole()
  711. os.startTimer(.4)
  712. while alive do
  713.   taskwrite = nil
  714.   task = math.random(1, #clickables + 1)
  715.   if task == #clickables + 1 then
  716.     task = keys[math.random(1, 26)]
  717.     taskwrite = "Press " .. task
  718.     clickablenum = nil
  719.   else
  720.     clickablenum = task
  721.     if clickables[task][4] == "Button" then
  722.       if clickables[task][5] == false then
  723.         taskwrite = "Engage " .. clickables[task][3]
  724.         task = true
  725.       else
  726.         taskwrite = "Disengage " .. clickables[task][3]
  727.         task = false
  728.       end
  729.     elseif clickables[task][4] == "Slider" then
  730.       taskRand = math.random(0, 3)
  731.       while clickables[task][5] == taskRand do
  732.         taskRand = math.random(0, 3)
  733.       end
  734.       taskwrite = "Set " .. clickables[task][3] .. " to " .. tostring(taskRand)
  735.       task = taskRand
  736.     elseif clickables[task][4] == "Switch" then
  737.       if clickables[task][5] == false then
  738.         taskwrite = "Activate " .. clickables[task][3]
  739.         task = true
  740.       else
  741.         taskwrite = "Deactivate " .. clickables[task][3]
  742.         task = false
  743.       end
  744.     elseif clickables[task][4] == "Dial" then
  745.       taskRand = math.random(1, 7)
  746.       while clickables[task][5] == taskRand do
  747.         taskRand = math.random(1, 7)
  748.       end
  749.       taskwrite = "Set " .. clickables[task][3] .. " to " .. tostring(taskRand)
  750.       task = taskRand
  751.     end
  752.   end
  753.   rednet.send(id, taskwrite)
  754.   cast = taskwrite
  755.   while not initialized do
  756.     response = nil
  757.     rednet.send(id, cast)
  758.     otherID, response = rednet.receive(.01)
  759.     if response and response ~= "complete" and response ~= "init" and response ~= "dead" and response ~= "nextsector" and response ~= "go" then
  760.       newtask = response
  761.       cast = "init"
  762.     end
  763.     if response == "init" and newtask then
  764.       rednet.send(id, "init")
  765.       initialized = true
  766.     end
  767.   end
  768.   --spacewrite(tostring(done) .. " tasks completed...", 1, 3, colors.white, colors.black)
  769.   complete = false
  770.   while not complete do
  771.     spacewrite("Sector: " .. tostring(sector), 9, 2, colors.white, colors.black)
  772.     spacewrite("                          ", 1, 4, colors.white, colors.black)
  773.     newtask = assert(newtask, "ERROR: newtask is nil")
  774.     spacewrite(newtask, 1, 4, colors.white, colors.black)
  775.     spacewrite("                          ", 1, 5)
  776.     if (countnum / (13 - sector)) > .75 then
  777.       term.setBackgroundColor(colors.lime)
  778.     elseif (countnum / (13 - sector)) > .5 then
  779.       term.setBackgroundColor(colors.yellow)
  780.     elseif (countnum / (13 - sector)) > .25 then
  781.       term.setBackgroundColor(colors.orange)
  782.     else
  783.       term.setBackgroundColor(colors.red)
  784.     end
  785.     term.setCursorPos(1, 5)
  786.     for i = 1, (countnum / (13 - sector)) * w do
  787.       term.write(" ")
  788.     end
  789.     --term.setCursorPos(1, h)
  790.     --term.write(countnum)
  791.     e, m, x, y, string, message = nil, nil, nil, nil, nil, nil
  792.     --parallel.waitForAny(receive, key, tick, click, drag)
  793.     event = {os.pullEventRaw()}
  794.     if event[1] == "timer" then
  795.       tick()
  796.     elseif event[1] == "mouse_click" then
  797.       e, m, x, y = event[1], event[2], event[3], event[4]
  798.     elseif event[1] == "mouse_drag" then
  799.       e, m, x, y = event[1], event[2], event[3], event[4]
  800.     elseif event[1] == "rednet_message" then
  801.       otherID, message = event[2], event[3]
  802.     elseif event[1] == "key" then
  803.       string = event[2]
  804.     end
  805.     num = 1
  806.     if message and message ~= "complete" and message ~= "init" and message ~= "dead" and message ~= "nextsector" and message ~= "go" then
  807.       newtask = message
  808.     end
  809.     if x and y then
  810.       for i = 1, #clickables do
  811.         clickCheck()
  812.         num = num + 1
  813.         if clickablenum and clickables[clickablenum][5] == task then
  814.           rednet.send(id, "complete")
  815.           complete = true
  816.           done = done + 1
  817.           term.setCursorPos(done, 1)
  818.           term.setBackgroundColor(colors.black)
  819.           term.write(" ")
  820.         end
  821.       end
  822.     end
  823.     --if complete then break end
  824.     if not clickablenum and string == task then
  825.       rednet.send(id, "complete")
  826.       complete = true
  827.       done = done + 1
  828.       term.setCursorPos(done, 1)
  829.       term.setBackgroundColor(colors.black)
  830.       term.write(" ")
  831.     end
  832.     if message == "complete" then
  833.       countnum = 13 - sector
  834.       --otherID, newtask = rednet.receive(.1)
  835.       done = done + 1
  836.       term.setCursorPos(done, 1)
  837.       term.setBackgroundColor(colors.black)
  838.       term.write(" ")
  839.       spacewrite("                          ", 1, 4, colors.white, colors.lime)
  840.       sleep(.01)
  841.       spacewrite("                          ", 1, 4, colors.white, colors.black)
  842.     end
  843.     if done >= 24 or message == "nextsector" then
  844.       movingon = false
  845.       ready = false
  846.       cast = "nextsector"
  847.       while not movingon do
  848.         response = nil
  849.         rednet.send(id, cast)
  850.         otherID, response = rednet.receive(.01)
  851.         if response == "nextsector" or response == "go" then
  852.           cast = "go"
  853.           ready = true
  854.         end
  855.         if response == "go" and ready then
  856.           rednet.send(id, "nextsector")
  857.           rednet.send(id, "go")
  858.           movingon = true
  859.         end
  860.       end
  861.       term.setCursorPos(1, 1)
  862.       term.setBackgroundColor(colors.white)
  863.       term.setTextColor(colors.black)
  864.       textutils.slowPrint("       HYPERSPACE!!!      ")
  865.       sleep(.3)
  866.       term.setBackgroundColor(colors.white)
  867.       term.clear()
  868.       sleep(.3)
  869.       term.setBackgroundColor(colors.lightGray)
  870.       term.clear()
  871.       sleep(.3)
  872.       term.setBackgroundColor(colors.gray)
  873.       term.clear()
  874.       sleep(.3)
  875.       term.setBackgroundColor(colors.black)
  876.       term.clear()
  877.       sleep(.3)
  878.       term.setTextColor(colors.white)
  879.       sector = sector + 1
  880.       initialized = false
  881.       done = 0
  882.       newtask = nil
  883.       taskwrite = nil
  884.       countnum = 13 - sector
  885.       spacewrite("  ", 25, 1, colors.white, colors.black)
  886.       generateConsole()
  887.       os.startTimer(.4)
  888.       complete = true
  889.     end
  890.     if countnum <= 0 or message == "dead" then
  891.       term.setCursorPos(1, h)
  892.       term.setBackgroundColor(colors.red)
  893.       rednet.send(id, "dead")
  894.       textutils.slowPrint("Critical Failiure...")
  895.       alive = false
  896.       break
  897.     end
  898.   end
  899. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement