It's really simple, actually. I made a project demonstrating how to do it (http://scratch.mit.edu/projects/coolfixit/1347450) but I'll explain it here, too: you can't really tell how it works.
Basically, put four sprites around the main sprite. If, say, the right sprite is touching a wall, change a variable so that the main sprite knows it shouldn't move in that direction. The same goes for the other four directions. Go check out that project I created now to see exactly how things work
Offline