daily pastebin goal
34%
SHARE
TWEET

door.lua

a guest Feb 16th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Get Libraries
  2. local component = require("component")
  3. local computer = require("computer")
  4. local event = require("event")
  5. local sides = require("sides")
  6.  
  7. --Get Redstone IO
  8. local left = component.proxy(component.get("4d487"))
  9. local mid = component.proxy(component.get("548cb"))
  10. local right = component.proxy(component.get("b4b42"))
  11. --  Left=Floor  Mid=Door  Right=Corridor
  12.  
  13. local gpu = component.gpu
  14. gpu.setResolution(50,25)
  15. local w,h = gpu.getResolution()
  16.  
  17. local close = false
  18. ----------------------FUNCTIONS----------------------------
  19. function opendoor()
  20.   left.setOutput(sides.bottom, 15)
  21.   right.setOutput(sides.bottom, 15)
  22.   mid.setOutput(sides.bottom, 15)
  23. end
  24.  
  25. function closedoor()
  26.   mid.setOutput(sides.bottom, 0)
  27.   left.setOutput(sides.bottom, 0)
  28.   right.setOutput(sides.bottom, 0)
  29. end
  30.  
  31. function centerwrite(y,z)
  32.   local len = string.len(z)
  33.   local x = (w / 2) - (len / 2) + 1
  34.   gpu.set(x,y,z)
  35. end
  36.  
  37. function init()
  38.   state = false
  39.   gpu.setBackground(0xcc0000)
  40.   gpu.fill(1,1,w,h," ")
  41.   closedoor()
  42. end
  43.  
  44. function button(_,_,_,_,_,name)
  45.   event.ignore("touch", button)
  46.   if name == "UndercoverQuasar" or name == "EvolutionHaze" then
  47.     if state == false then
  48.       state = true
  49.     elseif state == true then
  50.       state = false
  51.     end
  52.  
  53.     if state == false then
  54.       gpu.setBackground(0xcc0000)
  55.       gpu.fill(1,1,w,h," ")
  56.       centerwrite(h/2,"Goodbye")
  57.       closedoor()
  58.       os.sleep(2)
  59.       gpu.fill(1,1,w,h," ")
  60.     end
  61.  
  62.     if state == true then
  63.       gpu.setBackground(0x00cc00)
  64.       gpu.fill(1,1,w,h," ")
  65.       centerwrite(h/2,"Welcome ")
  66.       centerwrite((h/2)+1,name)
  67.       opendoor()
  68.       os.sleep(2)
  69.       gpu.fill(1,1,w,h," ")
  70.     end
  71.  
  72.   else
  73.     closedoor()
  74.     gpu.setBackground(0xcc0000)
  75.     gpu.fill(1,1,w,h," ")
  76.     centerwrite(h/2,"ACCESS DENIED")
  77.     computer.beep(2000,0.5)
  78.   end
  79.  
  80.   os.sleep(1)
  81.   event.listen("touch", button)
  82. end
  83.  
  84. function exit(_,_,_,z,_)
  85.   if z == 207 then
  86.     close = true
  87.   end
  88. end
  89. ----------------------FUNCTIONS END -----------------------
  90.  
  91. --Setup event listeners
  92. event.listen("touch", button)
  93. event.listen("key_down", exit)
  94.  
  95. --Set door to closed on startup
  96. init()
  97.  
  98. --Check if program has been exited
  99. while true do
  100.   if close == true then
  101.     event.ignore("key_down", exit)
  102.     event.ignore("touch", button)
  103.     gpu.setResolution(100,50)
  104.     break
  105.   end
  106.   os.sleep(1)
  107. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top