Factor out sprite movement

Since the sprite movement function depends on variable capture, I
created a function to set up the variables and then return the needed
function.