Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tr_port = 53646 -- Порт передатчика(это устройство)
- local rc_port = 22866 -- Порт приемника(дрон)
- -- НЕ ТРОГАТЬ!!!
- local isize = 1
- local s_slot = 1
- local mod_st = 8
- local acceleration = 2
- local isavail = false
- local step = 2
- local mod_st_memory = 8
- local comp = require('computer')
- local cmp = require('component')
- local gpu = cmp.gpu
- local event = require('event')
- local kb = require('keyboard')
- if not cmp.isAvailable('modem') then
- io.stderr:write('Компонент \'Плата беспроводной сети\' не обнаружен!')
- os.exit()
- end
- local m = cmp.modem
- if not m.open(tr_port) and not m.isOpen(tr_port) then
- io.stderr:write('Не удалось открыть порт '..tr_port)
- os.exit()
- end
- m.setStrength(mod_st)
- function send(...)
- m.broadcast(rc_port,...)
- end
- local wason = false
- function cls_ob(_,_,_,_,S,msg,eng,accel,invsize,slot_sel,st_in_slot,m_st)
- gpu.setForeground(0xFFFFFF)
- if msg == 'Info' then
- if eng > 66 then
- gpu.setForeground(0x19FF19)
- elseif eng < 67 and eng > 20 then
- gpu.setForeground(0xFFFF00)
- elseif eng < 21 then
- gpu.setForeground(0xFF0000)
- end
- gpu.set(28,4,eng..'% ')
- gpu.setForeground(0xFFFFFF)
- gpu.set(19,6,accel..' м/с ')
- gpu.set(20,8,invsize..' слотов ')
- isize = invsize
- gpu.set(18,9,slot_sel..' ')
- s_slot = slot_sel
- gpu.set(28,10,st_in_slot..' предметов ')
- gpu.set(23,7,math.floor(S + 0.5)..' м ')
- local was = gpu.getForeground()
- gpu.setForeground(0x19FF19)
- gpu.set(18,3,'Включён ')
- mod_st = m_st
- gpu.setForeground(was)
- wason = true
- end
- isavail = true
- end
- function key(ev,_,_,code,_)
- local knum = tonumber(code)
- if knum == 211 then --211 Delete
- comp.beep(1000,0.35)
- os.sleep(0.15)
- comp.shutdown(true)
- end
- local ky = kb.keys[code]
- if ky == 'w' then
- send('move',0,0,step)
- end
- if ky == 's' then
- send('move',0,0,-step)
- end
- if ky == 'a' then
- send('move',step,0,0)
- end
- if ky == 'd' then
- send('move',-step,0,0)
- end
- if ky == 'space' then
- send('move',0,step,0)
- end
- if ky == 'lshift' then
- send('move',0,-step,0)
- end
- if ky == 'home' then
- gpu.setResolution(1,1)
- resized = true
- end
- if ky == 'end' then
- draw_int()
- end
- end
- function mouse(_,_,x,y,tc_tp,_)
- if isavail then
- if x == 44 then
- if y == 6 then
- if acceleration*10 < 20 then
- acceleration = acceleration + 0.5
- end
- send('Accel',acceleration)
- elseif y == 11 then
- if mod_st < 1000 then
- mod_st = mod_st + 8
- end
- send('Streng',mod_st)
- elseif y == 9 then
- if isize > 0 then
- if s_slot < isize then
- s_slot = s_slot + 1
- end
- send('Slot',s_slot)
- end
- end
- elseif x == 46 then
- if y == 6 then
- if acceleration*10 > 5 then
- acceleration = acceleration - 0.5
- end
- send('Accel',acceleration)
- elseif y == 11 then
- if mod_st > 8 then
- mod_st = mod_st - 8
- end
- send('Streng',mod_st)
- elseif y == 9 then
- if isize > 0 then
- if s_slot > 1 then
- s_slot = s_slot - 1
- end
- send('Slot',s_slot)
- end
- end
- end
- end
- step = acceleration/1
- if (x > 1 and x < 19) and (y > 12 and y < 16) then
- send('Power Off!')
- wason = false
- event.ignore('modem_message')
- os.sleep(0.25)
- event.listen('modem_message',cls_ob)
- end
- if (x > 1 and x < 19) and (y > 16 and y < 20) then
- send('Power On!')
- end
- end
- function chkfor_avail()
- if isavail then
- gpu.setBackground(0x00E600)
- gpu.set(44,6,'+')
- gpu.set(44,11,'+')
- gpu.set(44,9,'+')
- gpu.setBackground(0xFF2400)
- gpu.set(46,6,'-')
- gpu.set(46,11,'-')
- gpu.set(46,9,'-')
- gpu.setBackground(0x333333)
- else
- gpu.setBackground(0x333333)
- gpu.set(44,6,'+')
- gpu.set(44,11,'+')
- gpu.set(44,9,'+')
- gpu.set(46,6,'-')
- gpu.set(46,11,'-')
- gpu.set(46,9,'-')
- end
- end
- event.listen('modem_message',cls_ob)
- event.listen('key_down',key)
- event.listen('touch',mouse)
- local cfa = event.timer(0.1,chkfor_avail,math.huge)
- function bg_fill(color,x,y,x1,y1,symbol)
- local fg_was = gpu.getForeground()
- local bg_was = gpu.getBackground()
- gpu.setForeground(color)
- gpu.setBackground(color)
- gpu.fill(x,y,x1,y1,symbol)
- gpu.setForeground(fg_was)
- gpu.setBackground(bg_was)
- end
- function draw_int()
- gpu.setResolution(80,25)
- bg_fill(0x333333,1,1,80,25,' ')
- bg_fill(0x4D4D4D,1,1,80,1,' ')
- gpu.setBackground(0x333333)
- gpu.set(2,3,'Приемник(дрон): Недоступно')
- gpu.set(2,4,'Уровень заряда приемника: Недоступно')
- gpu.set(2,5,'Уровень заряда передатчика: Вычисление...')
- gpu.set(2,6,'Ускорение дрона: Недоступно')
- gpu.set(2,7,'Расстояние до дрона: Недоступно')
- gpu.set(2,8,'Размер инвентаря: Недоступно')
- gpu.set(2,9,'Выбранный слот: Недоступно')
- gpu.set(2,10,'Кол-во предметов в слоте: Недоступно')
- gpu.set(2,11,'Дальность передачи: '..mod_st..' м')
- gpu.setBackground(0x00E600)
- gpu.set(44,6,'+')
- gpu.set(44,11,'+')
- gpu.set(44,9,'+')
- gpu.setBackground(0xFF2400)
- gpu.set(46,6,'-')
- gpu.set(46,11,'-')
- gpu.set(46,9,'-')
- gpu.setBackground(0x333333)
- bg_fill(0xFF0000,2,13,17,3,' ')
- bg_fill(0x00FF00,2,17,17,3,' ')
- gpu.setBackground(0xFF0000)
- gpu.set(3,14,'Выключить дрона')
- gpu.setBackground(0x00FF00)
- gpu.set(3,18,'Разбудить дрона')
- gpu.setBackground(0x333333)
- end
- draw_int()
- while true do
- a = {comp.pullSignal(2)}
- if a[1] ~= 'modem_message' and a[1] ~= 'touch' and a[1] ~= 'key_down' and a[1] ~= 'key_up' then
- cls_ob()
- gpu.setForeground(0xFF0000)
- gpu.set(28,4,'Недоступно ')
- gpu.set(19,6,'Недоступно ')
- gpu.set(20,8,'Недоступно ')
- gpu.set(18,9,'Недоступно ')
- gpu.set(28,10,'Недоступно ')
- gpu.set(23,7,'Недоступно ')
- if wason then
- gpu.set(18,3,'Сигнал потерян! ')
- else
- gpu.set(18,3,'Выключен ')
- end
- mod_st_memory = mod_st
- gpu.setForeground(0xFFFFFF)
- isavail = false
- was_lost = true
- end
- if isavail and was_lost then
- was_lost = false
- send('Streng',mod_st_memory)
- end
- os.sleep()
- local cp_eng = math.floor(comp.energy()/comp.maxEnergy()*100 + 0.5)
- if cp_eng > 66 then
- gpu.setForeground(0x19FF19)
- elseif cp_eng < 67 and cp_eng > 10 then
- gpu.setForeground(0xFFFF00)
- elseif cp_eng < 11 then
- gpu.setForeground(0xFF0000)
- end
- gpu.set(30,5,cp_eng..'% ')
- gpu.setForeground(0xFFFFFF)
- m.setStrength(mod_st)
- gpu.set(22,11,m.getStrength()..' м ')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement