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 + 18
    scale = -1
  end
  local pos_y = player.Position.Y - 8

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

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

  wait(1)
end

function onBegin()
	disableMovement()
	waitUntilOnGround()
	walkTo(40)
	wait(1)
	walkTo(48)
	wait(1)
	walkTo(72)
	player.DummyAutoAnimate = false
	player.Sprite:Play("lookUp")
	wait(1)
	badeline_appears()
	say("nalter_sods_dialog_end_pre")
	wait(0.5)
	player.DummyAutoAnimate = true
	say("nalter_sods_dialog_end")
end

function onEnd(room, wasSkipped)
	completeArea(not wasSkipped, wasSkipped)
end