function EventLoopCoroutine()
    dialogCoroutine = coroutine.create(function()
        loadBackground("res/backgrounds/Backgrounds (Other)/BG_C04A.png", 0)
        loadBackground("res/backgrounds/Backgrounds (Other)/BG_C03N2.png", 1)
        loadBackground("res/backgrounds/Backgrounds (SPHIA)/BG_B16E.png", 2)
        loadCharacter("res/characters/Sayaka Yukidoh/SY06CL.png", 0)
        loadMusic("res/music/01 - Anxiety.mp3")
        local currentTime = getTime()
        while getTime() - currentTime < 1.5 do
            drawText("Cube II", 100, 100, 30)
            coroutine.yield()
        end
        playMusic()
        drawBackground(getScreenWidth()/2, getScreenHeight()/2, 1.68, 0)
        dialogBox({
            "[Self] (Here we are.)",
            "[Self] Argh!..."
        }, {})
        while isDialogExecuted() do
            coroutine.yield()
        end
        stopDrawBackground(0)
        local currentTime = getTime()
        while getTime() - currentTime < 0.4 do
            coroutine.yield()
        end
        drawBackground(getScreenWidth()/2, getScreenHeight()/2, 1.68, 1)
        drawCharacter(getScreenWidth()/2, getScreenHeight()/2, 2.1, 0, {r = 90, g = 90, b = 90})
        dialogBox({
            "[Self] I can help Sayaka this time.",
            "[Self] Sayaka!",
            "[Sayaka] Shadow?",
            "[Self] You wouldn't kill anyone, if you leave this place. I promise. Please, let's go.",
            "[Self] Follow my voice."
        }, {})
        while isDialogExecuted() do
            coroutine.yield()
        end
        stopDrawCharacter(0)
        stopDrawBackground(1)
        stopMusic()
        unloadMusic()
        loadMusic("res/music/09 - Old wise man.mp3")
        playMusic()
        dialogBox({
            "Escaping Leiblich facility was pretty easy."
        }, {})
        while isDialogExecuted() do
            coroutine.yield()
        end
        drawBackground(getScreenWidth()/2, getScreenHeight()/2, 1.68, 2)
        dialogBox({
            "[Self] Satoru!",
            "[Satoru] Hm? Who is it?",
            "[Self] Doesn't matter. Please, take your sister away from here. She is in danger.",
            "[Satoru] B-But wait! Who are you?",
            "[Sayaka] Brother... I want to leave...",
            "[Satoru] Okay, I'll take you home. I would be very happy if no one see me right there right now...",
        }, {})
        while isDialogExecuted() do
            coroutine.yield()
        end
        stopDrawBackground(2)
        local currentTime = getTime()
        while getTime() - currentTime < 0.4 do
            coroutine.yield()
        end
        local currentTime = getTime()
        stopMusic()
        while getTime() - currentTime < 10.0 do
            drawText("Story ended. Infinity loop broken.", getScreenWidth()/2-measureTextX("Story ended. Infinity loop broken.", 30), getScreenHeight()/2-measureTextY("Story ended. Infinity loop broken.", 30), 30)
            coroutine.yield()
        end
        unloadBackground(0)
        unloadBackground(1)
        unloadBackground(2)
        unloadCharacter(1)
        unloadMusic()
    end)
end

function EventLoop()
    if dialogCoroutine and coroutine.status(dialogCoroutine) ~= "dead" then
        coroutine.resume(dialogCoroutine)
    end
end

setFont("res/InterTight-Regular.ttf")
EventLoopCoroutine()