For anyone interested, a simply illustration of the basic idea behind sensing with wall is here:
Sprite A can see sprite B if:
a) distance between A and B is less than or equal to range of sensing;
AND
b) there’s no wall between
For a), distance can be calculated by square root of (deltaX^2 + deltaY^2)
For b), consider the following,
in which,
- finding the critical points requires some geometric calculation (similar triangles, tan/arctan)
- tilemap ext is useful for checking if a certain tile is wall
An interactive demo is here, the line between the sprites is drawn and critical lat/long tiles are colored (lats are purple, longs are red).
Try moving sprites and changing range parameter (set to 128, full screen)
After that, on the shoulder of @richard, the shader ext is useful for showing enemy alert range for player.