1000줄 코드 쓰기 미니게임(4)

2949 단어 Lua
금화, 열쇠, 소장품 업데이트:
--     
function MineSecretDialog:updateUserMoney(addMoney, isInit)
    addMoney = addMoney or 0
    isInit = isInit or false

    if addMoney ~= 0 or isInit then
        userData.money = math.max(0, userData.money + addMoney)
        AddLabel( "$ "..userData.money, ccp(posX2 + 151, posY - gap), self.m_bgKuang, Tag.MoneyLabel, ColorList[2], ccp(0, 0.5) )
    end
end
--    , ,   
function MineSecretDialog:updateUserKey(addIronKey, addSilverKey, addGoldKey, isInit)
    addIronKey = addIronKey or 0
    addSilverKey = addSilverKey or 0
    addGoldKey = addGoldKey or 0
    isInit = isInit or false

    if addIronKey ~= 0 or isInit then
        userData.ironKey = math.min(BarMaxNum.KEY, math.max(0, userData.ironKey + addIronKey))
        AddLabel( userData.ironKey, ccp(posX2 + 163, posY - gap * 2), self.m_bgKuang, Tag.IronKeyLabel, H_Font_Gray_Stroke_10, ccp(0.5, 0.5) )
    end

    if addSilverKey ~= 0 or isInit then
        userData.silverKey = math.min(BarMaxNum.KEY, math.max(0, userData.silverKey + addSilverKey))
        AddLabel( userData.silverKey, ccp(posX2 + 190, posY - gap * 2), self.m_bgKuang, Tag.SilverKeyLabel, H_Font_Gray_Stroke_10, ccp(0.5, 0.5) )
    end

    if addGoldKey ~= 0 or isInit then
        userData.goldKey = math.min(BarMaxNum.KEY, math.max(0, userData.goldKey + addGoldKey))
        AddLabel( userData.goldKey, ccp(posX2 + 217, posY - gap * 2), self.m_bgKuang, Tag.GoldKeyLabel, H_Font_Gray_Stroke_10, ccp(0.5, 0.5) )
    end
end
--      
function MineSecretDialog:updateUserCollection(collectLetter, addNum, isInit)
    addNum = addNum or 1
    isInit = isInit or false
    local count = 0

    if collectLetter ~= nil then 
        for i=1,#(userData.collection) do
            if userData.collection[i].letter == collectLetter then 
                userData.collection[i].num = math.min(BarMaxNum.COLLECT, userData.collection[i].num + addNum)
                local color = H_Font_WhiteSmall
                if userData.collection[i].num > 0 then color = ColorList[i] end
                AddLabel( userData.collection[i].letter, ccp(15 + (i-1)*20, posY - gap * 2), self.m_bgKuang, Tag.CollectionLabel+i, color, ccp(0.5, 0.5) )
            end
            if userData.collection[i].num > 0 then count = count + 1 end
        end
        if count == #(userData.collection) then
            -- TODO:      ,    
            for i=1,#(userData.collection) do
                userData.collection[i].num = userData.collection[i].num - 1
            end
            isInit = true
        end
    end

    if isInit then
        for i=1,#(userData.collection) do
            local color = H_Font_WhiteSmall
            if userData.collection[i].num > 0 then color = ColorList[i] end
            AddLabel( userData.collection[i].letter, ccp(15 + (i-1)*20, posY - gap * 2), self.m_bgKuang, Tag.CollectionLabel+i, color, ccp(0.5, 0.5) )
        end
    end
end

좋은 웹페이지 즐겨찾기