craniumkid22

CellBlock

Feb 9th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.86 KB | None | 0 0
  1. local blocksState = {
  2.     [1] = false,
  3.     [2] = false,
  4.     [3] = false,
  5.     [4] = false,
  6.     [5] = false
  7.     }
  8.  
  9. local doorState = {
  10.     [1] = false,
  11.     [2] = false
  12.     }
  13.  
  14. local yardState = {
  15.     [1] = false,
  16.     [2] = false
  17.     }
  18.  
  19. local alarmState = false
  20.  
  21. local alarm = {
  22.     [1] = {color = colors.red,
  23.             x1 = 36,
  24.             x2 = 50,
  25.             y1 = 16,
  26.             y2 = 18}
  27.     }
  28. local yard = {
  29.     [1] = {color = colors.lightGray,
  30.             x1 = 2,
  31.             x2 = 16,
  32.             y1 = 2,
  33.             y2 = 9},
  34.     [2] = {color = colors.gray,
  35.             x1 = 18,
  36.             x2 = 32,
  37.             y1 = 2,
  38.             y2 = 9}
  39.     }
  40.  
  41. local blocks = {
  42.     [1] = {color = colors.white,
  43.             x1 = 11,
  44.             x2 = 13,
  45.             y1 = 11,
  46.             y2 = 14},
  47.     [2] = {color = colors.orange,
  48.             x1 = 15,
  49.             x2 = 17,
  50.             y1 = 11,
  51.             y2 = 14},
  52.     [3] = {color = colors.magenta,
  53.             x1 = 19,
  54.             x2 = 21,
  55.             y1 = 11,
  56.             y2 = 14},
  57.     [4] = {color = colors.lightBlue,
  58.             x1 = 23,
  59.             x2 = 25,
  60.             y1 = 11,
  61.             y2 = 14},
  62.     [5] = {color = colors.yellow,
  63.             x1 = 27,
  64.             x2 = 29,
  65.             y1 = 11,
  66.             y2 = 14}
  67.     }
  68.  
  69. local doors = {
  70.     [1] = {color = colors.lime,
  71.             x1 = 1,
  72.             x2 = 10,
  73.             y1 = 15,
  74.             y2 = 17},
  75.     [2] = {color = colors.pink,
  76.             x1 = 30,
  77.             x2 = 33,
  78.             y1 = 15,
  79.             y2 = 17}
  80.     }
  81.  
  82. local function openBlock(cell)
  83.     rs.setBundledOutput("bottom", colors.combine(rs.getBundledOutput("bottom") + cell))
  84. end
  85.  
  86. local function closeBlock(cell)
  87.     rs.setBundledOutput("bottom", colors.combine(rs.getBundledOutput("bottom") - cell))
  88. end
  89.  
  90. local function GUI()
  91.     for i = 1, #blocks do
  92.         term.setBackgroundColor(blocksState[i] and colors.red or colors.lime)
  93.         term.setTextColor(blocksState[i] and colors.black or colors.white)
  94.         term.setCursorPos(blocks[i].x1, blocks[i].y1)
  95.         write("+-+")
  96.         term.setCursorPos(blocks[i].x1, blocks[i].y1+1)
  97.         write("|"..i.."|")
  98.         term.setCursorPos(blocks[i].x1, blocks[i].y1+2)
  99.         write("| |")
  100.         term.setCursorPos(blocks[i].x1, blocks[i].y2)
  101.         write("+-+")
  102.         term.setCursorPos(36, i + 1)
  103.         term.setTextColor(colors.black)
  104.         term.setBackgroundColor(colors.white)
  105.         write("Block "..i..": ")
  106.         if blocksState[i] then
  107.             term.setTextColor(colors.red)
  108.             write("Open  ")
  109.         elseif not blocksState[i] then
  110.             term.setTextColor(colors.lime)
  111.             write("Closed")
  112.         end
  113.     end
  114.     for i = 1, #doors do
  115.         term.setBackgroundColor(doorState[i] and colors.red or colors.lime)
  116.         term.setTextColor(doorState[i] and colors.black or colors.white)
  117.         term.setCursorPos(doors[i].x1, doors[i].y1)
  118.         write(i == 1 and "+--------+" or "+--+")
  119.         term.setCursorPos(doors[i].x1, doors[i].y1+1)
  120.         write(i == 1 and "Processing" or "Yard")
  121.         term.setCursorPos(doors[i].x1, doors[i].y2)
  122.         write(i == 1 and "+--------+" or "+--+")
  123.         term.setTextColor(colors.black)
  124.         term.setBackgroundColor(colors.white)
  125.         term.setCursorPos(36,8)
  126.         write("Processing: ")
  127.         if doorState[1] then
  128.             term.setTextColor(colors.red)
  129.             term.setCursorPos(38, 9)
  130.             write("Open  ")
  131.         elseif not doorState[1] then
  132.             term.setTextColor(colors.lime)
  133.             term.setCursorPos(38, 9)
  134.             write("Closed")
  135.         end
  136.         term.setTextColor(colors.black)
  137.         term.setBackgroundColor(colors.white)
  138.         term.setCursorPos(36,10)
  139.         write("Yard gate: ")
  140.         if doorState[2] then
  141.             term.setTextColor(colors.red)
  142.             term.setCursorPos(38, 11)
  143.             write("Open  ")
  144.         elseif not doorState[2] then
  145.             term.setTextColor(colors.lime)
  146.             term.setCursorPos(38, 11)
  147.             write("Closed")
  148.         end
  149.     end
  150.     for i = 1, #yard do
  151.         term.setBackgroundColor(yardState[i] and colors.red or colors.lime)
  152.         term.setTextColor(yardState[i] and colors.black or colors.white)
  153.         term.setCursorPos( i == 1 and 4 or 20, 4)
  154.         write("+---------+")
  155.         term.setCursorPos( i == 1 and 4 or 20, 5)
  156.         write("| Yard  ")
  157.         write(i == 1 and "A" or "B")
  158.         write(" |")
  159.         term.setCursorPos( i == 1 and 4 or 20, 6)
  160.         write("|         |")
  161.         term.setCursorPos( i == 1 and 4 or 20, 7)
  162.         write("+---------+")
  163.         term.setTextColor(colors.black)
  164.         term.setBackgroundColor(colors.white)
  165.         term.setCursorPos(36, 12 + i)
  166.         write("Yard ")
  167.         write(i == 1 and "A: " or "B: ")
  168.         term.setTextColor(yardState[i] and colors.red or colors.lime)
  169.         write(yardState[i] and "Open  " or "Closed")
  170.     end
  171.     term.setBackgroundColor(alarmState and colors.red or colors.lime)
  172.     term.setTextColor(alarmState and colors.black or colors.white)
  173.     term.setCursorPos(39, 16)
  174.     write("+-------+")
  175.     term.setCursorPos(39, 17)
  176.     write("| Alarm |")
  177.     term.setCursorPos(39, 18)
  178.     write("+-------+")
  179. end
  180.  
  181. term.clear()
  182. for i = 1, 19 do
  183.     paintutils.drawLine(1, i, 51, i, colors.lightGray)
  184. end
  185. for i = 11, 19 do
  186.     paintutils.drawLine(10, i, 30, i, colors.black)
  187. end
  188. for i = 2, 9 do
  189.     paintutils.drawLine(2, i, 16, i, colors.black)
  190.     paintutils.drawLine(18, i, 32, i, colors.black)
  191. end
  192. for i = 3, 8 do
  193.     paintutils.drawLine(3, i, 15, i, colors.gray)
  194.     paintutils.drawLine(19, i, 31, i, colors.gray)
  195. end
  196. for i = 1, 19 do
  197.     paintutils.drawLine(35, i, 51, i, colors.white)
  198. end
  199. for i = 15, 19 do
  200.     paintutils.drawLine(11, i, 29, i, colors.gray)
  201. end
  202. GUI()
  203. rs.setBundledOutput("bottom", 0)
  204. while true do
  205.     local events = {os.pullEvent()}
  206.     if events[1] == "mouse_click" and events[2] == 1 then
  207.         for i = 1, #blocks do
  208.             if events[3] >= blocks[i].x1 and events[3] <= blocks[i].x2 then
  209.                 if events[4] >= blocks[i].y1 and events[4] <= blocks[i].y2 then
  210.                     if blocksState[i] == true then
  211.                         blocksState[i] = false
  212.                         closeBlock(blocks[i].color)
  213.                         GUI()
  214.                         break
  215.                     elseif blocksState[i] == false then
  216.                         blocksState[i] = true
  217.                         openBlock(blocks[i].color)
  218.                         GUI()
  219.                         break
  220.                     end
  221.                 end
  222.             end
  223.         end
  224.         for i = 1, #doors do
  225.             if events[3] >= doors[i].x1 and events[3] <= doors[i].x2 then
  226.                 if events[4] >= doors[i].y1 and events[4] <= doors[i].y2 then
  227.                     if doorState[i] == true then
  228.                         doorState[i] = false
  229.                         closeBlock(doors[i].color)
  230.                         GUI()
  231.                         break
  232.                     elseif doorState[i] == false then
  233.                         doorState[i] = true
  234.                         openBlock(doors[i].color)
  235.                         GUI()
  236.                         break
  237.                     end
  238.                 end
  239.             end
  240.         end
  241.         for i = 1, #yard do
  242.             if events[3] >= yard[i].x1 and events[3] <= yard[i].x2 then
  243.                 if events[4] >= yard[i].y1 and events[4] <= yard[i].y2 then
  244.                     if yardState[i] == true then
  245.                         yardState[i] = false
  246.                         closeBlock(yard[i].color)
  247.                         GUI()
  248.                         break
  249.                     elseif yardState[i] == false then
  250.                         yardState[i] = true
  251.                         openBlock(yard[i].color)
  252.                         GUI()
  253.                         break
  254.                     end
  255.                 end
  256.             end
  257.         end
  258.         if events[3] >= alarm[1].x1 and events[3] <= alarm[1].x2 then
  259.             if events[4] >= alarm[1].y1 and events[4] <= alarm[1].y2 then
  260.                 if alarmState == true then
  261.                     alarmState = false
  262.                     rs.setBundledOutput("bottom", 0)
  263.                     GUI()
  264.                 elseif alarmState == false then
  265.                     alarmState = true
  266.                     for i = 1, #blocksState do
  267.                         blocksState[i] = false
  268.                     end
  269.                     for i = 1, #yardState do
  270.                         yardState[i] = false
  271.                     end
  272.                     for i = 1, #doorState do
  273.                         doorState[i] = false
  274.                     end
  275.                     rs.setBundledOutput("bottom", colors.red)
  276.                     GUI()
  277.                 end
  278.             end
  279.         end
  280.     end
  281. end
Advertisement
Add Comment
Please, Sign In to add comment