Created
April 13, 2023 05:55
-
-
Save Mulperi/bb42e80702044cf337273035e82a9365 to your computer and use it in GitHub Desktop.
simple raycasting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RayCast = function(grid, cellX, cellY) | |
local points = {} | |
for angle = 0, 360, 1 do | |
local radius = TileSize | |
local targetX = cellX * TileSize | |
local targetY = cellY * TileSize | |
for i = 1, love.graphics.getWidth(), 1 do | |
if not PixelOutOfBounds(targetX, targetY) and | |
GetCellByPixelCoordinates(targetX, targetY, grid, TileSize) == 0 then | |
radius = radius + 1 | |
targetX = Player.x * TileSize + math.cos(DegreesToRadians(angle)) * radius | |
targetY = Player.y * TileSize + math.sin(DegreesToRadians(angle)) * radius | |
end | |
end | |
table.insert(points, { x = targetX, y = targetY }) | |
end | |
return points | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment