diff --git a/main.lua b/main.lua index 19fad86..c272015 100644 --- a/main.lua +++ b/main.lua @@ -1,3 +1,7 @@ +function int(x) + return math.ceil(x) +end + function love.load() p2 = math.pi / 2 p3 = 3 * math.pi / 2 @@ -8,10 +12,10 @@ function love.load() love.window.setMode(1024, 512) player = {} - player["x"] = 100 + player["x"] = 96 player["y"] = 110 player["size"] = 8 - player["angle"] = -math.pi / 2 + player["angle"] = math.pi / 2 player["dx"] = math.cos(player.angle) * 5 player["dy"] = math.sin(player.angle) * 5 player["offset"] = 20 @@ -52,12 +56,12 @@ function love.update() local yo = 0 if player.dy < 0 then yo = -player.offset else yo = player.offset end - local ipx = math.ceil(player.x / map.size) - local ipx_add_xo = math.ceil((player.x + xo) / map.size) - local ipx_sub_xo = math.ceil((player.x - xo) / map.size) - local ipy = math.ceil(player.y / map.size) - local ipy_add_yo = math.ceil((player.y + yo) / map.size) - local ipy_sub_yo = math.ceil((player.y - yo) / map.size) + local ipx = int(player.x / map.size) + local ipx_add_xo = int((player.x + xo) / map.size) + local ipx_sub_xo = int((player.x - xo) / map.size) + local ipy = int(player.y / map.size) + local ipy_add_yo = int((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 pos2 = (ipy_add_yo - 1)*map.x + ipx @@ -237,13 +241,6 @@ function drawRays3D() disT = disH 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 if ca < 0 then ca = ca + 2 * math.pi @@ -253,16 +250,22 @@ function drawRays3D() end disT = disT * math.cos(ca) - local lineH = map.size * 320 / disT + local lineH = int(map.size * 320 / disT) if lineH > 320 then lineH = 320 end - local lineO = 160 - lineH / 2 - love.graphics.setLineWidth(8) - love.graphics.line( - r * 8 + 530, lineO, - r * 8 + 530, lineH + lineO - ) + local lineO = int(160 - (lineH / 2)) + + love.graphics.setPointSize(8) + love.graphics.setColor(1, 1, 1) + 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) if ray.angle < 0 then