Advertisement
briannovius

VR base

Nov 4th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. neuralInt = peripheral.wrap("back")
  2. modem = peripheral.find("modem")
  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.  
  15. --Core functions
  16. block = 32
  17. scale = 2
  18. initx = math.floor(gpsz*block/scale)
  19. inity = math.floor(gpsx*block/scale)
  20. world = {
  21. {1,1,1,1,1,1,1,1,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,0,0,0,0,0,0,1},
  26. {1,0,0,0,0,0,0,0,1},
  27. {1,0,2,0,3,0,4,0,1},
  28. {1,0,0,0,0,0,0,0,1},
  29. {1,1,1,1,1,1,1,1,1}
  30. }
  31. cam = {160,160,180}
  32. fov = 70
  33. lines = {}
  34. lineThickness = math.floor(window[1]/(fov))+1
  35. renderdist = 1000
  36. gen = true
  37. colors = {
  38. {255,255,255},
  39. {255,0,0},
  40. {0,255,0},
  41. {0,0,255},
  42. {255,255,0},
  43. }
  44. for i = 1, 360 do
  45.     x = math.cos(math.rad(i))*-1
  46.     y = math.sin(math.rad(i))
  47.     table.insert(roc,{x,y})
  48. end
  49. function setUpLines()
  50.     for l = 0,fov do
  51.         table.insert(lines,c.addRectangle(l*lineThickness,0,lineThickness,50,255))
  52.     end
  53. end
  54. function trig(degrees)
  55.     degr = math.floor(degrees)
  56.     while degr > 360 do
  57.         degr = degr - 360
  58.     end
  59.     while degr < 1 do
  60.         degr = degr + 360
  61.     end
  62.     return roc[degr]
  63. end
  64. function Engine()
  65.     detail = 1
  66.     line = math.floor(renderdist/detail/2)
  67.     thickness = math.floor(window[1]/fov)+1
  68.     dist = {}
  69.     color = {}
  70.     for i = 1, fov do
  71.         table.insert(dist,500)
  72.         table.insert(color,{0,0,0})
  73.     end
  74.     for f = 1, fov do
  75.         ff = f
  76.         cx = cam[1]
  77.         cy = cam[2]
  78.         cdeg = cam[3]
  79.         f = f - math.floor(fov/2) - cdeg
  80.         while ff > 359 do
  81.             ff = ff - 360
  82.         end
  83.         while ff < 0 do
  84.             ff = ff + 360
  85.         end
  86.         x = trig(f)[1]
  87.         y = trig(f)[2]
  88.         x = x * detail
  89.         y = y * detail
  90.         for l = 1 ,line do
  91.             l = l *detail
  92.             cx= cx + x
  93.             cy= cy + y
  94.             px = math.floor(cx/block)
  95.             py = math.floor(cy/block)
  96.             if py > #world or py < 1 or px > #world[1] or px < 1 then
  97.                 x = x
  98.             else
  99.                 if world[py][px] ~= 0 then
  100.                     dist[ff] = math.floor(l)
  101.                     color[ff] = colors[world[py][px]]
  102.                     break
  103.                 end
  104.             end
  105.         end
  106.     end
  107.     move = 0
  108.     for a = 1 ,fov do
  109.         i = dist[a]
  110.         i = window[1]/(i+1)*16
  111.         r = color[a][1]
  112.         g = color[a][2]
  113.         b = color[a][3]
  114.         if true then
  115.             lineWidth,lineHeight = lines[a].getSize()
  116.             lines[a].setSize(lineWidth,i)
  117.             lineHeight = i
  118.             linex,liney = lines[a].getPosition()
  119.             liney = math.floor(window[2]/2-(owner.pitch/90)*window[2])-math.floor(lineHeight/2)
  120.             lines[a].setColor(r,g,b)
  121.             lines[a].setPosition(linex,liney)
  122.         end
  123.         move = move + thickness
  124.     end
  125. end
  126. f = c.addRectangle(0,0,window[1],window[2])
  127. f.setColor(0,255,255)
  128. setUpLines()
  129. print("press E to exit")
  130. function one()
  131. while true do
  132.     event = os.startTimer(.01)
  133.     out, key = os.pullEvent()
  134.     if out == "key" and key == 18 then
  135.         c.clear()
  136.     break
  137.     end
  138.     Engine()
  139.     owner = neuralInt.getMetaOwner()
  140.     cam[1] = math.floor(gpsz*block/scale)-initx+80
  141.     cam[2] = math.floor(gpsx*block/scale)-inity+80
  142.     cam[3] = 360-owner.yaw+180
  143. end
  144. end
  145.  
  146. function two()
  147.     while true do
  148.     local sEvent, param, param2, param3 = os.pullEvent()
  149.     if sEvent == "key" then
  150.         print'key'
  151.         print(param)
  152.         if param == 17 then
  153.             print('w')
  154.             local yaw = owner.yaw
  155.              xfromyaw = math.sin(math.rad(yaw))
  156.              yfromyaw = math.cos(math.rad(yaw))
  157.              print(xfromyaw)
  158.              print(yfromyaw)
  159.              gpsx = gpsx + xfromyaw
  160.              gpsz = gpsz + yfromyaw
  161.         elseif param == 32 then
  162.              local yaw = owner.yaw + 90
  163.              xfromyaw = math.sin(math.rad(yaw))
  164.              yfromyaw = math.cos(math.rad(yaw))
  165.              print(xfromyaw)
  166.              print(yfromyaw)
  167.              gpsx = gpsx + xfromyaw
  168.              gpsz = gpsz + yfromyaw
  169.         elseif param == 31 then
  170.              local yaw = owner.yaw
  171.              xfromyaw = math.sin(math.rad(yaw))
  172.              yfromyaw = math.cos(math.rad(yaw))
  173.              print(xfromyaw)
  174.              print(yfromyaw)
  175.              gpsx = gpsx - xfromyaw
  176.              gpsz = gpsz - yfromyaw
  177.         elseif param == 30 then
  178.              local yaw = owner.yaw - 90
  179.              xfromyaw = math.sin(math.rad(yaw))
  180.              yfromyaw = math.cos(math.rad(yaw))
  181.              print(xfromyaw)
  182.              print(yfromyaw)
  183.              gpsx = gpsx + xfromyaw
  184.              gpsz = gpsz + yfromyaw
  185.     end
  186. end
  187. end
  188. end
  189. parallel.waitForAny(one, two)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement