local function doFadeWipe(state)
  fadeWipe = celeste.FadeWipe(engine.Scene, state, nil)
  engine.Scene:Add(fadeWipe)
  fadeWipe.duration = 2
  fadeWipe.EndTimer = 3
end

local Vector2 = require("#microsoft.xna.framework.vector2")


function onBegin()

  if getFlag("entrada_deeperwell") then

    disablePause()
    setFlag("flagdecal_deeperwell", false)
    setFlag("entrada_deeperwell", false)
    disableMovement()
    wait(1)

    player.DummyAutoAnimate = false
    player.Sprite:Play("sleep", false, false)
    wait(2)

    player.Depth = 0
    player.ForceCameraUpdate = false

    local from = player.Position
    local p = 0
    while p < 1 do
      player.Position = Vector2.Lerp(from, player.Position + vector2(0, 1), monocle.Ease.QuadInOut(p))
      if p > 1.5 and p < 2.5 then
        playSound("event:/game/WanderBDay/omori_gettingintowater", player.Position)
      end

      if p < 2 then
        player.DummyAutoAnimate = false
        player.Sprite:Play("sleepeterno", false, false)
      end
      wait()
      p = p + engine.DeltaTime * 0.20
    end

    player.DummyAutoAnimate = true
    player.Sprite:Play("idle", false, false)

    doFadeWipe(false)
    wait(2)

    setFlag("saida_deeperwell")
    player.ForceCameraUpdate = true

  end

end