Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local radar = peripheral.wrap("left")
- local localShip = peripheral.wrap("right")
- local monitor = peripheral.wrap("top")
- local pretty = require "cc.pretty"
- function dump(o)
- if type(o) == 'table' then
- local s = '{ '
- for k,v in pairs(o) do
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. '['..k..'] = ' .. dump(v) .. ','
- end
- return s .. '} '
- else
- return tostring(o)
- end
- end
- -- Rotates (x, y) around origin by the angle delta (in radians, counterclockwise)
- local function rotate(x, y, delta)
- -- Convert to polar coordinates
- local length, angle = math.sqrt(x^2 + y^2), math.atan2(y, x)
- -- Rotate by delta
- angle = angle + delta
- -- Convert back to cartesian coordinates
- return length * math.cos(angle), length * math.sin(angle)
- end
- term.redirect(monitor)
- term.setPaletteColor(colors.white, 1,1,1)
- term.setBackgroundColor(colors.white)
- term.clear()
- monitor.setTextScale(0.5)
- while true do
- local scan = radar.scan(256)[1]
- term.setBackgroundColor(colors.white)
- term.clear()
- local x,z = monitor.getSize()
- local xMiddle = x/2
- local zMiddle = z/2
- paintutils.drawPixel(xMiddle,zMiddle,colors.blue)
- local currentPos = localShip.getWorldspacePosition()
- local currentRot = localShip.getRotation()
- term.setCursorPos(3,3)
- term.write(currentRot['roll'])
- for i, ship in ipairs(scan) do
- local xOffset = currentPos['x'] - ship['position']['x']
- local zOffset = currentPos['z'] - ship['position']['z']
- xOffset, zOffset = rotate(xOffset, zOffset, currentRot['roll'])
- local drawX = xMiddle + (xOffset/6)*0.1
- local drawZ = zMiddle + (zOffset/9)*0.1
- paintutils.drawPixel(drawX, drawZ, colors.blue)
- local textLen = string.len(ship['mass'])
- local textStart = drawX - textLen/2
- term.setCursorPos(textStart, drawZ-1)
- term.write(ship['mass'])
- end
- os.sleep(0.05)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement