Skip to content

Instantly share code, notes, and snippets.

@Mulperi
Created April 13, 2023 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mulperi/bb42e80702044cf337273035e82a9365 to your computer and use it in GitHub Desktop.
Save Mulperi/bb42e80702044cf337273035e82a9365 to your computer and use it in GitHub Desktop.
simple raycasting
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