Nessiesson

Evil tower touchscreen 1

Feb 8th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. --Created by Pixelmnkey, modified by NessieHC
  2.  
  3. --(possibly save in a local variable?)
  4. --load-from-file TEST
  5. --load-from-file ToggleTest
  6.  
  7. local mon = peripheral.wrap("top")
  8. mon.setTextScale(1)
  9. mon.setTextColor(colors.white)
  10. local button={}
  11. mon.setBackgroundColor(colors.black)
  12.        
  13. function setTable(name, func, xmin, xmax, ymin, ymax)
  14.   button[name] = {}
  15.   button[name]["func"] = func
  16.   button[name]["active"] = false
  17.   button[name]["xmin"] = xmin
  18.   button[name]["ymin"] = ymin
  19.   button[name]["xmax"] = xmax
  20.   button[name]["ymax"] = ymax
  21. end
  22.  
  23.  
  24. --function test()
  25. --  print("test")
  26. --  if ToggleValueTEST == 0 do
  27. --    ToggleValueTEST = 1
  28. --    save-to-file TEST
  29. --    newValue (colourNumber) + ValueOfMob(colour)
  30. --    save-to-file ToggleTest
  31. --  else
  32. --    ToggleValueTEST = 0
  33. --    save-to-file TEST
  34. --    newValue (colournumber) - ValueOfMob(colour=
  35. --    save-to-file ToggleTest
  36. --  end
  37.  
  38. function zombie()
  39.   print("Zombie")
  40.   redstone.setBundledOutput("bottom", colors.white)
  41.   os.sleep(.1)
  42.   redstone.setBundledOutput("bottom", 0)
  43. end
  44.  
  45. function angryZombie()
  46.   print("Angry Zombie")
  47.   redstone.setBundledOutput("bottom", colors.orange)
  48.   os.sleep(.1)
  49.   redstone.setBundledOutput("bottom", 0)
  50. end
  51.  
  52. function skeleton()
  53.   print("Skeleton")
  54.   redstone.setBundledOutput("bottom", colors.magenta)
  55.   os.sleep(.1)
  56.   redstone.setBundledOutput("bottom", 0)
  57. end
  58.  
  59. function witherSkeleton()
  60.   print("Wither Skeleton")
  61.   redstone.setBundledOutput("bottom", colors.lightBlue)
  62.   os.sleep(.1)
  63.   redstone.setBundledOutput("bottom", 0)
  64. end
  65.  
  66. function creeper()
  67.   print("Creeper")
  68.   redstone.setBundledOutput("bottom", colors.yellow)
  69.   os.sleep(.1)
  70.   redstone.setBundledOutput("bottom", 0)
  71. end
  72.  
  73. function enderman()
  74.   print("Enderman")
  75.   redstone.setBundledOutput("bottom", colors.lime)
  76.   os.sleep(.1)
  77.   redstone.setBundledOutput("bottom", 0)
  78. end
  79.  
  80. function slime()
  81.   print("Slime")
  82.   redstone.setBundledOutput("bottom", colors.pink)
  83.   os.sleep(.1)
  84.   redstone.setBundledOutput("bottom", 0)
  85. end
  86.  
  87. function magmaCube()
  88.   print("Magma Cube")
  89.   redstone.setBundledOutput("bottom", colors.gray)
  90.   os.sleep(.1)
  91.   redstone.setBundledOutput("bottom", 0)
  92. end
  93.  
  94. function zombiePigman()
  95.   print("Zombie Pigman")
  96.   redstone.setBundledOutput("bottom", colors.lightGray)
  97.   os.sleep(.1)
  98.   redstone.setBundledOutput("bottom", 0)
  99. end
  100.  
  101. function witch()
  102.   print("Witch")
  103.   redstone.setBundledOutput("bottom", colors.cyan)
  104.   os.sleep(.1)
  105.   redstone.setBundledOutput("bottom", 0)
  106. end
  107.  
  108. function fillTable()
  109.   setTable("Zombie", zombie, 2, 17, 2, 2)
  110.   setTable("Angry Zombie", angryZombie, 2, 17, 4, 4)
  111.   setTable("Skeleton", skeleton, 2, 17, 6, 6)
  112.   setTable("Wither Skeleton", witherSkeleton, 2, 17, 8, 8)
  113.   setTable("Creeper", creeper, 2, 17, 10, 10)
  114.   setTable("Enderman", enderman, 2, 17, 12, 12)
  115.   setTable("Slime", slime, 2, 17, 14, 14)
  116.   setTable("Magma Cube", magmaCube, 2, 17, 16, 16)
  117.   setTable("Zombie Pigman", zombiePigman, 2, 17, 18, 18)
  118.   setTable("Witch", witch, 2, 17, 20, 20)
  119. end  
  120.  
  121. function fill(text, color, bData)
  122.   mon.setBackgroundColor(color)
  123.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  124.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  125.   for j = bData["ymin"], bData["ymax"] do
  126.     mon.setCursorPos(bData["xmin"], j)
  127.       if j == yspot then
  128.         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  129.           if k == xspot then
  130.             mon.write(text)
  131.               else
  132.                 mon.write(" ")
  133.               end
  134.           end
  135.         else
  136.           for i = bData["xmin"], bData["xmax"] do
  137.             mon.write(" ")
  138.           end
  139.         end
  140.       end
  141.   mon.setBackgroundColor(colors.black)
  142. end
  143.        
  144. function screen()
  145.   local currColor
  146.   for name,data in pairs(button) do
  147.     local on = data["active"]
  148.     if on == true then currColor = colors.lime else currColor = colors.red end
  149.     fill(name, currColor, data)
  150.   end
  151. end
  152.        
  153. function checkxy(x, y)
  154.   for name, data in pairs(button) do
  155.     if y>=data["ymin"] and  y <= data["ymax"] then
  156.       if x>=data["xmin"] and x<= data["xmax"] then
  157.         data["func"]()
  158.         data["active"] = not data["active"]
  159.         print(name)
  160.       end
  161.     end
  162.   end
  163. end
  164.        
  165. function heading(text)
  166.   w, h = mon.getSize()
  167.   mon.setCursorPos((w-string.len(text))/2+1, 1)
  168.   mon.write(text)
  169. end
  170.        
  171. fillTable()
  172. while true do
  173.   mon.clear()
  174.   heading("Mob Control")
  175.   screen()
  176.   local e,side,x,y = os.pullEvent("monitor_touch")
  177.   print(x..":"..y)
  178.   checkxy(x,y)
  179.   sleep(.1)
  180. end
Advertisement
Add Comment
Please, Sign In to add comment