wofl: compute angle

This commit is contained in:
Fabien Freling 2024-10-08 14:02:03 +02:00
parent d509a2cc2f
commit 834b40e932

View file

@ -1,6 +1,9 @@
player = {
x = nil,
y = nil
origin = {
x= nil,
y = nil
},
dir = nil
}
col_bg = 1
@ -10,18 +13,29 @@ function _init()
for i=0,31 do
for j=0,31 do
if mget(i,j) == 5 then -- player id
player.x = i
player.y = j
player.origin.x = i + 0.5
player.origin.y = j + 0.5
player.dir = math.pi / 2
break
end
end
if (player.x) break
end
print("player: ("..player.x..", "..player.y..")")
print("player: ("..player.origin.x..", "..player.origin.y..")")
end
function cast_ray(origin, angle)
end
function _draw()
cls(col_bg)
rectfill(0, 135, 480, 270, col_ground)
local fov = 120 -- horizontal
local angle_step=(fov / 480) / 360 * math.pi
for x=0,480-1 do
local angle = (player.dir-(fov/2) + x * angle_step) % (2 * math.pi)
local bloc, dist = cast_ray(player.origin, angle)
end
-- map()
end