Using a detector sprite is usually the way to go for keeping grid motion from going into walls. You could also just check the position on the tilemap to see if it's empty (-1).
You can find some ideas ideas on how to only moving a certain number of squares by searching for "turn based" or "dijkstra".
I have an oldish example that does that here:
but the more recent topic here about flood fill pathfinding would be more useful to you:
Finally your capx is running slow because it's creating all the wall objects every tick.