Hey,
I'm working on a doom style game (in graphics only, not gameplay) and want to add a floor to the map. I have my maps set up as individual sprites where the colour 0 indicates a floor, and any other number is used as the index I get the wall sprite from. I am planning on generating a map where each 0 is added as a floor tile (so I can generate paths using bitmasks and have nice neat looking floors and junctions etc)
I have been trying to use tline3d to draw the floors using the below which only sort of works, for a test I am just using a tiled grid of the same sprites that only has a checkered border but it is all distorted. Can anyone see what exactly is wrong? If you need more code for context let me know, I'm not sure whether it is just how I am using tline3d or whether it is some other maths I'm using...
function draw_floor()
local strafex = cos(player.a + 0.25)
local strafey = sin(player.a + 0.25)
local plane_scale = sin(fov / 2) / cos(fov / 2)
local planex = strafex * plane_scale
local planey = strafey * plane_scale
local start_y = flr(current_horizon)
if start_y < 0 then start_y = 0 end
local maptex = fetch("map/0.map")[1].bmp
for y = start_y, sh - 1 do
local p = y - current_horizon
if p <= 0 then p = 0.0001 end
local posZ = 0.5 * sh
local row_distance = posZ / p
local fx0 = player.x + row_distance * (player.dx - planex)
local fy0 = player.y + row_distance * (player.dy - planey)
local fx1 = player.x + row_distance * (player.dx + planex)
local fy1 = player.y + row_distance * (player.dy + planey)
tline3d(maptex,0,y,sw-1,y,fx0,fy0,fx1,fy1,1/row_distance,1/row_distance)
end
end |
So I figured it out, however I'm not 100% sure on the maths, I just monkeyed around until it worked!
I just needed to change 1/row_distance to just 1... I had it as 1 before but it wasn't working at the time I think because I was omitting the 'maptex' part. Though the documentation suggests omitting src should just automatically select the current map, is this not the case? I could never get it working without fetching the map as I am.
[Please log in to post a comment]




