the radar allows you to see creations and characters. it also allows you to find out what exactly is in front of you, a creation or a character
the larger the radar, the more accurate it is
unlike the original ScriptableComputer in SComputers, the radar sees creation welded to the ground
the radar also sees worm, woc and all robots from the game
you can't know the exact type of robot from the radar, but you can guess what kind of robot it is based on its mass
the radar has a field of vision that is set vertically and horizontally. however, it is always directed towards the radar and not upwards. you can turn this field of vision around as if turning the radar inside yourself
please note that the getTargets method has a limit of no more than one call per tick (it can be removed by enabling the "disable call limit" in the Permission Tool)
the maximum field of view is 180 degrees, which means that you cannot scan everything 360 degrees in 1 tick
the radar does not see through walls located on another object from the radar (separated by a bearing or other creation), but it sees perfectly through walls located on the same body as the radar
component name - radar
methods:
--------------------- settings
local maxdist = 60
local line = false
--------------------- code
local colors = require("colors")
local utils = require("utils")
local radar = getComponents("radar")[1]
local display = getComponents("display")[1]
display.reset()
display.clear()
radar.setHFov(math.rad(16))
radar.setVFov(math.rad(180))
local rx, ry = display.getWidth(), display.getHeight()
local crx, cry = rx / 2, ry / 2
local tick = 0
local points = {}
local idColors = {}
function callback_loop()
if _endtick then
display.clear()
display.forceFlush()
return
end
local angle = math.rad(tick % 360)
radar.setAngle(angle)
display.clear()
if line then
display.drawLine(crx, cry, (math.sin(angle) * crx) + crx, -(math.cos(angle) * cry) + cry)
end
for i = #points, 1, -1 do
local point = points[i]
if point[3] == angle then
table.remove(points, i)
end
end
for index, value in ipairs(radar.getTargets()) do
local id, hangle, vangle, dist, force, ctype = unpack(value)
local s = (dist / maxdist) * crx
local x = math.floor(math.sin(hangle) * s + crx)
local y = math.floor(-math.cos(hangle) * s + crx)
if not idColors[id] then
if ctype == "character" then
idColors[id] = colors.sm.Gray[1]
else
idColors[id] = sm.color.new(math.random(), math.random(), math.random())
end
end
for i = #points, 1, -1 do
local point = points[i]
if point[4] == id then
table.remove(points, i)
end
end
table.insert(points, {x, y, angle, id})
end
for i = #points, 1, -1 do
local point = points[i]
display.drawPixel(point[1], point[2], idColors[ point[4] ])
end
for ix = -1, 1 do
for iy = -1, 1 do
if ix == 0 or iy == 0 then
display.drawPixel(crx + ix, cry + iy, (ix == 0 and iy == -1) and "00ff00" or "ff0000")
end
end
end
display.flush()
tick = tick + 16
end