local vector2 = require("#microsoft.xna.framework.vector2")
local monocle = require("#monocle")
local celeste = require("#celeste")
local lua_helper = celeste.Mod.LuaCutscenes.LuaHelper

function dash(xVector,yVector)
 player.OverrideDashDirection = vector2(xVector, yVector)
 helpers.setPlayerState(2)
 player:StartDash()
 wait(0.25)
 helpers.setPlayerState(11)
 player.OverrideDashDirection = nil
end

local function makeCoroutine(func)
  return monocle.Coroutine(lua_helper.LuaCoroutineToIEnumerator(coroutine.create(func)))
end

local coroutineEntity = monocle.Entity()

function onBegin()
  disableMovement()
  player.ForceCameraUpdate = true
  wait(2)
  walkTo(-9890,false,0.8)
  coroutineEntity:add(jump(1))
  walk(-30,false,1.2)
  dash(-0.8,-0.8)
  walk(-60,false,1.2)
  dash(-1,0)
  walk(-30,false,1.2)
  run(-250,true)
  coroutineEntity:add(jump(1))
  walk(-40,false,1.5)
  dash(-1,0)
  walk(-40,false,1.5)
  player.OverrideDashDirection = vector2(-1,1)
  helpers.setPlayerState(2)
  player:StartDash()
  wait(0.1)
  helpers.setPlayerState(11)
  player.Speed = vector2(-425,-105)
  walk(-60,false,3)
  coroutineEntity:add(jump(1))
  player.Speed = vector2(-400,-150)
  walk(-90,false,3)
  dash(-1,0.8)
  walk(-5,false,4)
  coroutineEntity:add(jump(0.5))
  player.Speed = vector2(-450,-150)
  walk(-40,false,4)
  dash(-1.3,0.8)
  walk(-5,false,5)
  coroutineEntity:add(jump(1))
  player.Speed = vector2(-550,-150)
  walk(-100,false,5)
  dash(-1.6,0.8)
  walk(-5,false,6)
  coroutineEntity:add(jump(1))
  player.Speed = vector2(-550,-150)
  walk(-90,false,7)
  dash(-1.8,0.8)
  walk(-80,false,6)
  coroutineEntity:add(jump(1))
  player.Speed = vector2(-750,-150)
  walk(-400,false,7)
  coroutineEntity:add(jump(1))
  walk(-50,false,5)
  dash(-2,-0.8)
  walk(-50)
  coroutineEntity:add(jump(1))
  playSound("event:/char/madeline/jump_climb_left")
  walk(-35,false,1,true)
  coroutineEntity:add(jump(1))
  walk(-15,false,1,true)
  dash(-0.8,-0.8)
  walk(-160,false,1.5)
  coroutineEntity:add(jump(2))
  walk(-50,false,1.5)
  player.OverrideDashDirection = vector2(-1,0)
  helpers.setPlayerState(2)
  player:StartDash()
  wait(0.1)
  coroutineEntity:add(jump(1))
  player.Speed = vector2(-300,-150)
  walk(-104,false,2.5)
  player.OverrideDashDirection = vector2(-1,0)
  helpers.setPlayerState(2)
  player:StartDash()
  wait(0.1)
  coroutineEntity:add(jump(1))
  player.Speed = vector2(-300,-150)
  walk(-104,false,2.5)
  dash(-0.8,-0.8)
  walk(-50)
  coroutineEntity:add(jump(1))
  walk(-50)
  coroutineEntity:add(jump(1))
  walk(-50)
  player.Speed = vector2(100,0)
  coroutineEntity:add(jump(1))
  walk(30,false,1.5)
  dash(-0.8,-0.8)
  walk(-25,false,0.8)
  coroutineEntity:add(jump(1))
  walk(-80,false,1.3)
  coroutineEntity:add(jump(1))
  walk(-200,false,1.4)
  coroutineEntity:add(jump(1))
  walk(-40,false,1.4)
  dash(-0.8,-0.8)
  walk(-60,false,1.4)
  wait(0.5)
  walk(250,false,1.4)
  wait(2)
  walk(-20,false,0.3)
  wait(1)
  dash(0.8,-0.8)
  walk(50,false,1.5)
  wait(1)
  walk(-12,false,0.5)
  wait(1)
  walk(7,false,0.3)
  wait(0.6)
  helpers.setPlayerState(20)
  wait(20)
end

function onEnd(room, wasSkipped)
  player.OverrideDashDirection = nil
  enableMovement()
    if wasSkipped then
    completeArea(true)
  end
end