42 lines
730 B
Lua
42 lines
730 B
Lua
player = {
|
|
origin = {
|
|
x= nil,
|
|
y = nil
|
|
},
|
|
dir = nil
|
|
}
|
|
|
|
col_bg = 1
|
|
col_ground = 6
|
|
|
|
function _init()
|
|
for i=0,31 do
|
|
for j=0,31 do
|
|
if mget(i,j) == 5 then -- player id
|
|
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.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
|