Judging by your code, you're a lot more experienced than I am, but I did just post up a topic in this same forum. In my code, I did kind of mimic collision in the bounds of the window. Check it out, might not help you out, but it might give you some ideas