spenk

main

May 25th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.67 KB | None | 0 0
  1. os.loadAPI("CCGUI");
  2. os.loadAPI("RPAPI")
  3.  
  4. local side = "back";
  5.  
  6. local running = RPAPI.getPower(side, "black");
  7.  
  8. local up = "green";
  9. local down = "lime";
  10.  
  11. function pulse(dir, dist)
  12.     RPAPI.setPower(side, "black", true);
  13.     for i=0, dist, 1 do
  14.         RPAPI.setPower(side, dir, true);
  15.         os.sleep(1);
  16.         RPAPI.setPower(side, dir, false);
  17.         os.sleep(1);
  18.     end
  19.     RPAPI.setPower(side, "black", false);
  20. end
  21.  
  22. function getLvl()
  23.     if RPAPI.getPower(side, "magenta") == true then
  24.         return 1;
  25.     elseif RPAPI.getPower(side, "purple") == true then
  26.         return 2;
  27.     elseif RPAPI.getPower(side, "brown") == true then
  28.         return 3;
  29.     elseif RPAPI.getPower(side, "lightBlue") == true then
  30.         return 4;
  31.     elseif RPAPI.getPower(side, "yellow") == true then
  32.         return 5;
  33.     elseif RPAPI.getPower(side, "lightGray") == true then
  34.         return 6;
  35.     elseif RPAPI.getPower(side, "gray") == true then
  36.         return 7;
  37.     elseif RPAPI.getPower(side, "white") == true then
  38.         return 8;
  39.     elseif RPAPI.getPower(side, "orange") == true then
  40.         return 9;
  41.     end
  42.  
  43. end
  44.  
  45. function getDir(from, to)
  46.     if from > to then
  47.         return up;
  48.     else
  49.         return down;
  50.     end
  51. end
  52.  
  53. function calcDist(from, to, dir)
  54.     local dif = 0;
  55.     local layers = 0;
  56.     if from == 1 or to == 1 then
  57.         dif = 3;
  58.     end
  59.  
  60.     if dir == up then
  61.         layers = from - to;
  62.     else
  63.         layers = to - from;
  64.     end
  65.  
  66.     layers = (layers * 8) - dif;
  67.  
  68.     return layers;
  69.  
  70. end
  71.  
  72. function procesPress(to)
  73.     local dir = getDir(getLvl(), to);
  74.     local dist = calcDist(getLvl(), to, dir);
  75.     pulse(dir, dist);
  76. end
  77.  
  78.  
  79. function drawScreen()
  80.     def = CCGUI.newMenu()
  81.  
  82.     b1 = CCGUI.newItem()
  83.     b2 = CCGUI.newItem()
  84.     b3 = CCGUI.newItem()
  85.     b4 = CCGUI.newItem()
  86.     b5 = CCGUI.newItem()
  87.     b6 = CCGUI.newItem()
  88.     b7 = CCGUI.newItem()
  89.     b8 = CCGUI.newItem()
  90.     b9 = CCGUI.newItem()
  91.  
  92.  
  93.     b1:newName("[ 1]")
  94.     b1:newType("bp1")
  95.     b1:newColour(colours.magenta)
  96.  
  97.     b2:newName("[ 0]")
  98.     b2:newType("bp2")
  99.     b2:newColour(colours.magenta)
  100.  
  101.     b3:newName("[-1]")
  102.     b3:newType("bp3")
  103.     b3:newColour(colours.magenta)
  104.  
  105.     b4:newName("[-2]")
  106.     b4:newType("bp4")
  107.     b4:newColour(colours.magenta)
  108.  
  109.     b5:newName("[-3]")
  110.     b5:newType("bp5")
  111.     b5:newColour(colours.magenta)
  112.  
  113.     b6:newName("[-4]")
  114.     b6:newType("bp6")
  115.     b6:newColour(colours.magenta)
  116.  
  117.     b7:newName("[-5]")
  118.     b7:newType("bp7")
  119.     b7:newColour(colours.magenta)
  120.  
  121.     b8:newName("[-6]")
  122.     b8:newType("bp8")
  123.     b8:newColour(colours.magenta)
  124.  
  125.     b9:newName("[-7]")
  126.     b9:newType("bp9")
  127.     b9:newColour(colours.magenta)
  128.  
  129.  
  130.     def:newItem(b1)
  131.     def:newItem(b2)
  132.     def:newItem(b3)
  133.     def:newItem(b4)
  134.     def:newItem(b5)
  135.     def:newItem(b6)
  136.     def:newItem(b7)
  137.     def:newItem(b8)
  138.     def:newItem(b9)
  139.  
  140.     while true do
  141.         bp = def:draw()
  142.         if bp =="bp1" then procesPress(1); CCGUI.msgBox({"Going to 1" , "They see me rollin","They waitin"}); end
  143.         if bp =="bp2" then procesPress(2); CCGUI.msgBox({"Going to 0" ,"They see me rollin","They waitin"}); end
  144.         if bp =="bp3" then procesPress(3); CCGUI.msgBox({"Going to -1","They see me rollin","They waitin"}); os.reboot(); end
  145.         if bp =="bp4" then procesPress(4); CCGUI.msgBox({"Going to -2","They see me rollin","They waitin"}); os.reboot(); end
  146.         if bp =="bp5" then procesPress(5); CCGUI.msgBox({"Going to -3","They see me rollin","They waitin"}); os.reboot(); end
  147.         if bp =="bp6" then procesPress(6); CCGUI.msgBox({"Going to -4","They see me rollin","They waitin"}); os.reboot(); end
  148.         if bp =="bp7" then procesPress(7); CCGUI.msgBox({"Going to -5","They see me rollin","They waitin"}); os.reboot(); end
  149.         if bp =="bp8" then procesPress(8); CCGUI.msgBox({"Going to -6","They see me rollin","They waitin"}); os.reboot(); end
  150.         if bp =="bp9" then procesPress(9); CCGUI.msgBox({"Going to -7","They see me rollin","They waitin"}); os.reboot(); end
  151.     end
  152. end
  153. drawScreen()
Advertisement
Add Comment
Please, Sign In to add comment