Advertisement
Guest User

door.lua

a guest
Feb 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local sides = require("sides")
  4. local gpu = component.gpu
  5. gpu.setResolution(50,25)
  6.  
  7. local left = component.proxy(component.get("3ba"))
  8. local mid = component.proxy(component.get("280"))
  9. local right = component.proxy(component.get("0cb"))
  10. local close = false
  11. local state = false
  12. gpu.setResolution(100,50)
  13. local w,h = gpu.getResolution()
  14.  
  15. --Left - Floor
  16. --Mid - Door
  17. --Right - Corridor
  18.  
  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 button(_,_,_,_,_)
  32.   if state == false then
  33.     gpu.setBackground(0xcc0000)
  34.     gpu.fill(1,1,w,h," ")
  35.     closedoor()
  36.   end
  37.  
  38.   if state == true then
  39.     gpu.setBackground(0x00cc00)
  40.     gpu.fill(1,1,w,h," ")
  41.     opendoor()
  42.   end
  43.  
  44.   if state == false then
  45.     state = true
  46.   elseif state == true then
  47.     state = false
  48.   end
  49. end
  50.  
  51. function exit(_,_,_,z,_)
  52.   if z == 207 then
  53.     event.ignore("key_down", exit)
  54.     event.ignore("touch", button)
  55.     close = true
  56.   end
  57. end
  58.  
  59. event.listen("touch", button)
  60. event.listen("key_down", exit)
  61.  
  62. button()
  63.  
  64. while true do
  65.   if close == true then
  66.     break
  67.   end
  68.   os.sleep(1)
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement