cc.Class({
    extends: cc.Component,

    properties: {
        地鼠预设: cc.Prefab,
        炸弹预设: cc.Prefab,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        ObjectPools = this;
        this.dishuPool = new cc.NodePool();
        this.zhadanPool = new cc.NodePool();
    },

    start() {

    },
    生成地鼠: function () {
        let 地鼠 = null;
        //c1、当前对象池中的可用对象数量
        if (this.dishuPool.size > 0) {
            //_1、从对象池中获取对象
            地鼠 = this.dishuPool.get();
        } else {
            //_2、若没有空闲的对象，也就是对象不够用时，就克隆节点
            地鼠 = cc.instantiate(this.地鼠预设);
        }
        return 地鼠;
    },
    地鼠回收: function (地鼠) {
        this.dishuPool.put(地鼠);
    },

    生成炸弹: function () {
        let 炸弹 = null;
        //c1、当前对象池中的可用对象数量
        if (this.zhadanPool.size > 0) {
            //_1、从对象池中获取对象
            炸弹 = this.zhadanPool.get();
        } else {
            //_2、若没有空闲的对象，也就是对象不够用时，就克隆节点
            炸弹 = cc.instantiate(this.炸弹预设);
        }
        return 炸弹;
    },
    炸弹回收: function (炸弹) {
        this.zhadanPool.put(炸弹);
    },
    playSimpleAudioEngine: function (engineType) {
        // 若为击打音效 则随机0-1被打音效
        if (engineType == 0) {
            var randomIndex = parseInt(Math.random() * 2, 10);
            engineType = randomIndex;
        }
        cc.audioEngine.stopAll();
        switch (engineType) {
            case 0:
                var ling = cc.audioEngine.play(cc.url.raw('resources/audio/dazhongdishu.mp3'), false, 1);
                break;
            case 1:
                var yi = cc.audioEngine.play(cc.url.raw('resources/audio/dishubeida.mp3'), false, 1);
                break;
            case 2:
                var er = cc.audioEngine.play(cc.url.raw("resources/audio/dishuguadiao.mp3"), false, 1);
                break;
            case 3:
                var san = cc.audioEngine.play(cc.url.raw("resources/audio/dishuguaixiao.mp3"), false, 1);
                break;
            case 4:
                var si = cc.audioEngine.play(cc.url.raw("resources/audio/lianji.mp3"), false, 1);
                break;
            case 5:
                var wu = cc.audioEngine.play(cc.url.raw("resources/audio/meidazhong.mp3"), false, 1);
                break;
            case 6:
                var liu = cc.audioEngine.play(cc.url.raw("resources/audio/zhadanbaozha.mp3"), false, 1);
                break;
            default:
                break;
        }
    },

    // update (dt) {},
});
