CaptainSpaceCat

Spaceteam Letters

May 26th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.88 KB | None | 0 0
  1. rednet.open("back")
  2. function spacewrite(string, x, y, txtcol, bakcol)
  3.   if txtcol then
  4.     term.setTextColor(txtcol)
  5.   end
  6.   if bakcol then
  7.     term.setBackgroundColor(bakcol)
  8.   end
  9.   term.setCursorPos(x, y)
  10.   term.write(string)
  11. end
  12. w, h = term.getSize()
  13. term.setBackgroundColor(colors.black)
  14. term.clear()
  15. local logo = paintutils.loadImage("space.nfp")
  16. local dial = paintutils.loadImage("dial.nfp")
  17. local sliderX = paintutils.loadImage("sliderX.nfp")
  18. local sliderY = paintutils.loadImage("sliderY.nfp")
  19. local buttonOn = paintutils.loadImage("buttonOn.nfp")
  20. local buttonOff = paintutils.loadImage("buttonOff.nfp")
  21. paintutils.drawImage(logo, 10, 2)
  22. spacewrite("SpaceTeam", 9, 5, colors.white, colors.black)
  23. --spacewrite("Start Game", 9, h, colors.white, colors.black)
  24. local start = false
  25. local x = nil
  26. local y = nil
  27. local tempX = nil
  28. local tempY = nil
  29. clickables = {}
  30.  
  31. function defDial(dialX, dialY, dialName)
  32.   clickables[#clickables + 1] = {}
  33.     clickables[#clickables][1] = dialX
  34.     clickables[#clickables][2] = dialY
  35.     clickables[#clickables][3] = dialName
  36.     clickables[#clickables][4] = "Dial"
  37.     clickables[#clickables][5] = 1
  38.   paintutils.drawImage(dial, dialX, dialY)
  39.   term.setCursorPos(dialX, dialY + 3)
  40.   term.setBackgroundColor(colors.lightGray)
  41.   term.write("/")
  42.   term.setBackgroundColor(colors.black)
  43.   term.setCursorPos(dialX - 1, dialY + 4)
  44.   term.write("1")
  45.   term.setCursorPos(dialX - 2, dialY + 1)
  46.   term.write("2")
  47.   term.setCursorPos(dialX - 1, dialY - 1)
  48.   term.write("3")
  49.   term.setCursorPos(dialX + 2, dialY - 2)
  50.   term.write("4")
  51.   term.setCursorPos(dialX + 5, dialY - 1)
  52.   term.write("5")
  53.   term.setCursorPos(dialX + 6, dialY + 1)
  54.   term.write("6")
  55.   term.setCursorPos(dialX + 5, dialY + 4)
  56.   term.write("7")
  57.   term.setCursorPos(dialX - #dialName / 2 + 3, dialY + 5)
  58.   term.write(dialName)
  59. end
  60.  
  61. function defSwitch(switchX, switchY, switchDir, switchState, switchName)
  62.   clickables[#clickables + 1] = {}
  63.     clickables[#clickables][1] = switchX
  64.     clickables[#clickables][2] = switchY
  65.     clickables[#clickables][3] = switchName
  66.     clickables[#clickables][4] = "Switch"
  67.     clickables[#clickables][5] = switchState
  68.     clickables[#clickables][6] = switchDir
  69.   term.setCursorPos(switchX, switchY)
  70.   term.setBackgroundColor(colors.gray)
  71.   term.write(" ")
  72.   term.setBackgroundColor(colors.lightGray)
  73.   if switchDir == "X" then
  74.     if switchState == true then
  75.       term.setCursorPos(switchX + 1, switchY)
  76.       term.write("   ")
  77.     else
  78.       term.setCursorPos(switchX - 3, switchY)
  79.       term.write("   ")
  80.     end
  81.     term.setBackgroundColor(colors.black)
  82.     term.setCursorPos(switchX + 4, switchY)
  83.     term.write("O")
  84.     term.setCursorPos(switchX - 4, switchY)
  85.     term.write("X")
  86.     term.setCursorPos(switchX - #switchName / 2 + 1, switchY + 1)
  87.     term.write(switchName)
  88.   elseif switchDir == "Y" then
  89.     if switchState == true then
  90.       for i = 3, 1, -1 do
  91.         term.setCursorPos(switchX, switchY - i)
  92.         term.write(" ")
  93.       end
  94.     else
  95.       for i = 1, 3 do
  96.         term.setCursorPos(switchX, switchY + i)
  97.         term.write(" ")
  98.       end
  99.     end
  100.     term.setBackgroundColor(colors.black)
  101.     term.setCursorPos(switchX, switchY - 4)
  102.     term.write("O")
  103.     term.setCursorPos(switchX, switchY + 4)
  104.     term.write("X")
  105.     term.setCursorPos(switchX - #switchName / 2 + 1, switchY + 5)
  106.     term.write(switchName)
  107.   end
  108. end
  109.  
  110. function defButton(butX, butY, butState, butName)
  111.   clickables[#clickables + 1] = {}
  112.     clickables[#clickables][1] = butX
  113.     clickables[#clickables][2] = butY
  114.     clickables[#clickables][3] = butName
  115.     clickables[#clickables][4] = "Button"
  116.     clickables[#clickables][5] = butState
  117.   term.setCursorPos(butX - #butName / 2 + 3, butY + 5)
  118.   term.write(butName)
  119.   if butState == true then
  120.     paintutils.drawImage(buttonOn, butX, butY)
  121.   else
  122.     paintutils.drawImage(buttonOff, butX, butY)
  123.   end
  124. end
  125.  
  126. function defSlider(slideX, slideY, slideDir, slideName)
  127.   clickables[#clickables + 1] = {}
  128.     clickables[#clickables][1] = slideX
  129.     clickables[#clickables][2] = slideY
  130.     clickables[#clickables][3] = slideName
  131.     clickables[#clickables][4] = "Slider"
  132.     clickables[#clickables][5] = 0
  133.     clickables[#clickables][6] = slideDir
  134.   term.setBackgroundColor(colors.black)
  135.   if slideDir == "X" then
  136.     for i = 0, 6 do
  137.       term.setCursorPos(slideX + i, slideY)
  138.       term.write("-")
  139.     end
  140.     for i = 0, 3 do
  141.       term.setCursorPos(slideX + i * 2, slideY - 1)
  142.       term.write(i)
  143.     end
  144.     paintutils.drawImage(sliderX, slideX - 1, slideY)
  145.   term.setCursorPos(slideX, slideY + 1)
  146.   term.write(slideName)
  147.   elseif slideDir == "Y" then
  148.     for i = 0, 6 do
  149.       term.setCursorPos(slideX, slideY + i)
  150.       term.write("|")
  151.     end
  152.     for i = 0, 3 do
  153.       term.setCursorPos(slideX - 1, slideY + 6 - i * 2)
  154.       term.write(i)
  155.     end
  156.     paintutils.drawImage(sliderY, slideX, slideY + 5)
  157.   term.setCursorPos(slideX - #slideName / 2 + 3, slideY + 8)
  158.   term.write(slideName)
  159.   end
  160. end
  161.  
  162. function checkSwitch(switchX, switchY)
  163.   if e == "mouse_click" then
  164.     tempX = x
  165.     tempY = y
  166.   end
  167.   if clickables[num][6] == "X" then
  168.     if clickables[num][5] == true then
  169.       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
  170.         clickables[num][5] = false
  171.         response = false
  172.       end
  173.     else
  174.       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
  175.         clickables[num][5] = true
  176.         response = true
  177.       end
  178.     end
  179.     term.setCursorPos(switchX - 3, switchY)
  180.     if clickables[num][5] == true then
  181.       term.setBackgroundColor(colors.black)
  182.     else
  183.       term.setBackgroundColor(colors.lightGray)
  184.     end
  185.     term.write("   ")
  186.     term.setCursorPos(switchX + 1, switchY)
  187.     if clickables[num][5] == true then
  188.       term.setBackgroundColor(colors.lightGray)
  189.     else
  190.       term.setBackgroundColor(colors.black)
  191.     end
  192.     term.write("   ")
  193.   elseif clickables[num][6] == "Y" then
  194.     if clickables[num][5] == true then
  195.       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
  196.         clickables[num][5] = false
  197.         response = false
  198.       end
  199.     else
  200.       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
  201.         clickables[num][5] = true
  202.         response = true
  203.       end
  204.     end
  205.     if clickables[num][5] == true then
  206.       term.setBackgroundColor(colors.lightGray)
  207.     else
  208.       term.setBackgroundColor(colors.black)
  209.     end
  210.     for i = 3, 1, -1 do
  211.       term.setCursorPos(switchX, switchY - i)
  212.       term.write(" ")
  213.     end
  214.     if clickables[num][5] == true then
  215.       term.setBackgroundColor(colors.black)
  216.     else
  217.       term.setBackgroundColor(colors.lightGray)
  218.     end
  219.     for i = 1, 3 do
  220.       term.setCursorPos(switchX, switchY + i)
  221.       term.write(" ")
  222.     end
  223.   end
  224. end
  225.  
  226. function checkButton(butX, butY)
  227.   if clickables[num][5] == true then
  228.     clickables[num][5] = false
  229.     term.setCursorPos(butX, butY)
  230.     paintutils.drawImage(buttonOff, butX, butY)
  231.     response = false
  232.   else
  233.     clickables[num][5] = true
  234.     term.setCursorPos(butX, butY)
  235.     paintutils.drawImage(buttonOn, butX, butY)
  236.     response = true
  237.   end
  238. end
  239.  
  240. function checkSlider(slideX, slideY)
  241.   term.setBackgroundColor(colors.black)
  242.   if clickables[num][6] == "X" and m == 1 and (x >= clickables[num][1] + clickables[num][5] - 1 and x <= clickables[num][1] + clickables[num][5] + 1) and (x >= clickables[num][1] and x <= clickables[num][1] + 6) and y == clickables[num][2] and e == "mouse_drag" then
  243.     for i = 0, 6 do
  244.       term.setCursorPos(slideX + i, slideY)
  245.       term.write("-")
  246.     end
  247.     term.setCursorPos(slideX - 1, slideY)
  248.     term.write(" ")
  249.     term.setCursorPos(slideX + 7, slideY)
  250.     term.write(" ")
  251.     paintutils.drawImage(sliderX, x - 1, y)
  252.     clickables[num][5] = x - slideX
  253.     response = (x - slideX) / 2
  254.   elseif clickables[num][6] == "Y" and m == 1 and (y >= clickables[num][2] + clickables[num][5] - 1 and y <= clickables[num][2] + clickables[num][5] + 1) and (y >= clickables[num][2] and y <= clickables[num][2] + 6) and x == clickables[num][1] and e == "mouse_drag" then
  255.     for i = 0, 6 do
  256.       term.setCursorPos(slideX, slideY + i)
  257.       term.write("|")
  258.     end
  259.     term.setCursorPos(slideX, slideY - 1)
  260.     term.write(" ")
  261.     term.setCursorPos(slideX, slideY + 7)
  262.     term.write(" ")
  263.     paintutils.drawImage(sliderY, x, y - 1)
  264.     clickables[num][5] = y - slideY
  265.     response = (slideY + 6 - y) / 2
  266.   end
  267. end
  268.  
  269. function checkDial(dialX, dialY)
  270.   term.setBackgroundColor(colors.black)
  271.   term.setCursorPos(dialX, dialY + 3)
  272.   term.write(" ")
  273.   term.setCursorPos(dialX - 1, dialY + 2)
  274.   term.write(" ")
  275.   term.setCursorPos(dialX - 1, dialY + 1)
  276.   term.write(" ")
  277.   term.setCursorPos(dialX, dialY)
  278.   term.write(" ")
  279.   term.setCursorPos(dialX + 1, dialY - 1)
  280.   term.write(" ")
  281.   term.setCursorPos(dialX + 2, dialY - 1)
  282.   term.write(" ")
  283.   term.setCursorPos(dialX + 3, dialY - 1)
  284.   term.write(" ")
  285.   term.setCursorPos(dialX + 4, dialY)
  286.   term.write(" ")
  287.   term.setCursorPos(dialX + 5, dialY + 1)
  288.   term.write(" ")
  289.   term.setCursorPos(dialX + 5, dialY + 2)
  290.   term.write(" ")
  291.   term.setCursorPos(dialX + 4, dialY + 3)
  292.   term.write(" ")
  293.   if x <= dialX and y >= dialY + 3 then
  294.     xPos, yPos = dialX, dialY + 3
  295.     mark = "/"
  296.     clickables[num][5] = 1
  297.     response = 1
  298.   elseif x < dialX and y > dialY and y < dialY + 3 then
  299.     xPos, yPos = dialX - 1, y
  300.     mark = "-"
  301.     clickables[num][5] = 2
  302.     response = 2
  303.   elseif x <= dialX and y <= dialY then
  304.     xPos, yPos = dialX, dialY
  305.     mark = "\\"
  306.     clickables[num][5] = 3
  307.     response = 3
  308.   elseif x > dialX and x < dialX + 4 and y < dialY then
  309.     xPos, yPos = x, dialY - 1
  310.     mark = "|"
  311.     clickables[num][5] = 4
  312.     response = 4
  313.   elseif x >= dialX + 4 and y <= dialY then
  314.     xPos, yPos = dialX + 4, dialY
  315.     mark = "/"
  316.     clickables[num][5] = 5
  317.     response = 5
  318.   elseif x > dialX + 4 and y < dialY + 3 then
  319.     xPos, yPos = dialX + 5, y
  320.     mark = "-"
  321.     clickables[num][5] = 6
  322.     response = 6
  323.   elseif x >= dialX + 4 and y >= dialY + 3 then
  324.     xPos, yPos = dialX + 4, dialY + 3
  325.     mark = "\\"
  326.     clickables[num][5] = 7
  327.     response = 7
  328.   end
  329.   term.setBackgroundColor(colors.lightGray)
  330.   term.setCursorPos(xPos, yPos)
  331.   term.write(mark)
  332. end
  333.  
  334. function clickCheck()
  335.   response = nil
  336.   --print(x, " ", y, " ", m, " ", i)
  337.   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
  338.     if clickables[num][4] == "Dial" and e == "mouse_drag" then
  339.       checkDial(clickables[num][1], clickables[num][2])
  340.     elseif clickables[num][4] == "Button" and e == "mouse_click" then
  341.       checkButton(clickables[num][1], clickables[num][2])
  342.     end
  343.   end
  344.   if clickables[num][4] == "Switch" then
  345.     checkSwitch(clickables[num][1], clickables[num][2])
  346.   elseif clickables[num][4] == "Slider" and e == "mouse_drag" then
  347.     checkSlider(clickables[num][1], clickables[num][2])
  348.   end
  349. end
  350.  
  351. function click()
  352.   e, m, x, y = os.pullEvent("mouse_click")
  353. end
  354.  
  355. function drag()
  356.   e, m, x, y = os.pullEvent("mouse_drag")
  357. end
  358.  
  359.  
  360. --defSwitch(5, 11, "X", false, "StartX")
  361. --defSwitch(11, 10, "Y", true, "StartY")
  362. --defSlider(11, 8, "X", "StartX")
  363. --defSlider(11, 12, "Y", "StartY")
  364. --defButton(11, 10, false, "Start")
  365. defDial(11, 10, "Start")
  366. while not start do
  367.   e, m, x, y = nil, nil, nil, nil
  368.   parallel.waitForAny(click, drag)
  369.   num = 1
  370.   for i = 1, #clickables do
  371.     clickCheck()
  372.     num = num + 1
  373.     if response == 7 then
  374.       start = true
  375.     end
  376.   end
  377. end
  378.  
  379. sleep(.3)
  380. term.setBackgroundColor(colors.black)
  381. term.clear()
  382. sleep(.3)
  383. term.setBackgroundColor(colors.gray)
  384. term.clear()
  385. sleep(.3)
  386. term.setBackgroundColor(colors.lightGray)
  387. term.clear()
  388. sleep(.3)
  389. term.setBackgroundColor(colors.white)
  390. term.clear()
  391. sleep(.3)
  392.  
  393. term.setBackgroundColor(colors.black)
  394. term.clear()
  395. spacewrite("Searching for signals...", 2, 1, colors.white, colors.black)
  396. clickables = {}
  397. response = nil
  398. local id = nil
  399. local host = nil
  400. local cast = "ping"
  401. local connected = false
  402. while not connected do
  403.   rednet.broadcast(cast)
  404.   spacewrite("Searching for signals...", 2, 1, colors.white, colors.black)
  405.   local randX = math.random(1, w)
  406.   local randY = math.random(2, h)
  407.   local randMark = math.random(1, 2)
  408.   if randMark == 1 then
  409.     spacewrite("*", randX, randY, colors.white, colors.black)
  410.   else
  411.     spacewrite(" ", randX, randY, colors.white, colors.black)
  412.   end
  413.   --print(cast .. "...")
  414.   otherID, response = rednet.receive(.01)
  415.   if response == "ping" or response == "ready" then
  416.     id = otherID
  417.     host = true
  418.     --print("Ping Recieved")
  419.   end
  420.   if id then cast = "ready" end
  421.   if response == "ready" and id then
  422.     rednet.broadcast("ready")
  423.     connected = true
  424.     term.clear()
  425.     term.setCursorPos(1, 1)
  426.     --print("Connected to id: " ..id)
  427.   end
  428. end
  429.  
  430. term.setBackgroundColor(colors.black)
  431. term.clear()
  432. for i = w, -8, -1 do
  433.   term.setBackgroundColor(colors.white)
  434.   term.clear()
  435.   spacewrite("Team Up!", i, 10, colors.lightBlue, colors.white)
  436.   sleep(.01)
  437.   term.setBackgroundColor(colors.black)
  438.   term.clear()
  439.   spacewrite("Team Up!", i, 10, colors.orange, colors.black)
  440.   sleep(.01)
  441. end
  442.  
  443. function receive()
  444.   e, id, message = os.pullEvent("rednet_message")
  445. end
  446.  
  447. function key()
  448.   e, string = os.pullEvent("char")
  449.   rednet.send(id, string)
  450. end
  451.  
  452. local toggle = false
  453. function w8()
  454.   sleep(.1)
  455.   num = num - .1
  456.   spacewrite("  ", done + 2, 1, colors.white, colors.lightGray)
  457.   if toggle then
  458.     toggle = false
  459.     term.setBackgroundColor(colors.blue)
  460.   else
  461.     toggle = true
  462.     term.setBackgroundColor(colors.lightBlue)
  463.   end
  464.   term.setCursorPos(done + 1, 1)
  465.   term.write(" ")
  466. end
  467.  
  468. 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"}
  469. done = 0
  470. sector = 1
  471. local alive = true
  472. while alive do
  473.   num = 13 - sector
  474.   task = keys[math.random(1, 26)]
  475.   spacewrite("Press " .. task, 1, h - 1, colors.white, colors.black)
  476.   --spacewrite(tostring(done) .. " tasks completed...", 1, 3, colors.white, colors.black)
  477.   complete = false
  478.   while not complete do
  479.     spacewrite("Sector: " .. tostring(sector), 9, 2, colors.white, colors.black)
  480.     term.setBackgroundColor(colors.black)
  481.     spacewrite("                          ", 1, h, colors.white, colors.black)
  482.     if (num / 12) > .75 then
  483.       term.setBackgroundColor(colors.lime)
  484.     elseif (num / 12) > .5 then
  485.       term.setBackgroundColor(colors.yellow)
  486.     elseif (num / 12) > .25 then
  487.       term.setBackgroundColor(colors.orange)
  488.     else
  489.       term.setBackgroundColor(colors.red)
  490.     end
  491.     term.setCursorPos(1, h)
  492.     for i = 1, (num / 12) * w do
  493.       term.write(" ")
  494.     end
  495.     --term.setCursorPos(1, h)
  496.     --term.write(num)
  497.     string, message = nil, nil
  498.     parallel.waitForAny(receive, key, w8)
  499.     if message == task then
  500.       rednet.send(id, "complete")
  501.       complete = true
  502.       done = done + 1
  503.       term.setCursorPos(done, 1)
  504.       term.setBackgroundColor(colors.black)
  505.       term.write(" ")
  506.     end
  507.     if message == "complete" then
  508.       done = done + 1
  509.       term.setCursorPos(done, 1)
  510.       term.setBackgroundColor(colors.black)
  511.       term.write(" ")
  512.     end
  513.     if done == 24 then
  514.       sector = sector + 1
  515.       done = 0
  516.       spacewrite("  ", 25, 1, colors.white, colors.black)
  517.     end
  518.     if num <= 0 then
  519.       term.setCursorPos(1, h)
  520.       term.setBackgroundColor(colors.red)
  521.       textutils.slowPrint("Critical Failiure...")
  522.       alive = false
  523.       break
  524.     end
  525.   end
  526. end
Add Comment
Please, Sign In to add comment