Advertisement
BananaSplit40404

3d_game

Jul 10th, 2024 (edited)
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. local monitor = peripheral.wrap("right")
  2. monitor.setCursorPos(1,1)
  3. monitor.setTextScale(0.5)
  4. monitor.setBackgroundColor(colors.black)
  5. monitor.clear()
  6.  
  7. monitor_width, monitor_height = monitor.getSize()
  8. monitor_width = monitor_width - 1
  9. monitor_height = monitor_height - 1
  10.  
  11. print(monitor_width, monitor_height)
  12. print(peripheral.getMethods(peripheral.getName(monitor)))
  13.  
  14. rednet.open("left")
  15. rednet.host("motherboard", tostring(os.getComputerID()))
  16.  
  17. gpus = {rednet.lookup("GPU_process")}
  18.  
  19. function sendDataToGPUS(data, gpus)
  20.     for _, computer in pairs(gpus) do
  21.         rednet.send(computer, data)
  22.     end
  23. end
  24.  
  25. -- an array of all the pixels in the monitor
  26. local monitor_pixels = {}
  27. for x = 1, monitor_width do
  28.   monitor_pixels[x] = {}
  29.   for y = 1, monitor_height do
  30.     monitor_pixels[x][y] = 0
  31.   end
  32. end
  33.  
  34.  
  35. -- environment to move around
  36. function createEnvironment(width, height)
  37.     local env = {}
  38.     for x = 1, width do
  39.       env[x] = {}
  40.       for y = 1, height do
  41.         env[x][y] = 0
  42.       end
  43.     end
  44.     return env
  45. end
  46.  
  47. function buildEnvWalls(env, width, height)
  48.     for x = 1, width do
  49.         env[x][1] = 1
  50.         env[x][height] = 1
  51.     end
  52.     for y = 1, height do
  53.         env[1][y] = 1
  54.         env[width][y] = 1
  55.     end
  56. end
  57.  
  58.  
  59.  
  60. playground = createEnvironment(10, 10)
  61. buildEnvWalls(playground, 10, 10)
  62.  
  63. player_location = {2,7}
  64.  
  65. rot = math.pi/4
  66.  
  67. computer_peripheral = term.current()
  68.  
  69.  
  70. function distibutedRayCast(env, player_location, gpus)
  71.     local x = player_location[1]
  72.     local y = player_location[2]
  73.     computer_data_pairs = {}
  74.     count = 0
  75.     screen = {}
  76.     working_gpus = #gpus
  77.     for i, computer_id in pairs(gpus) do
  78.         rot_i = rot + math.rad((i) - monitor_width/2)
  79.         sin, cos = 0.1*math.sin(rot_i), 0.1*math.cos(rot_i)
  80.         rednet.send(computer_id, {x, y, rot_i, sin, cos, env})
  81.         computer_data_pairs[computer_id] = i
  82.     end
  83.     while true do
  84.         local id, message = rednet.receive(nil, 10)
  85.         if message == nil then
  86.             break
  87.         end
  88.         x_loc = computer_data_pairs[id]
  89.         n = message
  90.         h = (10/(n*math.cos(math.rad(x_loc - monitor_width/2)))) * 80
  91.         term.redirect(monitor)
  92.         paintutils.drawLine(monitor_width-x_loc, (monitor_height/2)-(h/2), monitor_width-x_loc, (monitor_height/2)+(h/2), colors.white)
  93.         term.redirect(computer_peripheral)
  94.         count = count + 1
  95.  
  96.  
  97.         if x_loc+#gpus < monitor_width then
  98.             x_loc = x_loc + #gpus
  99.  
  100.             rot_i = rot + math.rad((x_loc) - monitor_width/2)
  101.             sin, cos = 0.1*math.sin(rot_i), 0.1*math.cos(rot_i)
  102.             rednet.send(id, {x, y, rot_i, sin, cos, env})
  103.             computer_data_pairs[id] = x_loc
  104.         else
  105.             working_gpus = working_gpus - 1
  106.             if working_gpus == 0 then
  107.                 break
  108.             end
  109.         end
  110.  
  111.  
  112.     end
  113. end
  114.  
  115. distibutedRayCast(playground, player_location, gpus)
  116.  
  117. -- rayCast(playground, player_location)
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement