player_score = {}

function player_score:Draw(dt)
    UiPush()
        UiTranslate(UiCenter(), 95)
        UiAlign("center top")

        local list = ListKeys("level.player-score")
        for i=#list, math.max(1, #list-5), -1 do
            local score_entry = GetInt("level.player-score."..list[i])
            local time = GetInt("level.player-score."..list[i]..".time")
            self:showScore(score_entry, #list - i, time)
            UiTranslate(0, 51)
        end
    UiPop()
end

function player_score:showScore(score, i, time)
    local time_lerp = 1 - (math:Clamp(GetTime() - time, 0.0, 2.5) / 2.5)
    local vis_lerp = 1.0
    if time_lerp < 0.5 then
        vis_lerp = time_lerp * 2.0
    end

    if score == 0 then
        return
    end
    local text = tostring(score)
    UiPush()
        if score > 0 then
            UiColor(0.56, 1, 0.29, vis_lerp^3) -- #84F240
            text = "+"..text
        else
            UiColor(1.0, 0.184, 0.184, vis_lerp^3) -- #FF2F2F
        end
        UiWindow(206, 112)
        UiTranslate(UiCenter(), UiMiddle())
        UiAlign("center middle")

        UiFont("bold.ttf", 80)
        UiText(text)
    UiPop()
end
