
local celeste = require('#celeste')

function onBegin()
--    disableRetry()
    disableMovement()
    setPlayerState(11)
    fire = getEntity('Bonfire')
    wait(0.5)
    walkTo(fire.X+40);
    wait(1.5)
    player.Facing=celeste.Facings.Left
    wait(0.5)
    say('iambad_sauf_CH1_END')
    wait(0.5)
    walkTo(fire.X-12)
    wait(0.2)
    player.DummyAutoAnimate=false
    player.Sprite:Play('duck')
    wait(0.5)
    -- permanently breaks lua cutscenes?
--    fire:SetMode(celeste.Bonfire.Mode.Lit)
    wait(1)
    player.Sprite:Play('idle')
    player.DummyAutoAnimate=true
    wait(0.4)
    walkTo(fire.X-24)
    wait(0.4)
    player.Facing=celeste.Facings.Right
    wait(1.5)
    walkTo(fire.X+46)
    wait(1.5)
    player.Facing=celeste.Facings.Left
    wait(0.5)
    walkTo(fire.X-48)  
    wait(1.5)
    player.Facing=celeste.Facings.Right
    wait(1)
    player.Facing=celeste.Facings.Left
    wait(0.5)
    player.Facing=celeste.Facings.Right
    wait(1)
    walkTo(fire.X+58)
    wait(0.5)
    player.Facing=celeste.Facings.Left
    wait(0.5)
    for num1 = 0, 2147483647, 1 do
        for num2 = 0, 2147483647, 1 do
            wait(0.5)
            walkTo(fire.X-48 + math.random(64)-32)
            wait(1.5)
            player.Facing=celeste.Facings.Right
            wait(1)
            player.Facing=celeste.Facings.Left
            wait(0.5)
            player.Facing=celeste.Facings.Right
            wait(1)
            walkTo(fire.X+58 + math.random(64)-32)
            wait(0.5)
            player.Facing=celeste.Facings.Left
            end
        end
    completeArea(false, true)
end


function onEnd(room, wasSkipped)
    setPlayerState(0)
    enableRetry()
    enableMovement()
end

