briannovius

VR base

Nov 3rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. neuralInt = peripheral.wrap("back")
  2. modem = peripheral.wrap("top")
  3. modem.open(1)
  4. c = neuralInt.canvas()
  5. c.clear()
  6. window = {}
  7. window[1],window[2] = c.getSize()
  8. roc = {}
  9. owner = neuralInt.getMetaOwner()
  10. gpsx,gpsy,gpsz = gps.locate()
  11. if gpsx == nil or gpsy == nil or gpsz == nil then
  12.     error("GPS not located")
  13. end
  14. block = 32
  15. scale = 2
  16. initx = math.floor(gpsz*block/scale)
  17. inity = math.floor(gpsx*block/scale)
  18. world = {
  19. {1,1,1,1,1,1,1,1,1},
  20. {1,0,0,0,0,0,0,0,1},
  21. {1,0,0,0,0,0,0,0,1},
  22. {1,0,0,0,0,0,0,0,1},
  23. {1,0,0,0,0,0,0,0,1},
  24. {1,0,0,0,0,0,0,0,1},
  25. {1,0,2,0,3,0,4,0,1},
  26. {1,0,0,0,0,0,0,0,1},
  27. {1,1,1,1,1,1,1,1,1}
  28. }
  29. cam = {160,160,180}
  30. fov = 70
  31. lines = {}
  32. lineThickness = math.floor(window[1]/(fov))+1
  33. renderdist = 1000
  34. gen = true
  35. colors = {
  36. {255,255,255},
  37. {255,0,0},
  38. {0,255,0},
  39. {0,0,255},
  40. {255,255,0},
  41. }
  42. for i = 1, 360 do
  43.     x = math.cos(math.rad(i))*-1
  44.     y = math.sin(math.rad(i))
  45.     table.insert(roc,{x,y})
  46. end
  47. function setUpLines()
  48.     for l = 0,fov do
  49.         table.insert(lines,c.addRectangle(l*lineThickness,0,lineThickness,50,255))
  50.     end
  51. end
  52. function trig(degrees)
  53.     degr = math.floor(degrees)
  54.     while degr > 360 do
  55.         degr = degr - 360
  56.     end
  57.     while degr < 1 do
  58.         degr = degr + 360
  59.     end
  60.     return roc[degr]
  61. end
  62. function Engine()
  63.     detail = 2
  64.     line = math.floor(renderdist/detail/2)
  65.     thickness = math.floor(window[1]/fov)+1
  66.     dist = {}
  67.     color = {}
  68.     for i = 1, fov do
  69.         table.insert(dist,500)
  70.         table.insert(color,{0,0,0})
  71.     end
  72.     for f = 1, fov do
  73.         ff = f
  74.         cx = cam[1]
  75.         cy = cam[2]
  76.         cdeg = cam[3]
  77.         f = f - math.floor(fov/2) - cdeg
  78.         while ff > 359 do
  79.             ff = ff - 360
  80.         end
  81.         while ff < 0 do
  82.             ff = ff + 360
  83.         end
  84.         x = trig(f)[1]
  85.         y = trig(f)[2]
  86.         x = x * detail
  87.         y = y * detail
  88.         for l = 1 ,line do
  89.             l = l *detail
  90.             cx= cx + x
  91.             cy= cy + y
  92.             px = math.floor(cx/block)
  93.             py = math.floor(cy/block)
  94.             if py > #world or py < 1 or px > #world[1] or px < 1 then
  95.                 x = x
  96.             else
  97.                 if world[py][px] ~= 0 then
  98.                     dist[ff] = math.floor(l)
  99.                     color[ff] = colors[world[py][px]]
  100.                     break
  101.                 end
  102.             end
  103.         end
  104.     end
  105.     move = 0
  106.     for a = 1 ,fov do
  107.         i = dist[a]
  108.         i = window[1]/(i+1)*16
  109.         r = color[a][1]
  110.         g = color[a][2]
  111.         b = color[a][3]
  112.         if true then
  113.             lineWidth,lineHeight = lines[a].getSize()
  114.             lines[a].setSize(lineWidth,i)
  115.             lineHeight = i
  116.             linex,liney = lines[a].getPosition()
  117.             liney = math.floor(window[2]/2-(owner.pitch/90)*window[2])-math.floor(lineHeight/2)
  118.             lines[a].setColor(r,g,b)
  119.             lines[a].setPosition(linex,liney)
  120.         end
  121.         move = move + thickness
  122.     end
  123. end
  124. f = c.addRectangle(0,0,window[1],window[2])
  125. f.setColor(0,255,255)
  126. setUpLines()
  127. print("press E to exit")
  128. while true do
  129.     event = os.startTimer(.01)
  130.     out, key = os.pullEvent()
  131.     if out == "key" and key == 18 then
  132.         c.clear()
  133.     break
  134.     end
  135.     Engine()
  136.     owner = neuralInt.getMetaOwner()
  137.     gpsx,gpsy,gpsz = gps.locate()
  138.     if gpsx == nil or gpsy == nil or gpsz == nil then
  139.         c.clear()
  140.         error("GPS not located")
  141.     end
  142.     cam[1] = math.floor(gpsz*block/scale)-initx+80
  143.     cam[2] = math.floor(gpsx*block/scale)-inity+80
  144.     cam[3] = 360-owner.yaw+180
  145. end
Add Comment
Please, Sign In to add comment