Advertisement
Guest User

door.lua

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