I haven't read the book or anything, but the thing that jumps out to me is how you've wrapped event handling in this while(betweenFrames > perFrame) loop. My impression was that you're supposed to do that processing every loop, and simply multiply by the time between two frames. So my guess for fixing your problem is: delete that while loop around your event handling, and in your event handling multiply velocity by dt instead of by perframe.