--ALL OF THE BADELINE RELATED CODE IS FROM THE LUA CUTSCENE RECEPIE BOOK AND I DID NOT MAKE ANY OF IT -BadTie
local badeline = nil

local function badeline_appears(left_side)
  local pos_x, scale
  if left_side then
    pos_x = player.Position.X - 18
    scale = 1
  else
    pos_x = player.Position.X + 10
    scale = -1
  end
  local pos_y = player.Position.Y - 2

  badeline = celeste.BadelineDummy(vector2(pos_x, pos_y))
  badeline.Sprite.Scale.X = scale
  getLevel():Add(badeline)

  getLevel().Displacement:AddBurst(badeline.Center, 0.5, 8, 32, 0.5)
  playSound("event:/char/badeline/maddy_split", badeline.Position)

  wait()
end

local function badeline_vanishes()
  badeline:Vanish()
  --Input.Rumble(getEnum("Celeste.RumbleStrength", "Medium"), getEnum("Celeste.RumbleLength", "Medium"))
  badeline = nil

  wait()
end

function onBegin(room)
  if getFlag("she_always_comes_back") then
    
    return
  end

  setFlag("she_always_comes_back", true)
  disableMovement()
  say("roomSeven")
  wait(0.25)
  badeline_appears()
  wait(1)
  say("roomSevenBaddy")
  badeline_vanishes()
  wait(0.5)
  say("maddy_scream")
end

function onEnd(room, wasSkipped)
  if badeline then
    badeline:RemoveSelf()
    badeline = nil
  end
  enableMovement()
end