local Engine = require("#monocle.engine")
local Calc = require("#monocle.calc")
local Ease = require("#monocle.ease")
local minput = require("#Monocle.MInput")
local wasDashAssistOn = false
-- TY MICROLITH
function onBegin()
  
  disableRetry()
  disableMovement()
  -- movement/retry
  npc = getEntity("MoreCustomNPC", "Celeste.Mod.MaxHelpingHand.Entities.")
  local npc_from = npc.Position
  local npc_to = vector2(npc.Position.X - 0, npc.Position.Y + 120)
  
  local plats = getEntities("JumpThru")
  
  local plat
  for i, e in ipairs(plats) do
    if not plat or plat.Y > e.Y then
      plat = e
    end
  end
  -- this get entity also gets the jungle helper invis jumpthrotgh
  -- local plat_from = plat.Position.Y
  -- local plat_to = plat.Position.Y + 120
  player.ForceCameraUpdate = true
  --event:/CommunalHelperEvents/game/strawberryJam/game/solar_elevator/elevate
  
  --playSound("event:/CommunalHelperEvents/game/strawberryJam/game/solar_elevator/elevate")
  
  local particlesA = getFirstEntity("ParticleEmitter", "Celeste.Mod.FemtoHelper.")
  
  local particlesA = getEntities("ParticleEmitter", "Celeste.Mod.FemtoHelper.")
  --get the badeline shp particles entity
  local particle
  for i, e in ipairs(particlesA) do
    if not particle or particle.Y > e.Y then
      particle = e
    end
  end
  
  local particleA_from = particle.Position
  --do this one once
  local particleA_to = vector2(particle.Position.X, particle.Position.Y + 120)
  
  
  
  
  
  
  num_seconds = 3
  --reveal ladder (real)
  for t = 0, num_seconds, Engine.DeltaTime do
    npc.Position = npc_from + (npc_to - npc_from) * Ease.Linear(t/num_seconds)
	--plat.Position = plat_from + (plat_to - plat_from) * Ease.Linear(t/num_seconds)
	
	particle.Position = particleA_from + (particleA_to - particleA_from) * Ease.Linear(t/num_seconds)
	plat:MoveV(0.665)
    wait()
  end
  playSound("event:/CommunalHelperEvents/game/strawberryJam/game/solar_elevator/halt")
  npc.Position = vector2(npc.Position.X - 0, npc.Position.Y + 220)
  
  
  player.DummyGravity = true
  playSound("event:/game/05_mirror_temple/eyewall_bounce")
  engine.TimeRate = 0.35
  player.DummyAutoAnimate = false
  player.Sprite:Play("roll")
  player.Speed = vector2(900, -325)
  player.ForceCameraUpdate = true;
  wait(0.05)
  player.Speed = vector2(825, -125)
  wait(0.05)
  player.Speed = vector2(675, -50)
  wait(0.05)
  player.Speed = vector2(550, 50)
  wait(0.05)
  player.Speed = vector2(450, 100)
  wait(0.05)
  player.Speed = vector2(350, 150)
  wait(0.05)
  player.Speed = vector2(300, 175)
  wait(0.05)
  player.Speed = vector2(230, 200)
  
  waitUntilOnGround()
  engine.TimeRate = 0.65
  player.Sprite:Play("roll")
  player.Speed = vector2(125, 0)
  player.DummyAutoAnimate = false

  wait(0.6)
  player.Sprite:Play("rollGetUp")
  
  engine.TimeRate = 1
  wait(1.2)
  player.Sprite:Play("sitUp")
  wait(1.2)
  endCutscene()
end

function onStay(player)
  --Engine.Scene:DirectionalShake({ x = 100, y = 100 }, 0.02)
end

--- Callback for when the cutscene ends.
-- Function, no yielding actions allowed.
-- That means no walking, waiting etc.
-- Only "clean up" actions.
-- @tparam #Celeste.Level room Current room.
-- @bool wasSkipped If the cutscene was skipped.
function onEnd(room, wasSkipped)
  enableMovement()
  enableRetry()
end
