-- KO00.lua
local colors = {
    blue = {r = 0, g = 0, b = 255},
    red = {r = 255, g = 0, b = 0},
    green = {r = 0, g = 255, b = 0}
}

    function EventLoopCoroutine()
        dialogCoroutine = coroutine.create(function()
        loadBackground("res/backgrounds/Backgrounds (SPHIA)/BG_B23E.png", 0)
        loadCharacter("res/characters/Keiko Inubushi/IN01BS.png", 0)
        loadCharacter("res/characters/Keiko Inubushi/IN03BS.png", 1)
        loadCharacter("res/characters/Kali Utsumi/KA01BS.png", 2)
        loadCharacter("res/characters/Kali Utsumi/KA03BS.png", 3)
        loadCharacter("res/characters/Kali Utsumi/KA07BS.png", 4)
        loadMusic("res/music/06 - Anima.mp3")
        drawBackground(getScreenWidth()/2, getScreenHeight()/2, 2.0, 0)
        dialogBox({"[Kokoro] Inubushi, stop!"}, {}, -1)
        while isDialogExecuted() do
            coroutine.yield()
        end
        playMusic()
        drawCharacter(getScreenWidth()/2, getScreenHeight()/2, 2.2, 0)
        dialogBox({
            "[Hotori] Huh? What are you talking about?",
            "[Kokoro] Uh... I'm sorry... I saw something strange, and I thought..."
        }, {}, -1)
        while isDialogExecuted() do
            coroutine.yield()
        end
        
        stopDrawCharacter(0)
        drawCharacter(getScreenWidth()/2, getScreenHeight()/2, 2.2, 1)
        dialogBox({
            "Don't worry. Everything is okay!~",
            "[Kokoro] (She doesn't look like she's trying to hide something. But... what I saw a few moments ago...)",
            "[Kokoro] (Wasn't she trying to... kill one of the children?...)",
            "[Kokoro] (Stop. Why did she answer when I called her Inubushi Keiko? It's strange...)"
        }, {}, -1)
        while isDialogExecuted() do 
            coroutine.yield()
        end
        
        stopDrawCharacter(1)
        local currentTime = getTime()
        while getTime() - currentTime < 1.5 do
            drawText("Mother and the Child", 100, 100, 30)
            coroutine.yield()
        end
        
        drawCharacter(getScreenWidth()-getScreenWidth()/3, getScreenHeight()/2, 2.2, 0)
        drawCharacter(getScreenWidth()/3, getScreenHeight()/2, 2.2, 2)
        dialogBox({
            "[Kokoro] Hotori-chan, can I take this child from you? And Utsumi-san, are you okay with it?"
        }, {}, -1)
        while isDialogExecuted() do coroutine.yield() end
        
        stopDrawCharacter(0)
        drawCharacter(getScreenWidth()-getScreenWidth()/3, getScreenHeight()/2, 2.2, 1)
        drawCharacter(getScreenWidth()/3, getScreenHeight()/2, 2.2, 3)
        dialogBox({
            "[Hotori and Utsumi] Of course!"
        }, {}, -1)
        while isDialogExecuted() do
            coroutine.yield()
        end
        
        stopDrawCharacter(1)
        stopDrawCharacter(3)
        drawCharacter(getScreenWidth()/2, getScreenHeight()/2, 2.2, 2)
        dialogBox({
            "[Kokoro] (Aww, he's so cute!!)"
        }, {}, -1)
        while isDialogExecuted() do
            coroutine.yield()
        end
        
        dialogBox({
            "[Kokoro] Utsumi-san, have you chosen a name for them yet? And they're so cute!",
            "[Utsumi] Ah, not yet... Maybe you have some ideas? You're holding a boy.",
        }, {"Takeshi", "Makoto", "Satoru"}, 1)
        while isDialogExecuted() do 
            coroutine.yield()
        end
        
        dialogBox({
            "[Utsumi] Okay, I'll think about it. Thank you, Kokoro-chan!"
        }, {}, -1)
        while isDialogExecuted() do 
            coroutine.yield()
        end
        
        stopDrawBackground(0)
        stopDrawCharacter(0)
        stopDrawCharacter(1)
        stopDrawCharacter(2)
        stopDrawCharacter(3)
        stopDrawCharacter(4)
        stopMusic()
        local currentTime = getTime()
        while getTime() - currentTime < 0.4 do
            coroutine.yield()
        end
        unloadBackground(0)
        unloadCharacter(0)
        unloadCharacter(1)
        unloadCharacter(2)
        unloadCharacter(3)
        unloadCharacter(4)
        unloadMusic()
        loadScript("scripts/SA01.lua")
    end)
end

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

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