Advertisement
zlofenix

Radar

Jun 15th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. modem = peripheral.wrap("right")
  2. Nradar = "radar_0"
  3. Nmon = "monitor_0"
  4.  
  5. radius = 10000
  6. scale = 50
  7.  
  8. w, h = term.getSize()
  9.  
  10. term.clear()
  11.  
  12. function colorScreen(color)
  13.  for a = 2,w-1 do
  14.   for b = 1,h do
  15.     paintutils.drawPixel(a,b,color)
  16.   end
  17.  end
  18. end
  19.  
  20. function textOut(x, y, text, fg, bg)
  21.  term.setCursorPos(x, y)
  22.  term.setTextColor(fg)
  23.  term.setBackgroundColor(bg)
  24.  term.write(text)
  25.  local xt,yt = term.getCursorPos()
  26.  term.setCursorPos(1, yt + 1)
  27. end
  28.  
  29. function translateXZ(oldX, oldZ, i)
  30.  local x = radarX - oldX
  31.  local z = radarZ - oldZ
  32.  x = x / (radius / scale)
  33.  z = z / (radius / scale)
  34.  x = x + (w / 2)
  35.  z = z + (h / 2)
  36.  x = math.floor(x);
  37.  z = math.floor(z);
  38.  return x,z
  39. end
  40.  
  41. function drawContact(x, y, z, name, color)
  42.   local newX, newZ = translateXZ(x, z)
  43.  
  44.   paintutils.drawPixel(newX, newZ, color)
  45.   textOut(newX - 3, newZ + 1, "[" .. name .. "]", colors.white, colors.black)
  46. end
  47.  
  48. function scanAndDraw()
  49.   if (modem.callRemote(Nradar,"getEnergyLevel") < radius*radius) then
  50.     hh = math.floor(h / 2);
  51.     hw = math.floor(w / 2);
  52.    
  53.     paintutils.drawLine(hw - 5, hh - 1, hw + 5, hh - 1, colors.red);
  54.     paintutils.drawLine(hw - 5, hh, hw + 5, hh, colors.red);
  55.     textOut(hw - 4, hh,"LOW POWER", colors.white, colors.red);
  56.     paintutils.drawLine(hw - 5, hh + 1, hw + 5, hh + 1, colors.red);
  57.     sleep(1);
  58.    
  59.     return 0;
  60.   end;  
  61.   modem.callRemote(Nradar,"scanRadiusW",radius);
  62.   sleep(2);
  63.  
  64.   redraw();
  65.  
  66.   numResults = modem.callRemote(Nradar,"getResultsCountW");
  67.  
  68.   if (numResults ~= 0) then
  69.     for i = 0, numResults-1 do
  70.       freq, cx, cy, cz = modem.callRemote(Nradar,"getResultW",i);
  71.      
  72.       drawContact(cx, cy, cz, freq, colors.red)
  73.     end
  74.   end
  75.  
  76.   drawContact(radarX, radarY, radarZ, "RAD", colors.yellow);
  77. end
  78.  
  79. function redraw()
  80.    colorScreen(colors.green)
  81.    textOut(1, h, "Energy: " .. modem.callRemote(Nradar,"getEnergyLevel") .. " Eu | Scan radius: " .. radius, colors.white, colors.black)
  82. end
  83.  
  84. --mrun = true
  85. --while (mrun) do
  86.  radarX = modem.callRemote(Nradar,"getRadarX");
  87.  radarY = modem.callRemote(Nradar,"getRadarY");
  88.  radarZ = modem.callRemote(Nradar,"getRadarZ");
  89.  scanAndDraw();
  90. --end
  91.  
  92. term.clear();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement