Advertisement
TheOddByte

[ComputerCraft][Game] Lasers

Sep 28th, 2013
1,769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.80 KB | None | 0 0
  1. --[[
  2.     [Game] Lasers
  3.     @version 1.2, 26/06/2014
  4.     @author TheOddByte
  5. --]]
  6.  
  7. local w,h = term.getSize()
  8.  
  9. local oldPullEvent = os.pullEvent
  10. os.pullEvent = os.pullEventRaw
  11.  
  12. local player = {
  13.  
  14.    
  15.     dead = false,
  16.     side = "down",
  17.    
  18.     ["sides"] = {
  19.         ["left"] = {
  20.             art = "<",
  21.         },
  22.        
  23.         ["right"] = {
  24.             art = ">",
  25.         },
  26.        
  27.         ["down"] = {
  28.             art = "v",
  29.         },
  30.        
  31.         ["up"] = {
  32.             art = "^",
  33.         },
  34.     },
  35. }
  36.  
  37. local player2 = {}
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. local function pGet(hCode,file)
  46.  
  47.     hResponse = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(hCode))
  48.     if hResponse then
  49.         hFile = fs.open(file,"w")
  50.         local sCode = hResponse.readAll()
  51.         hResponse.close()
  52.         hFile.write(sCode)
  53.         hFile.close()
  54.      
  55.     else
  56.         error("Error getting file: "..file,0)
  57.         fs.delete(".Lasers_Data") -- If a file failed to download
  58.     end
  59. end
  60.  
  61. if not fs.exists(".Lasers_Data") then
  62.     local folders = {
  63.         ".Lasers_Data/APIs", ".Lasers_Data/Settings", ".Lasers_Data/Themes",
  64.     }
  65.    
  66.     local apis = {
  67.         [1] = {
  68.             name = "gui",
  69.             code = "3v7rMmu1",
  70.         },
  71.        
  72.         [2] = {
  73.             name = "rNet",
  74.             code = "r3ueCHfs",
  75.         }
  76.     }
  77.    
  78.     term.clear()
  79.     term.setCursorPos(1,1)
  80.    
  81.     for i = 1, #folders do
  82.         print("Creating: "..folders[i])
  83.         fs.makeDir(folders[i])
  84.     end
  85.    
  86.     for i = 1,#apis do
  87.         print("Downloading: "..apis[i].name)
  88.         pGet(apis[i].code,".Lasers_Data/APIs/"..apis[i].name)
  89.     end
  90. end
  91.  
  92.  
  93. for _, file in ipairs( fs.list(".Lasers_Data/APIs/") ) do
  94.     os.unloadAPI(".Lasers_Data/APIs/" .. file)
  95.     os.loadAPI(".Lasers_Data/APIs/" .. file)
  96. end
  97.  
  98. local default = {
  99.     lang = 1, nickname = "<Nickname>", theme = "Lasers",
  100. }
  101.  
  102. if not fs.exists(".Lasers_Data/Settings/settings.cfg") then
  103.     gui.saveTable(".Lasers_Data/Settings/settings.cfg",default)
  104. end
  105.  
  106. if not fs.exists(".Lasers_Data/Themes/Lasers") then
  107.     local theme = {
  108.         bColor = "white",
  109.         defaultTextCol = "red",
  110.         activeBackCol = "red",
  111.         activeTextCol = "white",
  112.         headerBackCol = "red",
  113.         headerTextCol = "white",
  114.     }
  115.     local f = fs.open(".Lasers_Data/Themes/Lasers", "w")
  116.     for i, v in pairs( theme ) do
  117.         f.writeLine( i .. " = " .. tostring(v) )
  118.     end
  119.     f.close()
  120. end
  121.  
  122. local tSettings = gui.getTable(".Lasers_Data/Settings/settings.cfg")
  123. player.nickname = tSettings.nickname
  124. local theme = gui.loadTheme( ".Lasers_Data/Themes/" .. tSettings.theme )
  125.  
  126.  
  127.  
  128. --# Default data
  129. local language = "English"
  130.  
  131. local languages = {
  132.     "English",
  133. }
  134.  
  135. local function rebootGame()
  136.     shell.run(shell.getRunningProgram()) error()
  137. end
  138.  
  139.  
  140. local themes = {}
  141. local themes_downloadable = {}
  142.  
  143. for _, file in ipairs( fs.list(".Lasers_Data/Themes/") ) do
  144.     local nTheme = {}
  145.     nTheme.name = file
  146.     table.insert( themes, nTheme )
  147. end
  148.  
  149. local function changeName()
  150.     gui.drawBox( 2, w - 1, h/2 - 3, h/2 + 2, colors.red )
  151.     gui.drawLine( 2, w - 1, h/2 - 3, nil, colors.gray )
  152.     gui.drawLine( 3, w - 2, h/2, nil, colors.white)
  153.     gui.centerPrint( h/2 - 3, colors.red, colors.gray, "Change Name")
  154.     gui.centerPrint(h/2 - 1, colors.white, colors.red, "New Name")
  155.     term.setCursorPos(1, h/2)
  156.     local nName = ""
  157.     repeat
  158.         term.setTextColor( colors.black )
  159.         term.setBackgroundColor(colors.white)
  160.         nName = gui.mRead({centeredText = true, textLength = w - 7, exitOnKey = 29})
  161.     until nName ~= "" or nName == nil
  162.     if nName ~= nil then
  163.         tSettings.nickname = nName
  164.         gui.saveTable(".Lasers_Data/Settings/settings.cfg", tSettings)
  165.     end
  166. end
  167.  
  168.  
  169. local function changeLang()
  170.     tSettings.lang = tSettings.lang + 1
  171.         if tSettings.lang > #languages then
  172.             tSettings.lang = 1
  173.         end
  174.     gui.saveTable(".Lasers_Data/Settings/settings.cfg",tSettings)
  175.    
  176.    for i = 5, 0, - 1 do
  177.         gui.drawBox(w/2 - 12,w/2 + 12,6,13,colors.gray)
  178.         gui.centerPrint(7,colors.white,colors.gray,"The game will reboot")
  179.         gui.centerPrint(8,colors.white,colors.gray,"-for the changes to")
  180.         gui.centerPrint(9,colors.white,colors.gray,"-become active!")
  181.         gui.centerPrint(11,colors.white,colors.gray,"Rebooting in "..i)
  182.         sleep(1)
  183.    end
  184.    rebootGame()
  185. end
  186.  
  187.  
  188.  
  189. local function changeTheme()
  190.     local themes = gui.table_pages( themes, 5, h - 1 )
  191.     local page, mNum = 1, 1
  192.     local loop = true
  193.     while loop do
  194.         gui.clear( theme.bColor )
  195.         gui.drawBox(1,w,1,3,theme.headerBackCol)
  196.         gui.centerPrint(2,theme.headerTextCol,nil,"Themes")
  197.         gui.drawAt(2, h - 1, " < Back ")
  198.         for i = 1,#themes[page] do
  199.             themes[page][i].sX = math.ceil(w/2 - #themes[page][i].name/2) - 1
  200.             themes[page][i].fX = math.ceil(w/2 + #themes[page][i].name/2)
  201.             if mNum == i then
  202.                 gui.centerPrint(4 + i, theme.activeTextCol, theme.activeBackCol, " " .. themes[page][i].name .. " " )
  203.             else
  204.                 gui.centerPrint(4 + i, theme.defaultTextCol, theme.bColor, themes[page][i].name )
  205.             end
  206.         end
  207.         local e, p, mX, mY = os.pullEvent()
  208.         if e == "key" then
  209.             if p == keys.up then
  210.                 mNum = mNum - 1
  211.                 if mNum < 1 then
  212.                     page = page - 1
  213.                     if page < 1 then
  214.                         page = 1
  215.                         mNum = 1
  216.                     else
  217.                         mNum = #themes[page]
  218.                     end
  219.                 end
  220.                
  221.             elseif p == keys.down then
  222.                 mNum = mNum + 1
  223.                 if mNum > #themes[page] then
  224.                     page = page + 1
  225.                     if page > #themes then
  226.                         page = #themes
  227.                         mNum = #themes[page]
  228.                     else
  229.                         mNum = 1
  230.                     end
  231.                 end
  232.                
  233.             elseif p == 28 then
  234.                 if fs.exists(".Lasers_Data/Themes/" .. themes[page][mNum].name) then
  235.                     tSettings.theme = themes[page][mNum].name
  236.                     gui.saveTable(".Lasers_Data/Settings/settings.cfg", tSettings)
  237.                     loop = false
  238.                 end
  239.             end
  240.            
  241.         elseif e == "mouse_click" or e == "monitor_touch" then
  242.             for i = 1, #themes[page] do
  243.                 if mX >= themes[page][i].sX and mX <= themes[page][i].fX and mY == 4 + i then
  244.                     if mNum == i then
  245.                         if fs.exists(".Lasers_Data/Themes/" .. themes[page][mNum].name) then
  246.                             tSettings.theme = themes[page][mNum].name
  247.                             gui.saveTable(".Lasers_Data/Settings/settings.cfg", tSettings)
  248.                             loop = false
  249.                         end
  250.                     else
  251.                         mNum = i
  252.                     end
  253.                     break
  254.                 end
  255.             end
  256.            
  257.             if mX >= 2 and mX <= 9 and mY == h - 1 then
  258.                 term.setTextColor(theme.defaultTextCol)
  259.                 term.setBackgroundColor(theme.bColor)
  260.                 gui.drawAt(2, h - 1, " < Back ")
  261.                 sleep(.15)
  262.                 loop = false
  263.             end
  264.         end
  265.     end
  266. end
  267.  
  268.                
  269.  
  270.  
  271.  
  272. local highscores = {}
  273. if fs.exists(".Lasers_Data/highscore.data") then
  274.     highscores = gui.getTable(".Lasers_Data/highscore.data")
  275. end
  276.    
  277. local function view_highscores()
  278.  
  279. local hs = gui.table_pages(highscores,4,h - 3)
  280. local page = 1
  281.  
  282.  
  283. local tColors = {
  284.     [1] = {
  285.         bColor  = colors.gray,
  286.         tColor  = colors.white,
  287.         bColor2 = colors.white,
  288.         tColor2 = colors.black,
  289.     },
  290.    
  291.     [2] = {
  292.         bColor  = colors.lightGray,
  293.         tColor  = colors.white,
  294.         bColor2 = colors.red,
  295.         tColor2 = colors.white,
  296.     },
  297. }
  298.  
  299.   if #highscores ~= 0 then
  300.     local viewing = true
  301.     while viewing do
  302.         gui.drawBox(1,w,1,2,theme.headerBackCol)
  303.         gui.drawBox(1,w/2,3,h,colors.gray)
  304.         gui.drawBox(math.ceil(w/2),w,3,h,colors.white)
  305.         gui.centerPrint(1,theme.headerTextCol,theme.headerBackCol,"Highscores")
  306.         gui.drawLine(1,w,h,nil,theme.headerBackCol)
  307.         gui.centerPrint(h,theme.headerTextCol,theme.headerBackCol," [Space]Exit  [Down]Next Page  [Up]Previous Page ")
  308.         local cNum = 1
  309.         for i = 1,#hs[page] do
  310.             term.setTextColor(tColors[cNum].tColor)
  311.             term.setBackgroundColor(tColors[cNum].bColor)
  312.             gui.drawAt(2,3 + i,hs[page][i].pos .. ": " .. hs[page][i].name .. " ")
  313.             term.setTextColor(tColors[cNum].tColor2)
  314.             term.setBackgroundColor(tColors[cNum].bColor2)
  315.             gui.drawAt(w/2 + 4,3 + i," " .. hs[page][i].score .. " ")
  316.             cNum = cNum + 1
  317.             if cNum > 2 then
  318.                 cNum = 1
  319.             end
  320.         end
  321.         local evt, p1 = os.pullEvent("key")
  322.             if p1 == keys.up then
  323.                 page = page - 1
  324.                 if page < 1 then
  325.                     page = 1
  326.                 end
  327.                
  328.             elseif p1 == keys.down then
  329.                 page = page + 1
  330.                 if page > #hs then
  331.                     page = #hs
  332.                 end
  333.            
  334.             elseif p1 == 57 then
  335.                 viewing = false
  336.             end
  337.     end
  338.   else
  339.       gui.clear(colors.white)
  340.       gui.drawBox(w/2 - 15, w/2 + 15,h/2 - 2,h/2 + 3,theme.headerBackCol)
  341.       gui.drawBox(w/2 - 14, w/2 + 14,h/2 - 1,h/2 + 2,theme.bColor)
  342.       gui.centerPrint(h/2 - 2,theme.headerTextCol,theme.headerBackCol,"Alert!")
  343.       gui.centerPrint(h/2,theme.defaultTextCol,theme.bColor,"Currently no highscores")
  344.       gui.centerPrint(h/2+ 1,theme.defaultTextCol,theme.bColor,"Press any key to continue")
  345.       os.pullEvent("key")
  346.   end
  347. end
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357. local function main(botMode, multiplayer, host)
  358.  
  359.  
  360. local tScreen = {}
  361.  
  362.  
  363.  
  364. local mNum       = 1
  365. local cTime      = 10
  366. local score      = 0
  367. local mvSpeed    = 0.5
  368. local powerupBar = 0
  369.  
  370. local initializeLaser  =  false
  371. local laserBeam        =  false
  372. local won              =  false
  373. local tp               =  false
  374. local inMenu           =  false
  375.  
  376.    
  377. local vNum
  378. local hNum
  379. local oldX
  380. local oldY
  381. local newX
  382. local newY
  383. local cID
  384.  
  385.  
  386. local function check_highscores()
  387.   if #highscores ~= 0 then
  388.     local pos  = #highscores
  389.     local sPos
  390.     local temp = {}
  391.     for i = #highscores, 1, -1 do
  392.         sPos = i
  393.         if score > highscores[i].score then
  394.             pos = i
  395.         else
  396.             pos = i + 1
  397.             break
  398.         end
  399.     end
  400.  
  401.     for i = sPos, #highscores do
  402.         local n = {}
  403.         n.name  = highscores[i].name
  404.         n.score = highscores[i].score
  405.         n.pos   = highscores[i].pos + 1
  406.         table.insert(temp, n)
  407.     end
  408.     for i = 1,#temp do
  409.         highscores[temp[i].pos] = temp[i]
  410.     end
  411.    
  412.    
  413.     highscores[pos].name  = tSettings.nickname
  414.     highscores[pos].score = score
  415.     gui.saveTable(".Lasers_Data/highscore.data",highscores)
  416.    
  417.   else
  418.     local n = {}
  419.     n.name  = tSettings.nickname
  420.     n.score = score
  421.     n.pos   = 1
  422.     table.insert(highscores, n)
  423.     gui.saveTable(".Lasers_Data/highscore.data",highscores)
  424.   end
  425. end
  426.            
  427.  
  428. --# Multiplayer connection
  429. if multiplayer then
  430.  
  431. modemAttached = rNet.openSides()
  432.  
  433.  
  434.  
  435. if modemAttached then  
  436.     gui.clear(colors.white)
  437.     local bar        = gui.initBar(w/2 - 14, w/2 + 14,h/2,0,3)
  438.     local barTexture = {barColor = colors.red, barBackgroundColor = colors.gray}
  439.    
  440.    
  441.    
  442. local function drawScreen(text,id,h)
  443.     gui.clear(colors.white)
  444.     gui.drawBar(bar, barTexture)
  445.     gui.centerPrint(bar.y - 1,colors.black,colors.white,bar.currentProgress .. "/" .. bar.maxLen)
  446.     gui.centerPrint(bar.y + 1,colors.black,colors.white,text)
  447.     if id ~= nil then
  448.         if h then
  449.             gui.centerPrint(2,colors.black,colors.white,"Your ID: ".. os.getComputerID() .. "    Client ID: "..id)
  450.         else
  451.             gui.centerPrint(2,colors.black,colors.white,"Your ID: ".. os.getComputerID() .. "    Host ID: "..id)
  452.         end
  453.     end
  454. end
  455.  
  456.  
  457.    
  458.     if host then
  459.       --# Host
  460.         player.x = math.ceil(w/2) - 1
  461.         player.y = math.ceil(h/2)
  462.         gui.updateBar(bar, bar.currentProgress + 1, barTexture)
  463.         local rID, msg
  464.         for i = 1, 5 do
  465.             drawScreen("Searching for clients",nil)
  466.             rednet.broadcast("lasers_multiplayer_host")
  467.             repeat
  468.                 rID, msg = rednet.receive(1.5)
  469.             until rID ~= os.getComputerID()
  470.             if rID ~= nil then
  471.                 if msg == "lasers_multiplayer_client" then
  472.                 break
  473.                 end
  474.             end
  475.         end
  476.        
  477.         if rID == nil then
  478.             gui.updateBar(bar, 0, barTexture)
  479.             gui.clear(colors.white)
  480.             gui.drawBar(bar, barTexture)
  481.             gui.centerPrint(bar.y - 1,colors.black,colors.white,"No clients found")
  482.             gui.centerPrint(bar.y + 1,colors.black,colors.white,"Request timed out")
  483.             os.pullEvent("key")
  484.             shell.run(shell.getRunningProgram()) error()
  485.            
  486.         else
  487.        
  488.             player2.id = rID
  489.             gui.clear(colors.white)
  490.             gui.updateBar(bar, bar.currentProgress + 1, barTexture)
  491.             drawScreen("Sending data", player2.id, true)
  492.            
  493.             local rID
  494.             repeat
  495.                 rNet.sendTable(player2.id, player)
  496.                 rID, msg = rednet.receive(.5)
  497.             until rID == player2.id
  498.            
  499.             local rID
  500.             gui.updateBar(bar, bar.currentProgress + 1, barTexture)
  501.             drawScreen("Receiveing data", player2.id, true)
  502.             repeat
  503.                 rID, msg = rednet.receive()
  504.             until rID == player2.id
  505.             player2 = textutils.unserialize(msg)
  506.             player2.id = rID
  507.         end
  508.        
  509.        
  510.        
  511.     else
  512.    
  513.    
  514.    
  515.        --# Client
  516.         player.x = math.ceil(w/2) + 1
  517.         player.y = math.ceil(h/2)
  518.          gui.updateBar(bar, bar.currentProgress + 1, barTexture)
  519.          drawScreen("Searching for hosts", nil)
  520.          local rID, msg
  521.          for i = 1,5 do
  522.              rID, msg = rednet.receive(1.5)
  523.              if msg == "lasers_multiplayer_host" then
  524.                  break
  525.              end
  526.          end
  527.    
  528.         gui.clear(colors.white)
  529.         if rID ~= nil and msg == "lasers_multiplayer_host" then
  530.             rednet.send(rID,"lasers_multiplayer_client")
  531.             player2.id = rID
  532.          gui.updateBar(bar, bar.currentProgress + 1, barTexture)
  533.          drawScreen("Receiveing data", player2.id, false)
  534.          
  535.             repeat
  536.                 rID, msg = rednet.receive()
  537.             until rID == player2.id
  538.             rednet.send(player2.id,"lasers_multiplayer_data_received")
  539.            
  540.             player2 = textutils.unserialize(msg)
  541.             player2.id = rID
  542.             gui.clear(colors.white)
  543.            
  544.             gui.updateBar(bar, bar.currentProgress + 1, barTexture)
  545.             drawScreen("Sending data", player2.id, false)
  546.             rNet.sendTable(player2.id, player)
  547.         else
  548.             gui.updateBar(bar, 0, barTexture)
  549.             gui.clear(colors.white)
  550.             gui.drawBar(bar, barTexture)
  551.             gui.centerPrint(bar.y - 1,colors.black,colors.white,"No hosts found")
  552.             gui.centerPrint(bar.y + 1,colors.black,colors.white,"Request timed out")
  553.             os.pullEvent("key")
  554.             shell.run(shell.getRunningProgram()) error()
  555.         end
  556.        
  557.     end
  558. else
  559.     gui.clear( colors.white )
  560.     gui.centerPrint(h/2, colors.red, colors.white,"No modems attached!")
  561.     os.pullEvent()
  562.     rebootGame()
  563. end
  564.     else
  565.         player.x = math.ceil(w/2)
  566.         player.y = math.ceil(h/2)
  567.  
  568. end
  569.  
  570.            
  571.            
  572.    
  573.    
  574.    
  575.    
  576.  
  577.  
  578.  
  579.  
  580. local lasers = {
  581.    -- X axis
  582.     [1] = {
  583.         axis = "vertical",
  584.         direction = "left",
  585.         x = math.ceil(w/2),
  586.         y = 1,
  587.         minX = 2,
  588.         maxX = w - 1,
  589.     },
  590.    
  591.     [2] = {
  592.         axis = "vertical",
  593.         direction = "left",
  594.         x = math.ceil(w/2),
  595.         y = h - 1,
  596.         minX = 2,
  597.         maxX = w - 1,
  598.     },
  599.    
  600.    -- Y axis   
  601.     [3] = {
  602.         axis = "horizontal",
  603.         direction = "down",
  604.         x = 1,
  605.         y = math.ceil(h/2),
  606.         minY = 2,
  607.         maxY = h - 2,
  608.     },
  609.    
  610.     [4] = {
  611.         axis = "horizontal",
  612.         direction = "down",
  613.         x = w,
  614.         y = math.ceil(h/2),
  615.         minY = 2,
  616.         maxY = h - 2,
  617.     },
  618. }
  619.  
  620.  
  621.  
  622.  
  623.    
  624.    
  625.  
  626.  local  mOpts = {
  627.            
  628.     [1] = {
  629.         name = " Resume ",
  630.         functionName = "_resume",
  631.     },
  632.            
  633.     [2] = {
  634.         name = " Exit ",
  635.         functionName = rebootGame,
  636.     },
  637. }
  638.  
  639. local powerups = {
  640.     [1] = {
  641.        -- Art
  642.         bColor = colors.red,
  643.         tColor = colors.white,
  644.        
  645.        -- Data
  646.         bTimer = 3,
  647.         booleanName = "slowdownLaser",
  648.     },
  649.    
  650.     [2] = {
  651.        -- Art
  652.         bColor = colors.purple,
  653.         tColor = colors.white,
  654.        
  655.        -- Data
  656.         bTimer = 5,
  657.         booleanName = "teleport",
  658.     },
  659.    
  660.     [3] = {
  661.        -- Art
  662.         bColor = colors.lightBlue,
  663.         tColor = colors.white,
  664.        
  665.        -- Data
  666.         bTimer = 5,
  667.         booleanName = "freezeLaser",
  668.     },
  669. }
  670.  
  671. local tPowerup = {
  672.     ["booleans"] = {
  673.         freezeLaser = false,
  674.         teleport = false,
  675.         slowdownLaser = false
  676.     },
  677. }
  678.  
  679. local function createPowerup(index)
  680.   if #tPowerup < 2 then
  681.    nPowerup = {}
  682.    
  683.    
  684.    nPowerup.bColor = powerups[index].bColor
  685.    nPowerup.tColor = powerups[index].tColor
  686.    nPowerup.bTimer = powerups[index].bTimer
  687.    nPowerup.booleanName = powerups[index].booleanName
  688.    nPowerup.art = "P"
  689.    nPowerup.x = math.random(3,w - 2)
  690.    nPowerup.y = math.random(3,h - 3)
  691.    table.insert(tPowerup,nPowerup)
  692.   end
  693. end
  694.  
  695. local function powerupBoolean(booleanName)
  696.     if booleanName == "freezeLaser" then
  697.         tPowerup["booleans"].freezeLaser = true
  698.        
  699.     elseif booleanName == "slowdownLaser" then
  700.         tPowerup["booleans"].slowdownLaser = true
  701.    
  702.     elseif booleanName == "teleport" then
  703.         tPowerup["booleans"].teleport = true
  704.     end
  705. end
  706.  
  707.  
  708.  
  709.        
  710.  
  711.  
  712.  
  713. --# Bot/A.I Stuff
  714.  
  715. local bots = {}
  716.  
  717. local defBot = {
  718.     ["tColors"] = {
  719.         colors.red, colors.purple, colors.green, colors.blue,
  720.     },
  721.  
  722.     ["side"] = {
  723.         ["left"] = {
  724.             art = "<",
  725.         },
  726.        
  727.         ["right"] = {
  728.             art = ">",
  729.         },
  730.        
  731.         ["down"] = {
  732.             art = "v",
  733.         },
  734.        
  735.         ["up"] = {
  736.             art = "^",
  737.         },
  738.     },
  739. }
  740.  
  741. local function spawnBot(addX)
  742.  
  743.     local nBot = {}
  744.    
  745.     nBot.direction = "down"
  746.     nBot.x = math.ceil(w/2) + addX
  747.     nBot.y = math.ceil(h/2)
  748.     nBot.tColor = defBot["tColors"][math.random(1,#defBot["tColors"])]
  749.     nBot.side = defBot.side
  750.    
  751.     table.insert(bots,nBot)
  752. end
  753.  
  754. if botMode then
  755.     spawnBot(1)
  756.     player.x = math.ceil(w/2) - 1
  757. end
  758.  
  759. local function hBots()
  760.  
  761.  
  762. -- Getting the axises
  763.         for i = 1,#lasers do
  764.             if lasers[i].axis == "vertical" then
  765.                 vNum = i
  766.                 break
  767.             end
  768.         end
  769.         for i = 1,#lasers do
  770.             if lasers[i].axis == "horizontal" then
  771.                 hNum = i
  772.                 break
  773.             end
  774.         end
  775.  
  776.  
  777.     for i = 1,#bots do
  778.         if not laserBeam then
  779.           -- Y Axis
  780.             if lasers[hNum].direction == "down" then
  781.            
  782.                 if lasers[hNum].y <= h/2 then
  783.                   if not initializeLaser then
  784.                     bots[i].direction = "up"
  785.                     bots[i].y = bots[i].y - 1 if bots[i].y < 2 then bots[i].y = 2 end
  786.                     if bots[i].x == player.x and bots[i].y == player.y then
  787.                         bots[i].y = bots[i].y + 1
  788.                     end
  789.                   else
  790.                     bots[i].direction = "down"
  791.                     bots[i].y = bots[i].y + 1 if bots[i].y > h - 2 then bots[i].y = h - 2 end
  792.                     if bots[i].x == player.x and bots[i].y == player.y then
  793.                         bots[i].y = bots[i].y - 1
  794.                     end
  795.                   end
  796.                  
  797.                 else
  798.                
  799.                   if not initializeLaser then
  800.                     bots[i].direction = "down"
  801.                     bots[i].y = bots[i].y + 1 if bots[i].y > h - 2 then bots[i].y = h - 2 end
  802.                     if bots[i].x == player.x and bots[i].y == player.y then
  803.                         bots[i].y = bots[i].y - 1
  804.                     end
  805.                   else
  806.                     bots[i].direction = "up"
  807.                     bots[i].y = bots[i].y - 1 if bots[i].y <  2 then bots[i].y = 2 end
  808.                     if bots[i].x == player.x and bots[i].y == player.y then
  809.                         bots[i].y = bots[i].y + 1
  810.                     end
  811.                   end
  812.                              
  813.                 end
  814.        
  815.             elseif lasers[hNum].direction == "up" then
  816.            
  817.               if not initializeLaser then
  818.                 if lasers[hNum].y >= h/2 then
  819.                     bots[i].direction = "down"
  820.                     bots[i].y = bots[i].y + 1 if bots[i].y > h - 2 then bots[i].y = h - 2 end
  821.                     if bots[i].x == player.x and bots[i].y == player.y then
  822.                         bots[i].y = bots[i].y - 1
  823.                     end
  824.                   else
  825.                     bots[i].direction = "up"
  826.                     bots[i].y = bots[i].y - 1 if bots[i].y < 2 then bots[i].y = 2 end
  827.                     if bots[i].x == player.x and bots[i].y == player.y then
  828.                         bots[i].y = bots[i].y + 1
  829.                     end  
  830.                   end
  831.                  
  832.                 else
  833.                
  834.                   if not initializeLaser then
  835.                     bots[i].direction = "up"
  836.                     bots[i].y = bots[i].y - 1 if bots[i].y < 2 then bots[i].y = 2 end
  837.                     if bots[i].x == player.x and bots[i].y == player.y then
  838.                         bots[i].y = bots[i].y + 1
  839.                     end
  840.                   else
  841.                     bots[i].direction = "down"
  842.                     bots[i].y = bots[i].y + 1 if bots[i].y > h - 2 then bots[i].y = h - 2 end
  843.                     if bots[i].x == player.x and bots[i].y == player.y then
  844.                         bots[i].y = bots[i].y - 1
  845.                     end
  846.                   end
  847.                  
  848.                 end
  849.             end
  850.            
  851.           -- X axis
  852.             if lasers[vNum].direction == "right" then
  853.               if not initializeLaser then
  854.                 if lasers[vNum].x >= w/2 then
  855.                     bots[i].direction = "left"
  856.                     bots[i].x = bots[i].x - 1 if bots[i].x < 2 then bots[i].x = 2 end
  857.                     if bots[i].x == player.x and bots[i].y == player.y then
  858.                         bots[i].x = bots[i].x + 1
  859.                     end
  860.                   else
  861.                     bots[i].direction = "right"
  862.                     bots[i].x = bots[i].x + 1 if bots[i].x > w - 1 then bots[i].x = w - 1 end
  863.                     if bots[i].x == player.x and bots[i].y == player.y then
  864.                         bots[i].x = bots[i].x - 1
  865.                     end  
  866.                   end
  867.                  
  868.                 else
  869.                
  870.                   if not initializeLaser then
  871.                     bots[i].direction = "right"
  872.                     bots[i].x = bots[i].x + 1 if bots[i].x > w - 1 then bots[i].x = w - 1 end
  873.                     if bots[i].x == player.x and bots[i].y == player.y then
  874.                         bots[i].x = bots[i].x - 1
  875.                     end  
  876.                   else
  877.                     bots[i].direction = "left"
  878.                     bots[i].x = bots[i].x - 1 if bots[i].x < 2 then bots[i].x = 2 end
  879.                     if bots[i].x == player.x and bots[i].y == player.y then
  880.                         bots[i].x = bots[i].x + 1
  881.                     end
  882.                   end
  883.                  
  884.                 end
  885.        
  886.        
  887.             elseif lasers[vNum].direction == "left" then
  888.            
  889.               if not initializeLaser then
  890.                 if lasers[vNum].x <= w/2 then
  891.                     bots[i].direction = "right"
  892.                     bots[i].x = bots[i].x + 1 if bots[i].x > w - 1 then bots[i].x = w - 1 end
  893.                     if bots[i].x == player.x and bots[i].y == player.y then
  894.                         bots[i].x = bots[i].x - 1
  895.                     end
  896.                   else
  897.                     bots[i].direction = "left"
  898.                     bots[i].x = bots[i].x - 1 if bots[i].x < 2 then bots[i].x = 2 end
  899.                     if bots[i].x == player.x and bots[i].y == player.y then
  900.                         bots[i].x = bots[i].x + 1
  901.                     end  
  902.                   end
  903.                  
  904.                 else
  905.                
  906.                   if not initializeLaser then
  907.                     bots[i].direction = "left"
  908.                     bots[i].x = bots[i].x - 1 if bots[i].x < 2 then bots[i].x = 2 end
  909.                     if bots[i].x == player.x and bots[i].y == player.y then
  910.                         bots[i].x = bots[i].x + 1
  911.                     end  
  912.                   else
  913.                     bots[i].direction = "right"
  914.                     bots[i].x = bots[i].x + 1 if bots[i].x > w - 1 then bots[i].x = w - 1 end
  915.                     if bots[i].x == player.x and bots[i].y == player.y then
  916.                         bots[i].x = bots[i].x - 1
  917.                     end
  918.                   end
  919.                  
  920.                 end
  921.             end
  922.            
  923.            
  924.         else
  925.        
  926.            --# X axis
  927.             if lasers[vNum].x > bots[i].x then
  928.                 bots[i].direction = "left"
  929.                 bots[i].x = bots[i].x - 1 if bots[i].x < 2 then bots[i].x = 2 end
  930.                     if bots[i].x == player.x and bots[i].y == player.y then
  931.                         bots[i].x = bots[i].x + 1
  932.                     end
  933.                    
  934.             elseif lasers[vNum].x < bots[i].x then
  935.                 bots[i].direction = "right"
  936.                 bots[i].x = bots[i].x + 1 if bots[i].x > w - 1 then bots[i].x = w - 1 end
  937.                     if bots[i].x == player.x and bots[i].y == player.y then
  938.                         bots[i].x = bots[i].x - 1
  939.                     end
  940.             end
  941.            
  942.            --# Y axis
  943.             if lasers[hNum].y > bots[i].y then
  944.                 bots[i].direction = "up"
  945.                 bots[i].y = bots[i].y - 1 if bots[i].y < 2 then bots[i].y = 2 end
  946.                     if bots[i].x == player.x and bots[i].y == player.y then
  947.                         bots[i].y = bots[i].y + 1
  948.                     end
  949.                    
  950.             elseif lasers[hNum].y < bots[i].y then
  951.                 bots[i].direction = "down"
  952.                 bots[i].y = bots[i].y + 1 if bots[i].y > h - 2 then bots[i].y = h - 2 end
  953.                     if bots[i].x == player.x and bots[i].y == player.y then
  954.                         bots[i].y = bots[i].y - 1
  955.                     end
  956.             end
  957.            
  958.         end
  959.     end
  960. end
  961.  
  962.  
  963. local function checkCollision()
  964.     if not multiplayer then
  965.         for i = 1,#bots do
  966.             if player.x == bots[i].x and player.y == bots[i].y then
  967.                 return true
  968.             end
  969.         end
  970.     else
  971.         if player.x == player2.x and player.y == player2.y then
  972.             return true
  973.         end
  974.     end
  975. end
  976.  
  977.  
  978.  
  979.  
  980.  
  981.     local function events()
  982.         for i = 1,#tPowerup do
  983.             if player.x == tPowerup[i].x and player.y == tPowerup[i].y then
  984.                 powerupBoolean(tPowerup[i].booleanName)
  985.                 powerupBarTimer = os.startTimer(1)
  986.                 powerupBar = 5
  987.                 table.remove(tPowerup,i)
  988.                 break
  989.             end
  990.         end
  991.    
  992.         evt, p1, mX, mY = os.pullEvent()
  993.             if evt == "key" then
  994.                 if p1 == keys.up then
  995.                   if not inMenu then
  996.                     player.side = "up"
  997.                     player.y = player.y - 1
  998.                         if player.y < 2 then player.y = 2 end
  999.                         local collision = checkCollision()
  1000.                             if collision then
  1001.                                 player.y = player.y + 1
  1002.                             end
  1003.                       if multiplayer then
  1004.                           rNet.sendTable(player2.id, player)
  1005.                       end      
  1006.                   else
  1007.                       if mNum > 1 then
  1008.                           mNum = mNum - 1
  1009.                       end                    
  1010.                   end
  1011.                
  1012.                 elseif p1 == keys.down then
  1013.                   if not inMenu then
  1014.                     player.side = "down"
  1015.                     player.y = player.y + 1
  1016.                         if player.y > h - 2 then player.y = h - 2 end
  1017.                         local collision = checkCollision()
  1018.                             if collision then
  1019.                                 player.y = player.y - 1
  1020.                             end
  1021.                       if multiplayer then
  1022.                           rNet.sendTable(player2.id, player)
  1023.                       end  
  1024.                   else
  1025.                       if mNum < #mOpts then
  1026.                           mNum = mNum + 1
  1027.                       end
  1028.                   end
  1029.                      
  1030.                        
  1031.                    
  1032.                
  1033.                 elseif p1 == keys.left then
  1034.                   if not inMenu then
  1035.                     player.side = "left"
  1036.                     player.x = player.x - 1
  1037.                         if player.x < 2 then player.x = 2 end
  1038.                         local collision = checkCollision()
  1039.                             if collision then
  1040.                                 player.x = player.x + 1
  1041.                             end
  1042.                       if multiplayer then
  1043.                           rNet.sendTable(player2.id, player)
  1044.                       end  
  1045.                   end
  1046.                
  1047.                 elseif p1 == keys.right then
  1048.                   if not inMenu then
  1049.                     player.side = "right"
  1050.                     player.x = player.x + 1
  1051.                         if player.x > w - 1 then player.x = w - 1 end
  1052.                         local collision = checkCollision()
  1053.                             if collision then
  1054.                                 player.x = player.x - 1
  1055.                             end
  1056.                       if multiplayer then
  1057.                           rNet.sendTable(player2.id, player)
  1058.                       end  
  1059.                   end
  1060.  
  1061.                 elseif p1 == 29 then
  1062.                     if inMenu then
  1063.                         inMenu = false
  1064.                         countdown = os.startTimer(1)
  1065.                     else
  1066.                         inMenu = true
  1067.                     end
  1068.                
  1069.                 elseif p1 == 28 then
  1070.                     if inMenu then
  1071.                         if mOpts[mNum].functionName ~= "_resume" then
  1072.                             local callFunction = mOpts[mNum].functionName
  1073.                             callFunction()
  1074.                         end
  1075.                         inMenu = false
  1076.                     end  
  1077.                 end
  1078.                
  1079.             elseif evt == "rednet_message" then
  1080.                 if multiplayer then
  1081.                     if p1 == player2.id then
  1082.                         player2 = textutils.unserialize(mX)
  1083.                         player2.id = p1
  1084.                     end
  1085.                 end
  1086.                
  1087.                
  1088.            
  1089.             elseif evt == "timer" then
  1090.                
  1091.                 if p1 == countdown then
  1092.                     if not inMenu then
  1093.                         cTime = cTime - 1
  1094.                         if cTime < 0 then cTime = 0 end
  1095.                             if cTime > 0 then
  1096.                                 countdown = os.startTimer(1)
  1097.                             else
  1098.                                 spawnPowerup = os.startTimer(math.random(15,20))
  1099.                                 moveTimer = os.startTimer(.5)
  1100.                                 laserTimer = os.startTimer(math.random(3,5))
  1101.                                 scoreTimer = os.startTimer(1)
  1102.                                 if botMode then
  1103.                                 botMove = os.startTimer(.35)
  1104.                             end
  1105.                         end
  1106.                     end
  1107.                        
  1108.                 elseif p1 == moveTimer then
  1109.                     for i = 1,#lasers do
  1110.                    
  1111.                         if lasers[i].axis == "vertical" then
  1112.                             if lasers[i].direction == "left" then
  1113.                                 lasers[i].x = lasers[i].x - 1
  1114.                                 if lasers[i].x < lasers[i].minX then
  1115.                                     lasers[i].x = lasers[i].minX; lasers[i].direction = "right"
  1116.                                 end
  1117.                            
  1118.                             elseif lasers[i].direction == "right" then
  1119.                                 lasers[i].x = lasers[i].x + 1
  1120.                                 if lasers[i].x > lasers[i].maxX then
  1121.                                     lasers[i].x = lasers[i].maxX; lasers[i].direction = "left"
  1122.                                 end
  1123.                             end
  1124.                        
  1125.                         elseif lasers[i].axis == "horizontal" then
  1126.                             if lasers[i].direction == "up" then
  1127.                                 lasers[i].y = lasers[i].y - 1
  1128.                                 if lasers[i].y < lasers[i].minY then
  1129.                                     lasers[i].y = lasers[i].minY; lasers[i].direction = "down"
  1130.                                 end
  1131.                            
  1132.                             elseif lasers[i].direction == "down" then
  1133.                                 lasers[i].y = lasers[i].y + 1
  1134.                                 if lasers[i].y > lasers[i].maxY then
  1135.                                     lasers[i].y = lasers[i].maxY; lasers[i].direction = "up"
  1136.                                 end
  1137.                             end
  1138.                            
  1139.                         end
  1140.                        
  1141.                     end -- For loop
  1142.                    
  1143.                     local levels = {
  1144.                         [1] = {
  1145.                             score   = 250,
  1146.                             mvSpeed = 0.45,
  1147.                         },
  1148.                        
  1149.                         [2] = {
  1150.                             score   = 500,
  1151.                             mvSpeed = 0.4,
  1152.                         },
  1153.                        
  1154.                         [3] = {
  1155.                             score = 750,
  1156.                             mvSpeed = 0.35,
  1157.                         },
  1158.                        
  1159.                         [4] = {
  1160.                             score = 1000,
  1161.                             mvSpeed = 0.3,
  1162.                         },
  1163.                        
  1164.                         [5] = {
  1165.                             score = 1250,
  1166.                             mvSpeed = 0.25,
  1167.                         },
  1168.                        
  1169.                         [6] = {
  1170.                             score = 1500,
  1171.                             mvSpeed = 0.2,
  1172.                         },
  1173.                        
  1174.                         [7] = {
  1175.                             score = 2000,
  1176.                             mvSpeed = 0.1,
  1177.                         },
  1178.                     }
  1179.                
  1180.                 if not tPowerup["booleans"].slowdownLaser then
  1181.                     for i = 1,#levels do
  1182.                         if score >= levels[i].score then
  1183.                             mvSpeed = levels[i].mvSpeed
  1184.                         end
  1185.                     end
  1186.                
  1187.                 else
  1188.                     mvSpeed = 0.8
  1189.                 end
  1190.                    
  1191.                   if not tPowerup["booleans"].freezeLaser then 
  1192.                       moveTimer = os.startTimer(mvSpeed)
  1193.                   end
  1194.                  
  1195.                 elseif p1 == laserTimer then
  1196.                     initializeLaser = true
  1197.                     beamTimer = os.startTimer(3)
  1198.  
  1199.                 elseif p1 == beamTimer then
  1200.                     initializeLaser = false
  1201.                     laserBeam = true
  1202.                     fTimer = os.startTimer(2)
  1203.                
  1204.                 elseif p1 == fTimer then
  1205.                     laserBeam = false
  1206.                     laserTimer = os.startTimer(math.random(3,5))                   
  1207.                
  1208.                 elseif p1 == scoreTimer then
  1209.                     score = score + 10
  1210.                     scoreTimer = os.startTimer(1)      
  1211.  
  1212.                 elseif p1 == spawnPowerup then
  1213.                     if not multiplayer then
  1214.                         createPowerup(math.random(1,#powerups))
  1215.                         spawnPowerup = os.startTimer(math.random(15,20))
  1216.                     end
  1217.                
  1218.                 elseif p1 == rmTimer then
  1219.                     tp = false;
  1220.                    
  1221.                 elseif p1 == botMove then
  1222.                     hBots()
  1223.                     botMove = os.startTimer(.15)
  1224.  
  1225.                 elseif p1 == powerupBarTimer then
  1226.                     powerupBar = powerupBar - 1
  1227.                         if powerupBar > 0 then
  1228.                             powerupBarTimer = os.startTimer(1)
  1229.                         else
  1230.                           powerupBar = 0
  1231.                           tPowerup["booleans"].freezeLaser = false
  1232.                           tPowerup["booleans"].slowdownLaser = false
  1233.                           tPowerup["booleans"].teleport = false
  1234.                           moveTimer = os.startTimer(mvSpeed)                         
  1235.                         end                        
  1236.                 end
  1237.                
  1238.             elseif evt == "mouse_click" then
  1239.                 if tPowerup["booleans"].teleport then
  1240.                     if mX > 2 and mX < w and mY > 2 and mY < w - 1 then
  1241.                         oldX = player.x; oldY = player.y
  1242.                         newX = mX; newY = mY
  1243.                         player.x = mX; player.y = mY;
  1244.                         tp = true
  1245.                         rmTimer = os.startTimer(0.1)
  1246.                     end
  1247.                 end
  1248.                
  1249.             end
  1250.     end
  1251.    
  1252.    
  1253.    
  1254.    
  1255.    
  1256. local function draw()
  1257.     term.setBackgroundColor(colors.white)
  1258.     gui.clear()
  1259.    
  1260.     gui.drawLine(1,w,1,colors.lightGray,colors.white,"-")
  1261.     gui.drawLine(1,w,h - 1,colors.lightGray,colors.white,"-")
  1262.     for i = 1, h - 1 do
  1263.         gui.drawAt(1,i,"|")
  1264.         gui.drawAt(w,i,"|")
  1265.     end
  1266.    
  1267.     gui.drawAt(1,1,"+")
  1268.     gui.drawAt(w,1,"+")
  1269.     gui.drawAt(1,h - 1,"+")
  1270.     gui.drawAt(w,h - 1,"+")
  1271.    
  1272.     for i = 1,#lasers do
  1273.         term.setBackgroundColor(colors.gray)
  1274.         gui.drawAt(lasers[i].x,lasers[i].y," ")
  1275.     end
  1276.    
  1277.     if initializeLaser then
  1278.  
  1279.        
  1280.         for i = 1,#lasers do
  1281.             if lasers[i].axis == "vertical" then
  1282.                 vNum = i
  1283.                 break
  1284.             end
  1285.         end
  1286.         for i = 1,#lasers do
  1287.             if lasers[i].axis == "horizontal" then
  1288.                 hNum = i
  1289.                 break
  1290.             end
  1291.         end
  1292.        
  1293.         gui.drawLine(2,w - 1,lasers[hNum].y,colors.red,colors.white,"-")
  1294.         for i = 2,h - 2 do
  1295.             gui.drawAt(lasers[vNum].x,i,"|")
  1296.         end
  1297.        
  1298.     end
  1299.    
  1300.     if botMode then
  1301.        term.setBackgroundColor(colors.white)
  1302.         for i = 1,#bots do
  1303.             term.setTextColor(bots[i].tColor)
  1304.             gui.drawAt(bots[i].x,bots[i].y,bots[i].side[bots[i].direction].art)
  1305.         end
  1306.     end
  1307.    
  1308.     --#Players
  1309.     term.setBackgroundColor(colors.white)
  1310.     term.setTextColor(colors.black)
  1311.     gui.drawAt(player.x,player.y,player.sides[player.side].art)
  1312.     term.setTextColor(colors.blue)
  1313.     if multiplayer then
  1314.         gui.drawAt(player2.x, player2.y,player2.sides[player2.side].art)
  1315.     end
  1316.    
  1317.     if tp then
  1318.         term.setTextColor(colors.purple)
  1319.         gui.drawAt(oldX,oldY,"#")
  1320.         gui.drawAt(newX,newY,"#")
  1321.     end
  1322.    
  1323.  
  1324.         for i = 1,#tPowerup do
  1325.             term.setTextColor(tPowerup[i].tColor)
  1326.             term.setBackgroundColor(tPowerup[i].bColor)
  1327.             gui.drawAt(tPowerup[i].x,tPowerup[i].y,tPowerup[i].art)
  1328.         end
  1329.    
  1330.     if laserBeam then
  1331.         local vNum
  1332.         local hNum
  1333.        
  1334.         for i = 1,#lasers do
  1335.             if lasers[i].axis == "vertical" then
  1336.                 vNum = i
  1337.                 break
  1338.             end
  1339.         end
  1340.         for i = 1,#lasers do
  1341.             if lasers[i].axis == "horizontal" then
  1342.                 hNum = i
  1343.                 break
  1344.             end
  1345.         end
  1346.    
  1347.  
  1348.         gui.drawLine(2,w - 1,lasers[hNum].y,nil,colors.red," ")
  1349.         for i = 2,h - 2 do
  1350.             gui.drawAt(lasers[vNum].x,i," ")
  1351.         end
  1352.        
  1353.         if player.y == lasers[hNum].y or player.x == lasers[vNum].x then
  1354.             player.dead = true
  1355.             if multiplayer then
  1356.                 rNet.sendTable(player2.id, player)
  1357.             end
  1358.         end
  1359.  
  1360. if botMode then
  1361.  
  1362.     for i = 1,#bots do
  1363.             if bots[i].y == lasers[hNum].y or bots[i].x == lasers[vNum].x then
  1364.                table.remove(bots,i)
  1365.                break
  1366.             end
  1367.     end
  1368.  
  1369. end
  1370.  
  1371.  
  1372.        
  1373.        
  1374.     end
  1375.    
  1376.     gui.drawLine(1,w,h,colors.white,colors.lightGray)
  1377.     if cTime > 0 then
  1378.         gui.centerPrint(h,colors.white,nil,"Lasers starting in "..cTime.." seconds")
  1379.    
  1380.     else
  1381.         gui.drawAt(2,h,"[SCORE] "..score)
  1382.             if powerupBar > 0 then
  1383.                 gui.drawLine(w - 5,w - 1,h,nil,colors.gray)
  1384.                 gui.drawLine(w - 6,w - 6 + powerupBar,h,nil,colors.purple)
  1385.             end
  1386.     end
  1387.  
  1388. if inMenu then
  1389.         gui.drawBox(w/2 - 11,w/2 + 11,h/2 - 3,h/2 + 5,colors.gray)
  1390.         gui.drawBox(w/2 - 10,w/2 + 10,h/2 - 2,h/2 + 4,colors.white)
  1391.         for i = 1,#mOpts do
  1392.             if mNum == i then
  1393.                 gui.centerPrint((h/2 - 2) + i,colors.white,colors.red,mOpts[i].name)
  1394.             else
  1395.                 gui.centerPrint((h/2 - 2) + i,colors.red,colors.white,mOpts[i].name)
  1396.             end
  1397.         end
  1398. end    
  1399.    
  1400. end
  1401.  
  1402.  
  1403.  
  1404. --# Main part
  1405. countdown = os.startTimer(1)
  1406. while not player.dead do
  1407.  
  1408.     if player.y > h - 2 then
  1409.         player.y = h - 2
  1410.     end
  1411.  
  1412.     if botMode then
  1413.         if #bots == 0 then
  1414.             won = true
  1415.         end
  1416.        
  1417.         if won then
  1418.             break
  1419.         end
  1420.     end
  1421.  
  1422.     if multiplayer then
  1423.         if player2.dead then
  1424.             won = true
  1425.             break
  1426.         end    
  1427.     end    
  1428.     draw()
  1429.     events()
  1430. end
  1431.  
  1432. if won then
  1433.     term.setBackgroundColor(colors.lime)
  1434.     term.clear()
  1435.     gui.centerPrint(h/2,colors.white,colors.lime,"You won!")
  1436.     gui.centerPrint(h/2 + 1,colors.white,colors.lime,"Score: "..score)
  1437.     check_highscores()
  1438. else
  1439.  
  1440.     term.setBackgroundColor(colors.red)
  1441.     term.clear()
  1442.     gui.centerPrint(h/2,colors.white,colors.red,"You died!")
  1443.     gui.centerPrint(h/2 + 1,colors.white,colors.red,"Score: "..score)
  1444.     check_highscores()
  1445. end
  1446.  
  1447. sleep(1)
  1448. os.pullEvent("key")
  1449.  
  1450. rebootGame()
  1451.        
  1452. end
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461. local menu = {
  1462.  
  1463.     defLanguage = languages[tSettings.lang],
  1464.     defMenu = "Main",
  1465.    
  1466.     ["English"] = {
  1467.    
  1468.         ["Main"] = {
  1469.             title = "Lasers",
  1470.        
  1471.             [1] = {
  1472.                 name = "Single Player",
  1473.                 destination = "SP",
  1474.             },
  1475.        
  1476.             [2] = {
  1477.                 name = "Multiplayer",
  1478.                 destination = "MP",
  1479.             },
  1480.            
  1481.             [3] = {
  1482.                 name = "Highscore",
  1483.                 destination = "_function",
  1484.                 ["tFunction"] = {
  1485.                     name = view_highscores,
  1486.                 },
  1487.             },
  1488.                    
  1489.            
  1490.             [4] = {
  1491.                 name = "Settings",
  1492.                 destination = "Settings",
  1493.             },
  1494.            
  1495.             [5] = {
  1496.                 name = "Exit",
  1497.                 destination = "_exit",
  1498.             },
  1499.         },
  1500.        
  1501.         ["SP"] = {
  1502.             title = "Single Player",
  1503.            
  1504.             [1] = {
  1505.                 name = "Survival Mode",
  1506.                 destination = "_function",
  1507.                 ["tFunction"] = {
  1508.                     name = main,
  1509.                 },
  1510.             },
  1511.            
  1512.             [2] = {
  1513.                 name = "Bot Mode",
  1514.                 destination = "_function",
  1515.                 ["tFunction"] = {
  1516.                     name = main,
  1517.                     ["args"] = {
  1518.                         true,
  1519.                     },
  1520.                 },
  1521.             },
  1522.            
  1523.             [3] = {
  1524.                 name = "Back",
  1525.                 destination = "_back",
  1526.             },
  1527.         },
  1528.        
  1529.        
  1530.         ["MP"] = {
  1531.             title = "Multiplayer",
  1532.            
  1533.             [1] = {
  1534.                 name = "Host",
  1535.                 destination = "_function",
  1536.                 ["tFunction"] = {
  1537.                     name = main,
  1538.                     ["args"] = {
  1539.                         false,
  1540.                         true,
  1541.                         true,
  1542.                     },
  1543.                 },
  1544.             },
  1545.            
  1546.             [2] = {
  1547.                 name = "Join",
  1548.                 destination = "_function",
  1549.                 ["tFunction"] = {
  1550.                     name = main,
  1551.                     ["args"] = {
  1552.                         false,
  1553.                         true,
  1554.                         false,
  1555.                     },
  1556.                 },
  1557.             },
  1558.            
  1559.             [3] = {
  1560.                 name = "Back",
  1561.                 destination = "_back",
  1562.             },
  1563.         },
  1564.        
  1565.  
  1566.        
  1567.         ["Settings"] = {
  1568.             title = "Settings",
  1569.             [1] = {
  1570.                 name = languages[tSettings.lang],
  1571.                 destination = "_function",
  1572.                     ["tFunction"] = {
  1573.                         name = changeLang,
  1574.                     },
  1575.             },
  1576.            
  1577.             [2] = {
  1578.                 name = "Change Theme",
  1579.                 destination = "_function",
  1580.                 ["tFunction"] = {
  1581.                     name = changeTheme,
  1582.                 },
  1583.             },
  1584.            
  1585.             [3] = {
  1586.                 name = "Change Name",
  1587.                 destination = "_function",
  1588.                 ["tFunction"] = {
  1589.                     name = changeName,
  1590.                 },
  1591.             },
  1592.            
  1593.             [4] = {
  1594.                 name = "Back",
  1595.                 destination = "_back",
  1596.             }, 
  1597.         }, 
  1598.     }, 
  1599. }
  1600.    
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606. gui.handleMenu(menu,theme)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement