Advertisement
CaptainSpaceCat

SpaceTeam Updated

Jun 2nd, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.46 KB | None | 0 0
  1. ------======LOCALIZED VARIABLES======------
  2. local w, h = term.getSize()
  3. local midW, midH = math.floor(w/2), math.floor(h/2)
  4. local events = {}
  5. local logo = {{0, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 0, 1, 1, 0}, {1, 1, 1, 0, 1, 1, 0}}
  6.  
  7. if not fs.exists("clickables") then
  8.     shell.run("pastebin get Je7BEsW3 clickables")
  9. end
  10. os.loadAPI("clickables")
  11.  
  12. ------======GAME FUNCTIONS======------
  13. function rednetTest()
  14.   rednet.open("back")
  15. end
  16. if not pcall(rednetTest) then
  17.   --error("ERROR: device must have wireless capability")
  18. end
  19.  
  20. if not fs.exists("clickables") then
  21.   shell.run("pastebin get Je7BEsW3 clickables")
  22. end
  23.  
  24. for i,v in pairs(colors) do
  25.     if tonumber(v) then
  26.         loadstring(i .. "=" .. v)()
  27.     end
  28. end
  29.  
  30. function draw(string, x, y, txtcol, bakcol)
  31.     string = string or ""
  32.     txtcol = txtcol or colors.white
  33.         bakcol = bakcol or colors.black
  34.     if not tonumber(x) then
  35.         x = x:gsub(" ", "")
  36.             if x:sub(1, 1) == "l" then
  37.                 if x:find("+") then
  38.                     offset = tonumber(x:sub(x:find("+") + 1))
  39.                     term.setCursorPos(1 + offset, y)
  40.                 else
  41.                     term.setCursorPos(1, y)
  42.                 end
  43.             elseif x:sub(1, 1) == "c" then
  44.                 if x:find("+") then
  45.                     offset = tonumber(x:sub(x:find("+") + 1))
  46.                     term.setCursorPos(w/2 - #string/2 + 1 + offset, y)
  47.             elseif x:find("-") then
  48.                     offset = tonumber(x:sub(x:find("-") + 1))
  49.                     term.setCursorPos(w/2 - #string/2 + 1 - offset, y)
  50.             else
  51.                     term.setCursorPos(w/2 - #string/2 + 1, y)
  52.             end
  53.             elseif x:sub(1, 1) == "r" then
  54.                 if x:find("-") then
  55.                     offset = tonumber(x:sub(x:find("-") + 1))
  56.                     term.setCursorPos(w - #string + 1 - offset, y)
  57.                 else
  58.                     term.setCursorPos(w - #string + 1, y)
  59.                 end
  60.         end
  61.     else
  62.             term.setCursorPos(x, y)
  63.     end
  64.     term.setBackgroundColor(bakcol)
  65.     term.setTextColor(txtcol)
  66.     term.write(string)
  67. end
  68.  
  69. function waitForSignal(receiverID, timeOut)
  70.     local signalTimer
  71.     if timeOut then
  72.         signalTimer = os.startTimer(timeOut)
  73.     end
  74.     while true do
  75.         if receiverID then
  76.                 rednet.send(receiverID, "ping")
  77.         else
  78.             rednet.broadcast("ping")
  79.         end
  80.         local events = {os.pullEvent()}
  81.         if events[1] == "rednet_message" and events[2] == "ping" then
  82.             rednet.send(events[2], "ping")
  83.             return events[2]
  84.         elseif signalTimer and events[1] == "timer" and events[2] == signalTimer then
  85.             break
  86.         end
  87.         coroutine.yield()
  88.     end
  89.     return false
  90. end
  91.  
  92. function starScreen()
  93.     while true do
  94.         randCheck = math.random(1, 3)
  95.         if randCheck == 1 then
  96.                 randY = math.random(2, h)
  97.                 while stars[randY] do
  98.                     randY = math.random(2, h)
  99.                 end
  100.                 stars[randY] = w
  101.         end
  102.         for i, v in pairs(stars) do
  103.                 if v < 1 then
  104.                     deleteprev = true
  105.                     term.setCursorPos(1, i)
  106.                     term.write(" ")
  107.                 else
  108.                     if deleteprev then
  109.                         if i == 2 then
  110.                             stars[h] = nil
  111.                         else
  112.                             stars[i - 1] = nil
  113.                         end
  114.                     end
  115.                     term.setCursorPos(v, i)
  116.                     term.write("*")
  117.                     term.setCursorPos(v + 1, i)
  118.                     term.write(" ")
  119.                     stars[i] = v - 1
  120.                     deleteprev = false
  121.                 end
  122.         end
  123.         coroutine.yield()
  124.     end
  125. end
  126.  
  127. function gameConnect()
  128.     local signal = coroutine.create(waitForSignal())
  129.     local stars = coroutine.create(starScreen())
  130.     while coroutine.status(signal) ~= "dead" do
  131.         coroutine.resume(signal)
  132.         print("stars next")
  133.         coroutine.resume(stars)
  134.         print("signal next")
  135.     end
  136. end
  137.  
  138. ------======MAIN MENU======------
  139. term.setBackgroundColor(colors.black)
  140. term.setTextColor(colors.white)
  141. term.clear()
  142. paintutils.drawImage(logo, midW - 3, 2)
  143. draw("Spaceteam", "c", 5, colors.white, colors.black)
  144. local Start = clickables.Dial:new("Start", midW - 2, 10)
  145. while true do
  146.   Start:display()
  147.   events = {}
  148.   clickables.getEvents()
  149.   --if Start:check() == 7 then
  150.     break
  151.   --end
  152. end
  153. sleep(.2)
  154. term.setBackgroundColor(colors.black)
  155. term.clear()
  156. sleep(.2)
  157. term.setBackgroundColor(colors.gray)
  158. term.clear()
  159. sleep(.2)
  160. term.setBackgroundColor(colors.lightGray)
  161. term.clear()
  162. sleep(.2)
  163. term.setBackgroundColor(colors.white)
  164. term.clear()
  165. sleep(.2)
  166. term.setBackgroundColor(colors.black)
  167. term.clear()
  168.  
  169. ------======SIGNAL SEARCH======------
  170. local stars = {}
  171. local deleteprev = false
  172. draw("Searching for signals...", 1, 1)
  173.  
  174.  
  175.  
  176. --[[while true do
  177.   id, message = nil, nil
  178.   randCheck = math.random(1, 3)
  179.   if randCheck == 1 then
  180.     randY = math.random(2, h)
  181.     while stars[randY] do
  182.       randY = math.random(2, h)
  183.     end
  184.     stars[randY] = w
  185.   end
  186.   for i, v in pairs(stars) do
  187.     if v < 1 then
  188.       deleteprev = true
  189.       term.setCursorPos(1, i)
  190.       term.write(" ")
  191.     else
  192.       if deleteprev then
  193.         if i == 2 then
  194.           stars[h] = nil
  195.         else
  196.           stars[i - 1] = nil
  197.         end
  198.       end
  199.       term.setCursorPos(v, i)
  200.       term.write("*")
  201.       term.setCursorPos(v + 1, i)
  202.       term.write(" ")
  203.       stars[i] = v - 1
  204.       deleteprev = false
  205.     end
  206.   end
  207.   rednet.broadcast("ping")
  208.   id, message = rednet.receive(.1)
  209.   if id and message == "ping" then
  210.     rednet.send(id, "ping")
  211.     break
  212.   end
  213. end--]]
  214.  
  215. gameConnect()
  216.  
  217. sleep(.2)
  218. term.setBackgroundColor(colors.white)
  219. term.clear()
  220. for i = w, -7, -1 do
  221.     draw("Team Up! ", i, h/2, orange, white)
  222.     sleep(.05)
  223.     draw("Team Up! ", i, h/2, blue, white)
  224.     sleep(.05)
  225. end
  226.  
  227. ------======START GAME======------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement