fix up int casting and render wall lines
This commit is contained in:
parent
cc2bcc08c5
commit
19c2504bed
1 changed files with 25 additions and 22 deletions
45
main.lua
45
main.lua
|
@ -1,3 +1,7 @@
|
||||||
|
function int(x)
|
||||||
|
return math.ceil(x)
|
||||||
|
end
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
p2 = math.pi / 2
|
p2 = math.pi / 2
|
||||||
p3 = 3 * math.pi / 2
|
p3 = 3 * math.pi / 2
|
||||||
|
@ -8,10 +12,10 @@ function love.load()
|
||||||
love.window.setMode(1024, 512)
|
love.window.setMode(1024, 512)
|
||||||
|
|
||||||
player = {}
|
player = {}
|
||||||
player["x"] = 100
|
player["x"] = 96
|
||||||
player["y"] = 110
|
player["y"] = 110
|
||||||
player["size"] = 8
|
player["size"] = 8
|
||||||
player["angle"] = -math.pi / 2
|
player["angle"] = math.pi / 2
|
||||||
player["dx"] = math.cos(player.angle) * 5
|
player["dx"] = math.cos(player.angle) * 5
|
||||||
player["dy"] = math.sin(player.angle) * 5
|
player["dy"] = math.sin(player.angle) * 5
|
||||||
player["offset"] = 20
|
player["offset"] = 20
|
||||||
|
@ -52,12 +56,12 @@ function love.update()
|
||||||
local yo = 0
|
local yo = 0
|
||||||
if player.dy < 0 then yo = -player.offset else yo = player.offset end
|
if player.dy < 0 then yo = -player.offset else yo = player.offset end
|
||||||
|
|
||||||
local ipx = math.ceil(player.x / map.size)
|
local ipx = int(player.x / map.size)
|
||||||
local ipx_add_xo = math.ceil((player.x + xo) / map.size)
|
local ipx_add_xo = int((player.x + xo) / map.size)
|
||||||
local ipx_sub_xo = math.ceil((player.x - xo) / map.size)
|
local ipx_sub_xo = int((player.x - xo) / map.size)
|
||||||
local ipy = math.ceil(player.y / map.size)
|
local ipy = int(player.y / map.size)
|
||||||
local ipy_add_yo = math.ceil((player.y + yo) / map.size)
|
local ipy_add_yo = int((player.y + yo) / map.size)
|
||||||
local ipy_sub_yo = math.ceil((player.y - yo) / map.size)
|
local ipy_sub_yo = int((player.y - yo) / map.size)
|
||||||
|
|
||||||
local pos1 = (ipy - 1)*map.x + ipx_add_xo
|
local pos1 = (ipy - 1)*map.x + ipx_add_xo
|
||||||
local pos2 = (ipy_add_yo - 1)*map.x + ipx
|
local pos2 = (ipy_add_yo - 1)*map.x + ipx
|
||||||
|
@ -237,13 +241,6 @@ function drawRays3D()
|
||||||
disT = disH
|
disT = disH
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
love.graphics.setLineWidth(1)
|
|
||||||
love.graphics.line(
|
|
||||||
player.x, player.y,
|
|
||||||
ray.x, ray.y
|
|
||||||
)
|
|
||||||
|
|
||||||
local ca = player.angle - ray.angle
|
local ca = player.angle - ray.angle
|
||||||
if ca < 0 then
|
if ca < 0 then
|
||||||
ca = ca + 2 * math.pi
|
ca = ca + 2 * math.pi
|
||||||
|
@ -253,16 +250,22 @@ function drawRays3D()
|
||||||
end
|
end
|
||||||
disT = disT * math.cos(ca)
|
disT = disT * math.cos(ca)
|
||||||
|
|
||||||
local lineH = map.size * 320 / disT
|
local lineH = int(map.size * 320 / disT)
|
||||||
if lineH > 320 then
|
if lineH > 320 then
|
||||||
lineH = 320
|
lineH = 320
|
||||||
end
|
end
|
||||||
local lineO = 160 - lineH / 2
|
local lineO = int(160 - (lineH / 2))
|
||||||
love.graphics.setLineWidth(8)
|
|
||||||
love.graphics.line(
|
love.graphics.setPointSize(8)
|
||||||
r * 8 + 530, lineO,
|
love.graphics.setColor(1, 1, 1)
|
||||||
r * 8 + 530, lineH + lineO
|
local top = lineH - 1
|
||||||
|
for y = 0, top do
|
||||||
|
if y == 0 or y == top then
|
||||||
|
love.graphics.points(
|
||||||
|
r * 8 + 530, y + lineO
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
ray.angle = ray.angle + math.rad(1)
|
ray.angle = ray.angle + math.rad(1)
|
||||||
if ray.angle < 0 then
|
if ray.angle < 0 then
|
||||||
|
|
Loading…
Add table
Reference in a new issue