OK, this version is better (by raycasting to every square in the matrix, rather than just the edges) but it is still missing some cases, as in the startup example (right hand edge, row above the player). I think it's a <X vs <=X bug... Cursor keys to move the red square around. The main image doesn't change, I haven't written that part yet. (And now I have https://scratch.mit.edu/projects/159332081/ I probably never will)
remixed from my own project https://scratch.mit.edu/projects/97005201/ todo: optimise by raycasting surrounding 8 squares and then pushing deeper only at the edges and gaps. Every time you hit a block you can eliminate many blocks directly behind it.