local function doFadeWipe(state)
    fadeWipe = celeste.FadeWipe(engine.Scene, state)
    engine.Scene:Add(fadeWipe)
    fadeWipe.duration = 6;
    fadeWipe.EndTimer = 3;
end

function onBegin()
    setFlag("flag_bonfireOn", false)
    setFlag("flag_trueFire", true)
    setFlag("flag_bonfireSound", true)
    setFlag("flag_invisibleMotion", false)
    setFlag("flag_pickUpMatch", false)
    setFlag("flag_throwMatch", false)
    setFlag("flag_matchOnGround", false)
    setFlag("flag_bonfireOn2", false)
    setFlag("flag_shadowMadeline", false)
    setFlag("flag_turnEverythingOff", false)
    setFlag("flag_forestFire", false)
    
    disableMovement()
    playSound("event:/saltedsalmon_doomwoods_ending")
    doFadeWipe(true)
    wait(1.5)
    setFlag("flag_trueFire", false)
    wait(2)
    walkTo(8516,false,0.75)
    wait(0.4)
    player.Facing = getEnum("Celeste.Facings", "Left")
    walkTo(8501,false,0.75)
    wait(0.4)
    player.Facing = getEnum("Celeste.Facings", "Right")
    walkTo(8512,false,0.75)
    wait(0.6)
    player.Facing = getEnum("Celeste.Facings", "Left")
    wait(0.2)
    walkTo(8456,false,0.75)
    wait(0.6)
    playSound("event:/char/badeline/grab")
    setFlag("flag_pickUpMatch", true)
    wait(1)
    player.Facing = getEnum("Celeste.Facings", "Right")
    walkTo(8508,false,0.75)
    wait(0.05)
    player.Facing = getEnum("Celeste.Facings", "Left")
    wait(0.7)
    playSound("event:/saltedsalmon_doomwoods_match")
    wait(0.1)
    setFlag("flag_invisibleMotion", true)
    setFlag("flag_throwMatch", true)
    wait(0.15)
    playSound("event:/char/madeline/grab_letgo")
    playSound("event:/env/local/campfire_start")
    wait(0.603)
    setFlag("flag_throwMatch", false)
    setFlag("flag_invisibleMotion", false)
    wait(0.858)
    setFlag("flag_matchOnGround", true)
    wait(1.5)
    playSound("event:/env/local/campfire_start")
    setFlag("flag_bonfireOn", true)
    setFlag("flag_bonfireSound", false)
    wait(1.8)
    setFlag("flag_bonfireOn2", true)
    wait(2)
    player.Facing = getEnum("Celeste.Facings", "Right")
    walkTo(8632,false,0.75)
    wait(1)
    setFlag("flag_shadowMadeline", true)
    setFlag("flag_ambienceProgress", true)
    wait(0.98)
    setFlag("flag_bonfireOn2", false)
    setFlag("flag_bonfireOn", false)
    setFlag("flag_turnEverythingOff", true)
    setFlag("flag_throwMatch", false)
    setFlag("flag_matchOnGround", false)
    setFlag("flag_shadowMadeline", false)
    setFlag("flag_turnEverythingOff", true)
    wait(6.66)
    setFlag("flag_forestFire", true)
    wait(12)
    doFadeWipe(false)
    wait(3)
    completeArea(false,true,true)


end
function onEnd(room, wasSkipped)
    if wasSkipped then
        completeArea(false,true,true)
    end
    
end