Guest User

arcadeos

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