Advertisement
Guest User

controller

a guest
Jul 14th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.93 KB | None | 0 0
  1. local state
  2.  
  3. local mon = peripheral.wrap("top")
  4. mon.setTextScale(1)
  5. mon.setTextColor(colors.white)
  6. local button={}
  7. mon.setBackgroundColor(colors.black)
  8.      
  9. function setTable(name, func, xmin, xmax, ymin, ymax)
  10.    button[name] = {}
  11.    button[name]["func"] = func
  12.    button[name]["active"] = false
  13.    button[name]["xmin"] = xmin
  14.    button[name]["ymin"] = ymin
  15.    button[name]["xmax"] = xmax
  16.    button[name]["ymax"] = ymax
  17. end
  18. function caveSpider()
  19.   for name, data in pairs(button) do
  20.     if data["active"] == true then
  21.       rednet.open("left")
  22.       rednet.send(31,"spawner")
  23.       rednet.close("left")
  24.       --sleep(1)
  25.     end
  26.     if data["active"] == false then
  27.       rednet.open("left")
  28.       rednet.send(31,"spawner")
  29.       rednet.close("left")
  30.      
  31.     end
  32.   end
  33. end        
  34.  
  35. function skeleton()
  36.   --print("Doing Function")
  37.   for name, data in pairs(button) do
  38.     if data["active"] == true then
  39.       rednet.open("bottom")
  40.       rednet.send(33, "spawner")
  41.       rednet.close("bottom")
  42.     end
  43.     if data["active"] == false then
  44.       rednet.open("bottom")
  45.       rednet.send(33,"spawner")
  46.       rednet.close("bottom")
  47.     end
  48.   end      
  49. end  
  50.  
  51. function blaze()
  52.   for name, data in pairs(button) do
  53.     if data["active"] == true then
  54.       rednet.open("bottom")
  55.       rednet.send(34, "spawner")
  56.       rednet.close("bottom")
  57.       --sleep(1)
  58.     end
  59.     if data["active"] == false then
  60.       rednet.open("bottom")
  61.       rednet.send(34,"spawner")
  62.       rednet.close("bottom")
  63.       --sleep(1)
  64.     end
  65.   end
  66. end  
  67.  
  68. function zombie()
  69.   for name, data in pairs(button) do
  70.     if data["active"] == true then
  71.       rednet.open("bottom")
  72.       rednet.send(35, "spawner")
  73.       rednet.close("bottom")
  74.       --sleep(1)
  75.     end
  76.     if data["active"] == false then
  77.       rednet.open("bottom")
  78.       rednet.send(35,"spawner")
  79.       rednet.close("bottom")
  80.       --sleep(1)
  81.     end
  82.   end
  83. end
  84.  
  85. function witch()
  86.   for name, data in pairs(button) do
  87.     if data["active"] == true then
  88.       rednet.open("bottom")
  89.       rednet.send(36, "spawner")
  90.       rednet.close("bottom")
  91.       --sleep(1)
  92.     end
  93.     if data["active"] == false then
  94.       rednet.open("bottom")
  95.       rednet.send(36,"spawner")
  96.       rednet.close("bottom")
  97.       --sleep(1)
  98.     end
  99.   end
  100. end  
  101.  
  102. function miner()
  103.   for name, data in pairs(button) do
  104.     if data["active"] == true then
  105.       rednet.open("bottom")
  106.       rednet.send(50, "spawner")
  107.       rednet.close("bottom")
  108.       --sleep(1)
  109.     end
  110.     if data["active"] == false then
  111.       rednet.open("bottom")
  112.       rednet.send(50,"spawner")
  113.       rednet.close("bottom")
  114.       --sleep(1)
  115.     end
  116.   end
  117. end            
  118.  
  119. function funcName()
  120.    print("You clicked buttonText")
  121. end
  122.        
  123. function fillTable()
  124.    setTable("Cave Spider", caveSpider, 5, 20, 4, 8)
  125.    setTable("Skeleton-Disabled", skeleton, 23, 38, 4, 8)
  126.    setTable("Blaze", blaze, 41 ,56, 4,8)
  127.    setTable("Zombie", zombie, 5 ,20 , 11, 15)
  128.    setTable("Witch", witch, 23, 38, 11, 15)
  129. -- setTable("Miner", miner, 41, 56, 11, 15)
  130. -- setTable("TEST2", test2, 5, 20, 18, 22)
  131. -- setTable("TEST3", test3, 23, 38, 18, 22)  
  132. -- setTable("TEST4", test4, 41, 56, 18, 22)
  133. -- setTable("TEST5", test5, 5, 20, 25, 29)
  134. -- setTable("TEsT6", test6, 23, 38, 25, 29)
  135. --   setTable("VEXMATE", VEX, 41, 56, 25, 29)
  136. end    
  137.  
  138. function fill(text, color, bData)
  139.    mon.setBackgroundColor(color)
  140.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  141.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  142.    for j = bData["ymin"], bData["ymax"] do
  143.       mon.setCursorPos(bData["xmin"], j)
  144.       if j == yspot then
  145.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  146.             if k == xspot then
  147.                mon.write(text)
  148.             else
  149.                mon.write(" ")
  150.             end
  151.          end
  152.       else
  153.          for i = bData["xmin"], bData["xmax"] do
  154.             mon.write(" ")
  155.          end
  156.       end
  157.    end
  158.    mon.setBackgroundColor(colors.black)
  159. end
  160.      
  161. function screen()
  162.    local currColor
  163.    for name,data in pairs(button) do
  164.       local on = data["active"]
  165.       if on == true then currColor = colors.lime else currColor = colors.red end
  166.       fill(name, currColor, data)
  167.    end
  168. end
  169.      
  170. function checkxy(x, y)
  171.    for name, data in pairs(button) do
  172.       if y>=data["ymin"] and  y <= data["ymax"] then
  173.          if x>=data["xmin"] and x<= data["xmax"] then
  174.             data["func"]()
  175.             data["active"] = not data["active"]
  176.             --print(name)
  177.          end
  178.       end
  179.    end
  180. end
  181.      
  182. function heading(text)
  183.    w, h = mon.getSize()
  184.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  185.    mon.write(text)
  186. end
  187.      
  188. fillTable()
  189. while true do
  190.    mon.clear()
  191.    heading("Spawn Station Control")
  192.    screen()
  193.    local e,side,x,y = os.pullEvent("monitor_touch")
  194.    --print(x..":"..y)
  195.    checkxy(x,y)
  196.    sleep(.1)
  197. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement