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


function onBegin()

  if getFlag("enddoor2") then

    basil = celeste.Mod.MaxHelpingHand.Entities.MoreCustomNPC.GetNPC("basil")
    if basil then
      basil:RemoveSelf()
    end

    elevator = celeste.Mod.MaxHelpingHand.Entities.MoreCustomNPC.GetNPC("elevator")
    elevator:PlayAnimation("killbasil_end")
    elevator.Position = vector2(4840, 6121)

    redhand1 = celeste.Mod.MaxHelpingHand.Entities.MoreCustomNPC.GetNPC("redhand1")
    redhand1.Position = vector2(4990, 6413)

  end

end


function onStay()

  redhand2 = celeste.Mod.MaxHelpingHand.Entities.MoreCustomNPC.GetNPC("redhand1")
  if redhand2.position.Y < (player.Position.Y + 50) and redhand2.position.Y > (player.Position.Y - 50) then
    redhand2.Position = Vector2.Lerp(redhand2.Position, player.Position + vector2(0, 0), monocle.Ease.Linear(0.05))
  end

  if player.Position.X < redhand2.Position.X then
    redhand2:SetHorizontalScale(1)
  end

  if player.Position.X > redhand2.Position.X then
    redhand2:SetHorizontalScale(-1)
  end

  if redhand2.position.X < (player.Position.X + 8) and redhand2.position.X > (player.Position.X - 8) and redhand2.position.Y < (player.Position.Y + 8) and redhand2.position.Y > (player.Position.Y - 11) then
    playSound("event:/game/WanderBDay/omori_redhands_teleport", player.Position)
    setFlag("door2toblackspace")
  end

end