function onBegin()
    if abs(puppet.Position.X - player.Position.X) < 100 then
        speedXTweenTo(getSpeed(), 0.2, monocle.Ease.QuadIn)
    else
        speedXTweenTo(0, 0.2, monocle.Ease.QuadIn)
    end
end

function getSpeed()
    return sign(-(puppet.Position.X - player.Position.X)) * 90
end

function sign(x)
    return (x<0 and -1) or 1
end  

function abs(x)
    return x * sign(x)
end