Hi all!
There is my try to make the field-of view in Lua.
Issue: the diagonal walls are transparent.
Use WASD to move the green point.
If uses the diagonal marching, the worth points are on the crossings of line, between source and target midpoints and diagonals of every tile.
Exactly one point per tile and all tiles have a point (except 45 degree lines).
Field of view (or fog of war)
Field of view (or fog of war)
- Attachments
-
- field-of-view-01.love
- (1.36 KiB) Downloaded 283 times
Re: Field of view (or fog of war)
Second version:
fixed bugs, the diagonal wall is not more transparent;
the field of view is round;
the seen tiles have another color.
fixed bugs, the diagonal wall is not more transparent;
the field of view is round;
the seen tiles have another color.
- Attachments
-
- field-of-view-02.love
- (1.47 KiB) Downloaded 282 times
Last edited by darkfrei on Thu Jul 08, 2021 2:30 am, edited 1 time in total.
Re: Field of view (or fog of war)
Very nice work!
Re: Field of view (or fog of war)
Diagonal Marching
Code: Select all
-- License CC0 (Creative Commons license) (c) darkfrei, 2023
function getDiagonalMarch(angle)
local dx, dy = math.cos(angle), math.sin(angle)
local k = 1 / (math.abs(dx) + math.abs(dy))
return dx * k, dy * k, k
end
- Attachments
-
- diagonal-marching-01.love
- (1.75 KiB) Downloaded 104 times
Last edited by darkfrei on Fri Mar 31, 2023 12:50 pm, edited 4 times in total.
Re: Field of view (or fog of war)
link to video is probably broken
Re: Field of view (or fog of war)
Thanks, probably fixed.
Also, the math for factor k:
dx + dy is always 1;
atan2 (dy, dx) is always as given angle.
But normally the cos (angle) + sin (angle) cannot always give the 1, but the squared cos and sin functions.
So we are need to make the factor k, that will be used to make dx+dy=1 to be true.
It give us the dx and dy distances between diagonals. With this steps dx and dy you can march by all diagonals and step every tile just once, but every tile (it works 100% if you are in the diagonals crossings or on the diagonal that is more perpendicular to your movement).
https://www.desmos.com/calculator/0h3tavpxmw https://www.desmos.com/calculator/lu0axfvswn
Code: Select all
function getDiagonalMarch(angle)
local nx, ny = math.cos(angle), math.sin(angle)
local k = 1 / (math.abs(nx) + math.abs(ny))
return nx * k, ny * k, k
end
Who is online
Users browsing this forum: No registered users and 1 guest