Advertisement
Guest User

code

a guest
Apr 30th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. eps = 1e-9
  2. --...
  3. function cast(cam, r)
  4.     possibles = {}
  5.     for i, v in pairs(possibles) do
  6.         possibles[i] = nil
  7.     end
  8.    
  9.     for i, v in pairs(map) do
  10.         vectorX, vectorY = math.cos(r * math.pi/180), math.sin(r * math.pi/180)
  11.        
  12.         wallDistanceX, wallDistanceY = v[3] - v[1], v[4] - v[2]
  13.         wallParallelX, wallParallelY = -wallDistanceY, wallDistanceX
  14.         rayX, rayY = v[1] - cam.x, v[2] - cam.y --Make -
  15.        
  16.         Distance = (
  17.             (rayX * wallParallelX) + (rayY * wallParallelY))/(
  18.             (vectorX * wallParallelX) + (vectorY * wallParallelY)
  19.         )
  20.         if (
  21.             --[[
  22.             (math.min(v[1],v[3]) <= math.floor((cam.x + (Distance * vectorX))) and math.max(v[1],v[3]) >= math.floor((cam.x + (Distance * vectorX)))) and
  23.             (math.min(v[2],v[4]) <= math.floor((cam.y + (Distance * vectorY))) and math.max(v[2],v[4]) >= math.floor((cam.y + (Distance * vectorY))))
  24.             --]]
  25.             (math.min(v[1],v[3]) <= (cam.x + (Distance * vectorX)) and math.max(v[1],v[3]) >= (cam.x + (Distance * vectorX))) and
  26.             (math.min(v[2],v[4]) <= (cam.y + (Distance * vectorY)) and math.max(v[2],v[4]) >= (cam.y + (Distance * vectorY)))
  27.             --[[
  28.             (math.min(v[1],v[3]) + eps <= (cam.x + (Distance * vectorX)) and math.max(v[1],v[3]) + eps >= (cam.x + (Distance * vectorX))) and
  29.             (math.min(v[2],v[4]) + eps <= (cam.y + (Distance * vectorY)) and math.max(v[2],v[4]) + eps >= (cam.y + (Distance * vectorY)))
  30.             --]]
  31.         ) then --and Distance >= 0 and Distance < 1000 then
  32.             print(Distance)
  33.             table.insert(possibles, Distance)
  34.         else
  35.             table.insert(possibles, 0)
  36.         end
  37.     end
  38.    
  39.     --print(math.abs(math.min(unpack(possibles))))
  40.     --return math.min(unpack(possibles))
  41.     return math.abs(math.min(unpack(possibles)))
  42.     --print(Distance)
  43.     --return math.abs(Distance)
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement