import {CELL_WIDTH} from '../Model/ConstValue'; import AudioUtils from "../Utils/AudioUtils"; import Toast from '../Utils/Toast'; cc.Class({ extends: cc.Component, properties: { // foo: { // default: null, // The default value will be used only when the component attaching // to a node for the first time // url: cc.Texture2D, // optional, default is typeof default // serializable: true, // optional, default is true // visible: true, // optional, default is true // displayName: 'Foo', // optional // readonly: false, // optional, default is false // }, // ... bombWhite:{ default: null, type: cc.Prefab }, crushEffect:{ default: null, type: cc.Prefab }, crushNumsEffect: { default: null, type: cc.Prefab }, audioUtils:{ type: AudioUtils, default: null }, currentNums: { default: null, type: cc.Label }, targetNum: { default: null, type: cc.Label }, stepNums: { default: null, type: cc.Label } }, // use this for initialization onLoad: function () { }, playEffects: function(effectQueue, gameController = null){ if(!effectQueue || effectQueue.length <= 0){ return ; } let soundMap = {}; //某一时刻,某一种声音是否播放过的标记,防止重复播放 effectQueue.forEach(function(cmd){ let delayTime = cc.delayTime(cmd.playTime); let callFunc = cc.callFunc(function(){ let instantEffect = null; let animation = null; if(cmd.action == "crush"){ instantEffect = cc.instantiate(this.crushEffect); animation = instantEffect.getComponent(cc.Animation); animation.play("effect"); !soundMap["crush" + cmd.playTime] && this.audioUtils.playEliminate(cmd.step); soundMap["crush" + cmd.playTime] = true; } else if(cmd.action == "rowBomb"){ instantEffect = cc.instantiate(this.bombWhite); animation = instantEffect.getComponent(cc.Animation); animation.play("effect_line"); } else if(cmd.action == "colBomb"){ instantEffect = cc.instantiate(this.bombWhite); animation = instantEffect.getComponent(cc.Animation); animation.play("effect_col"); }else if(cmd.action == "crushNums"){ instantEffect = cc.instantiate(this.crushNumsEffect); instantEffect.getComponent(cc.Label).string = `${cmd.nums * 10}` animation = instantEffect.getComponent(cc.Animation); animation.play("crushNums"); // 分数统计 let cnum = this.currentNums.string * 1 let tnum = this.targetNum.string * 1 let snum = this.stepNums.string * 1 if(gameController.isStepPause){ gameController.isStepPause = false gameController.showSkillTip(false) }else{ snum -= 1 } cnum += cmd.nums * 10 this.currentNums.string = `${cnum}` this.stepNums.string = `${snum}` if(cnum > tnum){ Toast('难度疯狂递增...', {duration: 3}) this.targetNum.string = `${cnum * 1.5}` this.stepNums.string = '20' }else{ if(snum <= 0){ Toast(`挑战失败, 最高分${cnum}`, {duration: 3}) this.currentNums.string = '0' this.stepNums.string = '20' this.targetNum.string = '1000' } } } instantEffect.x = CELL_WIDTH * (cmd.pos.x - 0.5); instantEffect.y = CELL_WIDTH * (cmd.pos.y - 0.5); instantEffect.parent = this.node; animation.on("finished",function(){ instantEffect.destroy(); },this); },this); this.node.runAction(cc.sequence(delayTime, callFunc)); },this); }, // called every frame, uncomment this function to activate update callback // update: function (dt) { // }, });