Advertisement
koki2000

turtle remote control

Dec 29th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. rednet.open("back")
  2.  
  3. w, h = term.getSize()
  4. run = true
  5.  
  6. gomb = {}
  7. gomb[1] = {xs = w/2-2, ys = h-7, xe = w/2+2, ye = h-7, color = colors.red, text = "up"}
  8. gomb[2] = {xs = w/2-2, ys = h-5, xe = w/2+2, ye = h-5, color = colors.red, text = "fd"}
  9. gomb[3] = {xs = w/2-2, ys = h-3, xe = w/2+2, ye = h-3, color = colors.red, text = "back"}
  10. gomb[4] = {xs = w/2-2, ys = h-1, xe = w/2+2, ye = h-1, color = colors.green, text = "down"}
  11. gomb[5] = {xs = w/2-8, ys = h-3, xe = w/2-4, ye = h-1, color = colors.white, text = "left"}
  12. gomb[6] = {xs = w/2+4, ys = h-3, xe = w/2+8, ye = h-1, color = colors.yellow, text = "right"}
  13. gomb[7] = {xs = w/2-8, ys = h-7, xe = w/2-4, ye = h-7, color = colors.magenta, text = "pl.up"}
  14. gomb[8] = {xs = w/2-8, ys = h-6, xe = w/2-4, ye = h-6, color = colors.orange, text = "place"}
  15. gomb[9] = {xs = w/2-8, ys = h-5, xe = w/2-4, ye = h-5, color = colors.blue, text = "pl.dn"}
  16. gomb[10] = {xs = w/2+4, ys = h-7, xe = w/2+8, ye = h-7, color = colors.magenta, text = "rs.up"}
  17. gomb[11] = {xs = w/2+4, ys = h-6, xe = w/2+8, ye = h-6, color = colors.orange, text = "rs"}
  18. gomb[12] = {xs = w/2+4, ys = h-5, xe = w/2+8, ye = h-5, color = colors.blue, text = "rs.dn"}
  19.  
  20. function printbutton()
  21.  term.clear()
  22.  for i = 1, #gomb do
  23.   if gomb[i].color == term.getTextColor() then
  24.    term.setBackgroundColor(gomb[i].color)
  25.    term.setTextColor(colors.red)
  26.   else
  27.    term.setBackgroundColor(gomb[i].color)
  28.   end
  29.   for j =  gomb[i].ys, gomb[i].ye do
  30.    for k = gomb[i].xs, gomb[i].xe do
  31.     term.setCursorPos(k, j)
  32.     print(" ")
  33.    end
  34.   end
  35.   term.setCursorPos(gomb[i].xs, gomb[i].ys)
  36.   print(gomb[i].text)
  37.   term.setTextColor(colors.white)
  38.  end
  39.  term.setBackgroundColor(colors.black)
  40. end
  41.  
  42.  
  43. function mouseclick(x, y, xs, ys, xe, ye)
  44.  if x < xs or y < ys or x > xe or y > ye then
  45.   return false
  46.  end
  47.  return true
  48. end
  49.  
  50. function setter(i)
  51.  print(i, " -es gomb megnyomva!")
  52.  if i == 1 then --up
  53.  rednet.broadcast(gomb[i].text)
  54.  print(i, " gomb megnyomva!")
  55.  elseif i == 2 then --forward
  56.  rednet.broadcast(gomb[i].text)
  57.  elseif i == 3 then --back
  58.   rednet.broadcast(gomb[i].text)
  59.  elseif i == 4 then --down
  60.   rednet.broadcast(gomb[i].text)
  61.  elseif i == 5 then --left
  62.   rednet.broadcast(gomb[i].text)
  63.  elseif i == 6 then -- right
  64.   rednet.broadcast(gomb[i].text)
  65.  elseif i == 7 then -- placeup
  66.   rednet.broadcast(gomb[i].text)
  67.  elseif i == 8 then -- place
  68.   rednet.broadcast(gomb[i].text)
  69.  elseif i == 9 then -- placedown
  70.   rednet.broadcast(gomb[i].text)
  71.  elseif i == 10 then -- rs up
  72.   rednet.broadcast(gomb[i].text)
  73.  elseif i == 11 then -- rs
  74.   rednet.broadcast(gomb[i].text)
  75.  elseif i == 12 then -- rs down
  76.   rednet.broadcast(gomb[i].text)
  77.  end
  78.  sleep(.3)
  79. end
  80.  
  81. while run do
  82.  printbutton()
  83.  mytimer = os.startTimer(.1)
  84.  event, btn, x, y = os.pullEvent()
  85. --[[ if event == "timer" and btn == mytimer then
  86.   term.setCursorPos(1, 1)
  87.   print("timer lejart") sleep(1)]]
  88.  if event == "mouse_click" then
  89.   for i = 1, #gomb do
  90.    if mouseclick(x, y, gomb[i].xs, gomb[i].ys, gomb[i].xe, gomb[i].ye) then
  91.     setter(i)
  92.    end
  93.   end
  94.  end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement