I have a simple function to determine whether an entity can see another, in a top-down tile-based game (this is actually a tiny bit more complex in my game, to determine whether to see the first block, but I simplified it for this example):
public static boolean canSee(int x, int y, int x2, int y2, Area area) {
Array<Tile> blocks = new Array<>();
Utils.Bresenham.Plotter plotter = (x1, y1) -> {
Tile t = area.getTileAt(x1, y1);
if (t.blocksView()) {
blocks.add(t);
}
};
Utils.Bresenham.line(x, y, x2, y2, plotter);
return blocks.size == 0;
}
// Example below:
P = player, E = enemy, B = block
.....
.....
.....
P.B..
B...E
Now the problem I have is that in this position, the enemy can see the player, but the player cannot see the enemy (because the most top 'B' blocks the Bresenham).. and I'm not sure what's a good way to fix this.