5bitesofcookies

final arcade thingy patch

Jun 6th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.pullEvent = os.pullEventRaw
  2. --This is NOT INTENDED FOR USE ON
  3. --PERSONAL COMPUTERS!
  4. --ignore this:
  5. --[[------
  6. CONFIG]]
  7. function config()
  8.   --ignore this:
  9.   game = {}
  10.   gameDirr = {}
  11.   --CONFIG:
  12.   game[1] = "gamenamehere"
  13.   game[2] = "ddas"
  14.   game[3] = "d"
  15.   game[4] = "a"
  16.   gameDirr[1] = "examplefolder/examplegame"
  17.   gameDirr[2] = ""
  18.   gameDirr[3] = "worm"
  19.   gameDirr[4] = ""
  20.   masterpassword = "PLEASE change this"
  21. end
  22. ---------
  23.  
  24.  
  25. arcade = {}
  26. function arcade.int()
  27.   config()
  28.   insertCoin = paintutils.loadImage("recources/insertcoin")
  29.   arcade.title()
  30.   arcade.gameMenu()
  31.   os.reboot()
  32. end
  33. function arcade.title()
  34.   term.clear()
  35.   paintutils.drawImage(insertCoin,21,1)
  36.   term.setCursorPos(19,10)
  37.   term.setBackgroundColor(colors.black)
  38.   term.write("INSERT COIN!")
  39.   term.setCursorPos(19,10)
  40.   flash = true
  41.   while true do
  42.     flashTime = os.startTimer(2)
  43.     timesFlashed = 0
  44.     --^^this is is 30 we shutdown
  45.     event,but,x,y= os.pullEvent()
  46.     if event == "mouse_click"then
  47.       if x==51 and y==19 then
  48.         arcade.adminMenu()
  49.         return -- if they fail
  50.        else
  51.         return
  52.       end
  53.     elseif event == "timer" and but == flashTime and flash == true then
  54.       term.setCursorPos(19,10)
  55.       term.write("            ")
  56.       flash = false
  57.       timesFlashed = timesFlashed +1
  58.     elseif event =="timer" and but == flashTime and flash == false then
  59.       term.setCursorPos(19,10)
  60.       term.write("INSERT COIN!")
  61.       flash = true
  62.       timesFlashed = timesFlashed+1
  63.     end
  64.     if timesFlashed > 29 then
  65.       os.shutdown()
  66.     end
  67.   end
  68. end
  69. function arcade.adminMenu()
  70.   print("Admin menu. Enter password, enter to exit")
  71.   local trypass = read()
  72.   if trypass==masterpassword then
  73.     shell.run("shell")
  74.     error("An admin killed the program")
  75.   end
  76. end
  77. function arcade.gameMenu()
  78.   term.setBackgroundColor(colors.black)
  79.   term.clear()
  80.   term.setCursorPos(23,4)
  81.   term.setTextColor(colors.red)
  82.   print"MENU:"
  83.   term.setTextColor(colors.white)
  84.   term.setCursorPos((51-#game[1])/2,8)
  85.   print(game[1])
  86.   term.setCursorPos((51-#game[2])/2,9)
  87.   print(game[2])
  88.   term.setCursorPos((51-#game[3])/2,10)
  89.   print(game[3])
  90.   term.setCursorPos((51-#game[4])/2,11)
  91.   print(game[4])
  92.   local selected = 8
  93.   local selectedGame =1
  94.   while true do
  95.     for i=8,11 do
  96.       term.setCursorPos(((51-#game[i-7])/2)-1,i)
  97.       term.write(" ")
  98.       term.setCursorPos(((51-#game[i-7])/2)+#game[i-7],i)
  99.       term.write(" ")
  100.     end
  101.     term.setCursorPos(((51-#game[selectedGame])/2)-1,selected)
  102.     term.write(">")
  103.     term.setCursorPos(((51-#game[selectedGame])/2)+#game[selectedGame],selected)
  104.     term.write("<")
  105.     local _,key=os.pullEvent("key")
  106.     if key==200 and selectedGame>1 then
  107.       selected = selected-1
  108.       selectedGame = selectedGame-1
  109.     elseif key == 208 and selectedGame<4 then
  110.       selected=selected+1
  111.       selectedGame=selectedGame+1
  112.     elseif key == 28 then
  113.      arcade.handleGame(gameDirr[selectedGame])
  114.      os.reboot() -- to ensure a reboot
  115.     end
  116.   end
  117. end
  118. function arcade.handleGame(path)
  119.   --finally, no more GUI coding
  120.   --GUI coding requires SO MUCH MATHS :C
  121.   --this should be a very simple function. I hope.
  122.   --print"handlegame"
  123.   --sleep(5)
  124.   shell.run(path)
  125.   --print"die"
  126.   os.reboot()
  127.   --we have this here incase more must be added
  128. end
  129. function arcade.handleAutoShutoff()
  130.   gameCo = coroutine.create(arcade.int)
  131.   os.startTimer(0.05)
  132.   while true do
  133.     --print"res"
  134.     shutoffTimer = os.startTimer(60) --1 minute shutoff timer
  135.     while true do
  136.       events = {os.pullEvent()}
  137.       if events[1] == "timer" then
  138.         --print"tim"
  139.         if events[2] == shutoffTimer then
  140.           --print"ye"
  141.           os.shutdown()
  142.         end
  143.       end
  144.       if events[1] == evt or evt == nil then
  145.         err, evt = coroutine.resume(gameCo, unpack(events))
  146.         --print"Break"
  147.         break
  148.       end
  149.       if coroutine.status == "dead" then
  150.         os.reboot()
  151.       end
  152.     end
  153.   end
  154.   print("ded")
  155.   print(err)
  156.   print(evt)
  157.   if err == "An admin killed the program" then else
  158.     os.reboot() --cheapo way of restart thing :P
  159.   end
  160. end
  161. arcade.handleAutoShutoff()
Advertisement
Add Comment
Please, Sign In to add comment