CaptainPi

CC Turtle controller

Jan 22nd, 2017 (edited)
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. os.loadAPI("/pilabs/apis/button.lua")
  2.  
  3. local function draw()
  4.   term.setBackgroundColour(colours.black)
  5.   term.clear()
  6.   term.setBackgroundColour(colours.green)
  7.   term.setTextColour(colours.black)
  8.   for i, object in ipairs(buttons) do
  9.     button.draw(object)
  10.   end
  11.   term.setBackgroundColour(colours.black)
  12.   term.setTextColour(colours.white)
  13. end
  14.  
  15. local function click(x, y)
  16.   for i, object in ipairs(buttons) do
  17.     if button.inBounds(object, x, y) then
  18.       if object.action then
  19.         object.action()
  20.       end
  21.     end
  22.   end
  23. end
  24.  
  25. local function key(key)
  26.   if key == 87 then
  27.     turtle.forward()
  28.   elseif key == 65 then
  29.     turtle.turnLeft()
  30.   elseif key == 83 then
  31.     turtle.back()
  32.   elseif key == 68 then
  33.     turtle.turnRight()
  34.   elseif key == 69 then
  35.     turtle.down()
  36.   elseif key == 81 then
  37.     turtle.up()
  38.   end
  39. end
  40.  
  41. local function net(id, message)
  42.  
  43. end
  44.  
  45. local buttons = {
  46.   button.new(2, 2, 4, 3, "UP",
  47.     function()
  48.       turtle.up()
  49.     end
  50.   ),
  51.   button.new(7, 2, 4, 3, "FD",
  52.     function()
  53.       turtle.forward()
  54.     end
  55.   ),
  56.   button.new(12, 2, 4, 3, "DN",
  57.     function()
  58.       turtle.down()
  59.     end
  60.   ),
  61.   button.new(2, 6, 4, 3, "TL",
  62.     function()
  63.       turtle.turnLeft()
  64.     end
  65.   ),
  66.   button.new(7, 6, 4, 3, "BK",
  67.     function()
  68.       turtle.back()
  69.     end
  70.   ),
  71.   button.new(12, 6, 4, 3, "TR",
  72.     function()
  73.       turtle.turnRight()
  74.     end
  75.   ),
  76.   button.new(2, 10, 4, 3, "SU",
  77.     function()
  78.       turtle.suckUp()
  79.     end
  80.   ),
  81.   button.new(7, 10, 4, 3, "SF",
  82.     function()
  83.       turtle.suck()
  84.     end
  85.   ),
  86.   button.new(12, 10, 4, 3, "SD",
  87.     function()
  88.       turtle.suckDown()
  89.     end
  90.   ),
  91.   button.new(25, 2, 4, 3, "AU",
  92.     function()
  93.  
  94.     end
  95.   ),
  96.   button.new(30, 2, 4, 3, "AF",
  97.     function()
  98.  
  99.     end
  100.   ),
  101.   button.new(35, 2, 4, 3, "AD",
  102.     function()
  103.  
  104.     end
  105.   ),
  106.   button.new(25, 6, 4, 3, "PU",
  107.     function()
  108.  
  109.     end
  110.   ),
  111.   button.new(30, 6, 4, 3, "PF",
  112.     function()
  113.  
  114.     end
  115.   ),
  116.   button.new(35, 6, 4, 3, "PD",
  117.     function()
  118.  
  119.     end
  120.   ),
  121.   button.new(25, 10, 4, 3, "",
  122.     function()
  123.  
  124.     end
  125.   ),
  126.   button.new(30, 10, 4, 3, "",
  127.     function()
  128.  
  129.     end
  130.   ),
  131.   button.new(35, 10, 4, 3, "",
  132.     function()
  133.  
  134.     end
  135.   ),
  136.   button.new(17, 2, 7, 3, "APPS",
  137.     function()
  138.       --shell.run("/pilabs/turtle/appmenu.lua")
  139.       draw()
  140.     end
  141.   ),
  142.   button.new(17, 6, 7, 3, "TOOLS"),
  143.   button.new(17, 10, 7, 3, "EXTRA")
  144.  
  145. }
  146.  
  147. draw()
  148. while true do
  149.   local event, n, x, y = os.pullEvent()
  150.   if event == "mouse_click" and n == 1 then
  151.     click(x,y)
  152.   elseif event == "key" then
  153.     key(n)
  154.   elseif event == "rednet_message" then
  155.     net(n,x)
  156.   end
  157. end
  158.  
Advertisement
Add Comment
Please, Sign In to add comment