Advertisement
Guest User

startup

a guest
May 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. mon = peripheral.find("monitor")
  2. rednet.open("right")
  3. cablePos = "back"
  4. etage = "HALL"
  5. dyh = 0
  6. dyb = 6
  7.  
  8. function windowInit(win, bgColor, cursorX, cursorY, text)
  9.     win.setBackgroundColor(bgColor)
  10.     win.clear()
  11.     win.setCursorPos(cursorX, cursorY)
  12.     win.write(text)
  13. end
  14.  
  15. function monInit()
  16.     mon.setBackgroundColor(colors.lightGray)
  17.     mon.clear()
  18.     mon.setTextScale(0.5)
  19.     mon.setCursorPos(5,1)
  20.     mon.write(etage)
  21.     if dyh>0 then
  22.         up = window.create(mon, 2, 3, 13, 10)
  23.         windowInit(up, colors.lightBlue, 6, 5, "HALL")
  24.     end
  25.     if dyb>0 then
  26.         down = window.create(mon, 2, 14, 13, 10)
  27.         windowInit(down, colors.orange, 4, 5, "ETAGE -1")
  28.     end
  29. end
  30.  
  31. function move(slp, dy, color)
  32.     local i = 0
  33.     while i<dy do
  34.         rs.setBundledOutput(cablePos, color)
  35.         sleep(slp)
  36.         rs.setBundledOutput(cablePos, 0)
  37.         sleep(slp)
  38.         i = i+1
  39.     end
  40. end
  41.  
  42. function touchedWindow(win, ex, ey)
  43.     local x, y = win.getPosition()
  44.     return ((ex>=x) and (ex<=x+12) and (ey>=y) and (ey<=y+9))
  45. end
  46.  
  47. function touchedButton(win)
  48.     win.setBackgroundColor(colors.lightGray)
  49.     win.clear()
  50.     win.setVisible(false)
  51. end
  52.  
  53. monInit()
  54. while true do
  55.     local e, p1, p2, p3 = os.pullEvent()
  56.     if e=="monitor_touch" then
  57.         x = p2
  58.         y = p3
  59.         if (up~=nil) and touchedWindow(up, x, y) then
  60.             rednet.broadcast("elevator_left")
  61.             touchedButton(up)
  62.             move(0.5, dyh, colors.blue)
  63.             rednet.broadcast("", "elevator_left")
  64.             os.reboot()
  65.         end
  66.         if (down~=nil) and touchedWindow(down, x, y) then
  67.             rednet.broadcast("elevator_left")
  68.             touchedButton(down)
  69.             move(0.5, dyb, colors.orange)
  70.             rednet.broadcast("", "elevator_left")
  71.             os.reboot()
  72.         end
  73.     elseif e=="rednet_message" then
  74.         msg = p2
  75.         if msg=="elevator_left" then
  76.             if up~=nil then touchedButton(up) end
  77.             if down~=nil then touchedButton(down) end
  78.             rednet.receive("elevator_left", 10)
  79.             os.reboot()
  80.         end
  81.     end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement