local coroutineEntity = monocle.Entity()

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

function onBegin(room)
  walkTo(25440)
  wait(1)
  player.Sprite:Play("lookUp", false)
  wait(1)
  coroutineEntity:add(monocle.Coroutine(dashUp()))
  coroutineEntity:add(monocle.Coroutine(setFlag("funnyTestFlag", True)))
  playSound("event:/avvi_drizzle/sfx_breaking1", player.Position)
  walkTo(25440)
  wait(1)
  coroutineEntity:add(monocle.Coroutine(dashUp()))
  coroutineEntity:add(monocle.Coroutine(setFlag("funnyTestFlag1", True)))
  playSound("event:/avvi_drizzle/sfx_breaking2", player.Position)
  --dashUp()
  --setFlag("funnyTestFlag1", True)
  walkTo(25440)
  wait(1)
  coroutineEntity:add(monocle.Coroutine(dashUp()))
  coroutineEntity:add(monocle.Coroutine(setFlag("funnyTestFlag2", True)))
  playSound("event:/avvi_drizzle/sfx_breaking3", player.Position)
  --dashUp()
  --setFlag("funnyTestFlag2", True)
  walkTo(25440)
  wait(1)
  coroutineEntity:add(monocle.Coroutine(dashUp()))
  coroutineEntity:add(monocle.Coroutine(setFlag("funnyTestFlag3", True)))
  playSound("event:/avvi_drizzle/sfx_broken", player.Position)
  --dashUp()
  --setFlag("funnyTestFlag3", True)
  setFlag("avviEndingTeleport", True)
end

function dashUp()
  celeste.SaveData.Instance.Assists.DashAssist = false
  celeste.Input.Rumble(celeste.RumbleStrength.Strong, celeste.RumbleLength.Medium)
  monocle.MInput.Disabled = true
  player.OverrideDashDirection = vector2(0, -1)
  player.StateMachine.Locked = false
  player.StateMachine.State = player:StartDash()
  player.Dashes = 0
  wait(0.1)
  while (player.Speed.Y < 0) do -- Waits till maddy stops moving up
    player.Dashes = 0
    celeste.Input.MoveY.Value = -1
    celeste.Input.MoveX.Value = 0
    wait()
  end
  player.OverrideDashDirection = nil
  player.StateMachine.State = 11
  player.StateMachine.Locked = true
  monocle.MInput.Disabled = false
  waitUntilOnGround()
end

function onEnd(room, wasSkipped)
  enableMovement()
  player.DummyAutoAnimate = true
  player.ForceCameraUpdate = true
  getLevel():ResetZoom()
  setFlag("avviEndingTeleport", True)
  enableMovement()
    if wasSkipped then
    player.DummyAutoAnimate = true
    player.ForceCameraUpdate = true
    getLevel():ResetZoom()
    enableMovement()
    setFlag("avviEndingTeleport", True)
    end
end