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

function EventLoopCoroutine()
    dialogCoroutine = coroutine.create(function()
        loadCharacter("res/characters/Rin Mayuzumi/MA05AS.png", 0)
        loadBackground("res/backgrounds/Backgrounds (SPHIA)/BG_B23E.png", 0)
        loadMusic("res/music/02 - Chaining.mp3")

        dialogBox({"Where is SELF?", "That's the one question I can't answer.", "The very thought of That Guy is annoying, you see."}, {}, -1)
        while isDialogExecuted() do coroutine.yield() end
        local currentTime = getTime()
        while getTime() - currentTime < 1.5 do
            drawText("Who am I?", 100, 100, 30)
            coroutine.yield()
        end 
        playMusic()
        dialogBox({"[Satoru] (Who... am I?)", "[Satoru] Wh... What?"}, {}, -1)
        while isDialogExecuted() do 
            coroutine.yield() 
        end
        
        drawBackground(getScreenWidth()/2, getScreenHeight()/2, 2.0, 0)
        drawCharacter(getScreenWidth()/2, getScreenHeight()/2, 2.2, 0)
        dialogBox({
            "[Mayuzumi] I don't know who you are or why you're claiming to be Yukidoh Satoru, but you're definitely a liar.", 
            "[Mayuzumi] ...",
            "[Satoru] But... Rin...",
            "[Mayuzumi] I don't want to hear this nonsense anymore! Shouldn't we get out of here? Where are we, anyway?!"}, 
            {"Okay, I guess you're right...", "Maybe you've forgotten something?"}, 3)
        while isDialogExecuted() do 
            coroutine.yield()
        end
        
        local answerValue = getAnswerValue()
        if answerValue == 1 then
            dialogBox({"[Mayuzumi] Shut up! Don't talk to me like we know each other!"}, {}, -1)
            while isDialogExecuted() do 
                coroutine.yield() 
            end
        end

        stopDrawBackground(0)
        stopDrawCharacter(0)
        stopMusic()
        local currentTime = getTime()
        while getTime() - currentTime < 0.4 do
            coroutine.yield()
        end
        unloadBackground(0)
        unloadCharacter(0)
        while getTime() - currentTime < 0.4 do
            coroutine.yield()
        end
        unloadMusic()
        loadScript("scripts/KO00.lua")
    end)
end

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

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