1000行代码写小游戏(四)

更新金币、钥匙和收藏品:

-- 更新金币
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


  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值