Advertisement
RedbanditDEV

Valkyrian Computers Tracking System

Jun 3rd, 2023 (edited)
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local radar = peripheral.wrap("left")
  2. local localShip = peripheral.wrap("right")
  3. local monitor = peripheral.wrap("top")
  4. local pretty = require "cc.pretty"
  5.  
  6. function dump(o)
  7.     if type(o) == 'table' then
  8.         local s = '{ '
  9.         for k,v in pairs(o) do
  10.             if type(k) ~= 'number' then k = '"'..k..'"' end
  11.             s = s .. '['..k..'] = ' .. dump(v) .. ','
  12.         end
  13.         return s .. '} '
  14.     else
  15.         return tostring(o)
  16.     end
  17. end
  18.  
  19. -- Rotates (x, y) around origin by the angle delta (in radians, counterclockwise)
  20. local function rotate(x, y, delta)
  21.     -- Convert to polar coordinates
  22.     local length, angle = math.sqrt(x^2 + y^2), math.atan2(y, x)
  23.     -- Rotate by delta
  24.     angle = angle + delta
  25.     -- Convert back to cartesian coordinates
  26.     return length * math.cos(angle), length * math.sin(angle)
  27. end
  28.  
  29. term.redirect(monitor)
  30. term.setPaletteColor(colors.white, 1,1,1)
  31. term.setBackgroundColor(colors.white)
  32. term.clear()
  33. monitor.setTextScale(0.5)
  34.  
  35. while true do
  36.     local scan = radar.scan(256)[1]
  37.    
  38.     term.setBackgroundColor(colors.white)
  39.     term.clear()
  40.     local x,z = monitor.getSize()
  41.     local xMiddle = x/2
  42.     local zMiddle = z/2
  43.     paintutils.drawPixel(xMiddle,zMiddle,colors.blue)
  44.    
  45.     local currentPos = localShip.getWorldspacePosition()
  46.     local currentRot = localShip.getRotation()
  47.    
  48.     term.setCursorPos(3,3)
  49.     term.write(currentRot['roll'])
  50.    
  51.     for i, ship in ipairs(scan) do
  52.         local xOffset = currentPos['x'] - ship['position']['x']
  53.         local zOffset = currentPos['z'] - ship['position']['z']
  54.         xOffset, zOffset = rotate(xOffset, zOffset, currentRot['roll'])
  55.        
  56.         local drawX = xMiddle + (xOffset/6)*0.1
  57.         local drawZ = zMiddle + (zOffset/9)*0.1
  58.         paintutils.drawPixel(drawX, drawZ, colors.blue)
  59.         local textLen = string.len(ship['mass'])
  60.         local textStart = drawX - textLen/2
  61.         term.setCursorPos(textStart, drawZ-1)
  62.         term.write(ship['mass'])
  63.     end
  64.     os.sleep(0.05)
  65. end
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement