NielsUtrecht

arena

May 19th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. local monitor = peripheral.wrap("right")
  2. local locCable = "back"
  3.  
  4. local selected = 0
  5. local white = 0
  6. local red = 0
  7. local green = 0
  8. local blue = 0
  9. local yellow = 0
  10.  
  11. function setRedstone()
  12.     redstone.setBundledOutput(locCable, colors.white * white + colors.red * red + colors.green * green + colors.blue * blue + colors.yellow * yellow)
  13. end
  14.  
  15. function setMenuColor(selected)
  16.     if selected then
  17.         monitor.setBackgroundColor(colors.orange )
  18.     else
  19.         monitor.setBackgroundColor(colors.black )
  20.     end
  21. end
  22.  
  23. function resetScreen()
  24.     monitor.setTextScale(2)
  25.     monitor.setBackgroundColor(colors.black )
  26.     monitor.clear()
  27.     monitor.setTextColor(colors.white)
  28.     monitor.setCursorPos(1, 1)
  29.     monitor.write("Welcome to the")
  30.     monitor.setTextColor(colors.red)
  31.     monitor.setCursorPos(1, 2)
  32.     monitor.write("    ARENA") 
  33.     monitor.setCursorPos(1, 4)
  34.     monitor.setTextColor(colors.white)
  35.     monitor.write("Fields:")
  36.     monitor.setCursorPos(4, 5)
  37.     setMenuColor(white == 1)
  38.     monitor.write("[ Main   ]")
  39.     monitor.setCursorPos(4, 6)
  40.     setMenuColor(red == 1)
  41.     monitor.write("[ Red    ]")
  42.     monitor.setCursorPos(4, 7)
  43.     setMenuColor(green == 1)
  44.     monitor.write("[ Green  ]")
  45.     monitor.setCursorPos(4, 8)
  46.     setMenuColor(blue == 1)
  47.     monitor.write("[ Blue   ]")
  48.     monitor.setCursorPos(4, 9)
  49.     setMenuColor(yellow == 1)
  50.     monitor.write("[ Yellow ]")
  51. end
  52.  
  53. function handleMessage(msg)
  54.     print("Msg ", msg)
  55. end
  56.  
  57. function toggle(value)
  58.     if value > 0 then
  59.         return 0
  60.     else
  61.         return 1
  62.     end
  63. end
  64.  
  65. function click(row)
  66.     if row == 5 then
  67.         white = toggle(white)
  68.         if white == 0 then
  69.             red = 0
  70.             green = 0
  71.             blue = 0
  72.             yellow = 0
  73.         end
  74.     elseif row == 6 and white == 1 then
  75.         red = toggle(red)
  76.     elseif row == 7 and white == 1 then
  77.         green = toggle(green)
  78.     elseif row == 8 and white == 1 then
  79.         blue = toggle(blue)
  80.     elseif row == 9 and white == 1 then
  81.         yellow = toggle(yellow)
  82.     end
  83.     setRedstone()
  84. end
  85.  
  86. function handleTouch(p1, p2, p3, p4, p5)
  87.     print("x:",p2,", y:", p3)
  88.     if p3 >= 5 and p3 <= 9 and p2 >= 4 and p2 <= 14 then
  89.         click(p3)
  90.         resetScreen()
  91.     end
  92. end
  93.  
  94. resetScreen()
  95.  
  96. while true do
  97.     local event, p1, p2, p3, p4, p5 = os.pullEvent()
  98.     print(event, ": ", p1)
  99.     if event == "rednet_message" then
  100.         handleMessage(p2)
  101.     elseif event == "monitor_touch" then
  102.         handleTouch(p1, p2, p3, p4, p5)
  103.     end
  104.    
  105. end
Advertisement
Add Comment
Please, Sign In to add comment