I suppose the problem is the collision with walls. I can't explain you right now how it works but I posted a code to handle that case on smilebasicsource. On the search bar type "wall collision" and click on the first result.