public bool LineOfSight(Vector2 origin, Vector2 destination)
{
float maxRange = 800.0f;
float distance = Vector2.Distance(origin,destination);
int precision = 25; // How many steps to check, must be smaller than pixel width/height of a tile
//
if (distance > maxRange) // If target is out of range, do not check LOS
return false;
else
{
Vector2 stepDirection = destination - origin;
stepDirection.Normalize();
int iterations = (int)distance / precision;
for (int x = 1; x < iterations; x++)
{
if (TileMap.IsWallTileByPixel(origin + stepDirection * (x * 25)))
{
return false;
}
}
return true; // If no wall tiles were found LOS is clear
}
}