-
Notifications
You must be signed in to change notification settings - Fork 1
/
ray.lua
32 lines (30 loc) · 848 Bytes
/
ray.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require("utilities")
function backtrace( source, angle, type )
while true do
source = transform( source, angle, -1 )
if type == "border" then
if map:inBounds( source.x, source.y ) then
return source
end
elseif type == "wall" then
if not map:isWalkable( source.x, source.y ) then
return source
end
end
end
end
function castSingleRay( source, angle )
while true do
source = transform( source, angle, 16 )
if not map:isWalkable( source.x, source.y ) then
while true do
source = transform( source, angle, 8 )
if not map:inBounds( source.x, source.y ) then
return backtrace( source, angle, "border" )
elseif map:isWalkable( source.x, source.y ) then
return backtrace( source, angle, "wall" )
end
end
end
end
end