wofl: compute angle
This commit is contained in:
parent
d509a2cc2f
commit
834b40e932
|
@ -1,6 +1,9 @@
|
||||||
player = {
|
player = {
|
||||||
x = nil,
|
origin = {
|
||||||
y = nil
|
x= nil,
|
||||||
|
y = nil
|
||||||
|
},
|
||||||
|
dir = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
col_bg = 1
|
col_bg = 1
|
||||||
|
@ -10,18 +13,29 @@ function _init()
|
||||||
for i=0,31 do
|
for i=0,31 do
|
||||||
for j=0,31 do
|
for j=0,31 do
|
||||||
if mget(i,j) == 5 then -- player id
|
if mget(i,j) == 5 then -- player id
|
||||||
player.x = i
|
player.origin.x = i + 0.5
|
||||||
player.y = j
|
player.origin.y = j + 0.5
|
||||||
|
player.dir = math.pi / 2
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (player.x) break
|
if (player.x) break
|
||||||
end
|
end
|
||||||
print("player: ("..player.x..", "..player.y..")")
|
print("player: ("..player.origin.x..", "..player.origin.y..")")
|
||||||
|
end
|
||||||
|
|
||||||
|
function cast_ray(origin, angle)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function _draw()
|
function _draw()
|
||||||
cls(col_bg)
|
cls(col_bg)
|
||||||
rectfill(0, 135, 480, 270, col_ground)
|
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()
|
-- map()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue