Advertisement
MrSnake20_15

Tablet v2

Dec 15th, 2016
1,402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.62 KB | None | 0 0
  1. local comp = require('component')
  2. local modem = comp.modem
  3. local term = require("term")
  4. local event = require("event")
  5. local computer = require('computer')
  6. local gpu = comp.gpu
  7.  
  8. --Vars
  9. local port = 12345
  10. local full = true
  11. local x_max, y_max = gpu.maxResolution()
  12. local x_min, y_min = 1, 1
  13. local speed = 1
  14. local col = 0x0000FF
  15.  
  16. modem.open(port)
  17. gpu.setResolution(x_max,y_max)
  18. function link()
  19.     print("Введите 5-ти значный код, появившийся на мониторе дрона")
  20.     io.write(">>")
  21.     modem.broadcast(port,io.read())
  22.     modem.broadcast(port,"drone = component.proxy(component.list('drone')())")
  23. end
  24.  
  25. function help()
  26. term.clear()
  27. print([[
  28.                         Основное:
  29.                     Подключиться к дрону: 1
  30.                     Узнать расстояние до дрона: 2
  31.    ctr - вызов данной подсказки |H - Уменьшить/Увеличить экран
  32.              Поменять текст дрона: 3 | Ввести свою комманду: 4
  33.                         Выход:    Информация:
  34.                             Q         B
  35.                    Управление дроном:
  36.                    Изменить цвет дрона:   C
  37.                    Движение:              
  38.        ↑
  39.        W             Вниз:                Вверх:      
  40.     ← A S →         LShift                Space                                  
  41.        S                Скорость движения
  42.        ↓      Повысить скорость:    Понизить скорость:
  43.                       R                     F    
  44.                         Работа с инвентарями:
  45.        Забрать вещи из сундука:    Выбросить все вещи:
  46.                  K                            I                                                                                                
  47. ]])
  48.  
  49. end
  50.  
  51. buttons = {
  52. [17] = 'drone.move(1,0,0)', --forw
  53. [31] = "drone.move(-1,0,0)", --back
  54. [30] = "drone.move(0,0,-1)", --left
  55. [32] = "drone.move(0,0,1)", --right
  56. [42] = "drone.move(0,-1,0)",--down
  57. [57] = "drone.move(0,1,0)", --up
  58. [23] = "for i = 1, drone.inventorySize() do drone.select(i) drone.drop(0) end",
  59. [37] = "for i = 1,drone.inventorySize() do for i = 0, 5 do drone.suck(i) end end",
  60. }
  61.  
  62. help()
  63. print('Start')
  64. while true do
  65.     e = {event.pull()}
  66.     if e[1] == 'key_down' then
  67.         if e[4] == 16 then
  68.             print('Exit!')
  69.             break
  70.         elseif e[4] == 29 then
  71.             help()
  72.         elseif e[4] ==  2 then
  73.             link()
  74.         elseif e[4] == 19 then
  75.             speed = speed+0.5
  76.             modem.broadcast(port,"drone.setAcceleration(speed)")
  77.             print("Скорость изменена: " .. speed)
  78.         elseif e[4] == 33 then
  79.             speed = speed-0.5
  80.             modem.broadcast(port,"drone.setAcceleration(speed)")
  81.             print("Скорость изменена: " .. speed)
  82.         elseif e[4] == 46 then
  83.             col = math.random(0x0, 0xFFFFFF)
  84.             modem.broadcast(port,"drone.setLightColor(" .. col ..")")
  85.             print("Цвет дрона: " .. col .. " Скорость дрона: " .. speed)
  86.         elseif e[4] == 48 then
  87.             print("INFO: Цвет дрона: " .. col)
  88.         elseif e[4] == 4 then
  89.             print('Введите текст для дрона')
  90.             io.write(">>")
  91.             local cmd ="drone.setStatusText('" .. io.read() .."')"
  92.             modem.broadcast(port,cmd)
  93.         elseif e[4] == 5 then
  94.             print([[Уже отправлено:
  95.                 drone = component.proxy(component.list('drone')())
  96.                 modem = component.proxy(component.list("modem")()))
  97.                     Введите комманду!]])
  98.             io.write(">>")
  99.             modem.broadcast(port,io.read())
  100.         elseif e[4] == 3 then
  101.             modem.broadcast(port,'PING')
  102.             e = {event.pull('modem_message')}
  103.             dis = e[5]
  104.             print("Расстояние до дрона: ",dis)
  105.         elseif e[4] == 35 then
  106.                 if full then
  107.                     full = false
  108.                     gpu.setResolution(x_min,y_min)
  109.                 else
  110.                     full = true
  111.                     gpu.setResolution(x_max,y_max)
  112.                 end
  113.         else
  114.             if buttons[e[4]] then
  115.                 modem.broadcast(port,buttons[e[4]])
  116.                 print("Комманда '" .. buttons[e[4]] .. "' отправлена дрону.")
  117.             else
  118.                 computer.beep()
  119.             end
  120.         end
  121.     end
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement