Hello. I’m currently developing a game, in which every character are bound to cells. Each cell can have walls at their top/bottom/right/left and are linked to their neighbor cells (top/bottom/right/left again). I’d like to put in a list every cell currently visible to the player (it means they are not hidden by a wall). Until now, I’ve only used mathematics, and algorithms such as A* to navigate in the grid with my character, and I’d like to find a solution that doesn’t use Raycasting. Do you guys know an algorithm that can help me achieve that? The only thing you can do with cells are :
-Check where are the walls
-Get the neighboring cells you can navigate to.
Here is my current code, as you can see in the image, the visible cells, in blue, might be in corners that shouldn’t be visible from the character point of view.
//The classic pattern : everything in the field of view of the player
protected List<GridCell> classicPattern(GridCell start, int range){
int currentRange = range-1;
int authorizedRange = 2;
/* Initializing with adjacent cells */
if (start.hasDown())
reachable.Add(start.getDown());
if (start.hasUp())
reachable.Add(start.getUp());
if (start.hasLeft())
reachable.Add(start.getLeft());
if (start.hasRight())
reachable.Add(start.getRight());
while (currentRange != 0){
List<GridCell> tmp = new List<GridCell>();
currentRange--;
foreach(GridCell cell in reachable){
if (cell.hasDown() && Math.CellDistance(start, cell.getDown()) == authorizedRange && !tmp.Contains(cell.getDown()) && !reachable.Contains(cell.getDown()))
tmp.Add(cell.getDown());
if (cell.hasUp() && Math.CellDistance(start, cell.getUp()) == authorizedRange && !tmp.Contains(cell.getUp()) && !reachable.Contains(cell.getUp()))
tmp.Add(cell.getUp());
if (cell.hasLeft() && Math.CellDistance(start, cell.getLeft()) == authorizedRange && !tmp.Contains(cell.getLeft()) && !reachable.Contains(cell.getLeft()))
tmp.Add(cell.getLeft());
if (cell.hasRight() && Math.CellDistance(start, cell.getRight()) == authorizedRange && !tmp.Contains(cell.getRight()) && !reachable.Contains(cell.getRight()))
tmp.Add(cell.getRight());
}
authorizedRange ++;
foreach(GridCell cell in tmp){
reachable.Add(cell);
}
}
return reachable;
}
Thank you for your help guys and have fun coding games!

