import {CELL_HEIGHT, CELL_WIDTH, GRID_HEIGHT, GRID_WIDTH} from "../Model/ConstValue"; import AudioUtils from "../Utils/AudioUtils" import Toast from "../Utils/Toast" cc.Class({ extends: cc.Component, properties: { bombWhite:{ default:null, type:cc.Prefab }, crushEffect:{ default: null, type: cc.Prefab }, crushNumsEffect:{ default:null, type:cc.Prefab }, audioUtils:{ default:null, type:AudioUtils }, //当前分数 currentNums:{ default:null, type:cc.Label }, //关卡目标分数 // targetNum:{ // default:null, // type:cc.Label // }, //关卡目标1 targetOneNum:{ default:null, type:cc.Label }, //关卡目标2 targetTwoNum:{ default:null, type:cc.Label }, //关卡目标1 targetThreeNum:{ default:null, type:cc.Label }, //步数 surplusStepNums:{ default:null, type:cc.Label }, //关卡 levelNum:{ default:null, type:cc.Label }, stepTotal : 0, //已使用的步数 curLevelNum : 0, //当前关卡 }, // LIFE-CYCLE CALLBACKS: onLoad () { // console.log("this.node:",this.node) this.node.width = GRID_WIDTH * CELL_WIDTH; this.node.height = GRID_HEIGHT * CELL_HEIGHT; this.levelNum.string = 0; //关卡 // this.surplusStepNums.string = 20; //剩余步数 // console.log("当前关卡:",this.curLevelNum) // this.targetOneNum.string = 60; // this.targetTwoNum.string = 55; // this.targetThreeNum.string = 58; // this.progressBar = cc.find("Canvas/BloodProgress/bar").getComponent(cc.Sprite) // console.log("onload进度:",this.progressBar) //当前的关卡数 // let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label) this.curLevelNum = this.levelNum.string * 1 + 1; // console.log("curLevelNum:",this.curLevelNum) // curLevel.string = "第" + this.curLevelNum + "关"; //获取关卡类型的目标区域 // let sprite = cc.find("Canvas/TopResult/TargetArea") //关卡目标 // if (this.levelNum.string >= 8){ // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne"); // let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo"); // let targetThree = cc.find("Canvas/TopResult/TargetArea/Layout/TargetThree"); // targetOne.active = true; // targetTwo.active = true; // targetThree.active = true; // // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear; // targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat; // targetThree.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").fox; // // this.targetOneNum.string = 60; // this.targetTwoNum.string = 55; // this.targetThreeNum.string = 58; // // }else if (this.levelNum.string >= 5){ // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne"); // let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo"); // targetOne.active = true; // targetTwo.active = true; // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear; // targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat; // // this.targetOneNum.string = 60; // this.targetTwoNum.string = 55; // }else { // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne"); // targetOne.active = true; // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear; // // this.targetOneNum.string = 60; // } }, playEffects(effectQueue,gameController = null){ // console.log("特效的effectQueue:",effectQueue) if (!effectQueue || effectQueue.length <= 0){ return; } let soundMap = {}; //某一时刻,某一种声音是否播放过的标记,防止重复播放 effectQueue.forEach(function (cmd) { // console.log("cmd:", cmd) let delayTime = cc.delayTime(cmd.playTime); let callFunc = cc.callFunc(function (){ let instantEffect = null; let animation = null; // console.log("cmd的action:",cmd.action) if (cmd.action == "crush"){ // console.log("常规消除") 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"){ // console.log("正常消除了整行") instantEffect = cc.instantiate(this.bombWhite); animation = instantEffect.getComponent(cc.Animation); animation.play("effect_line"); }else if (cmd.action == "colBomb"){ // console.log("正常消除了整列") instantEffect = cc.instantiate(this.bombWhite); animation = instantEffect.getComponent(cc.Animation); animation.play("effect_col"); } else if (cmd.action == "crushRow"){ // console.log("道具消除整行") instantEffect = cc.instantiate(this.bombWhite); animation = instantEffect.getComponent(cc.Animation); animation.play("effect_line"); // this.down() }else if (cmd.action == "crushCol"){ // console.log("道具消除整列") instantEffect = cc.instantiate(this.bombWhite); animation = instantEffect.getComponent(cc.Animation); animation.play("effect_col"); } else if (cmd.action == "typeBomb"){ //道具消除一种类型 instantEffect = cc.instantiate(this.crushEffect); animation = instantEffect.getComponent(cc.Animation); animation.play("effect"); } 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"); //每完成一次,已使用的步数+1 this.stepTotal += 1; //分数统计 let currentNum = this.currentNums.string * 1; //当前分数 // let tnum = this.targetNum.string * 1; let stepNum = this.surplusStepNums.string * 1; let surplusStep = this.surplusStepNums.string * 1; if (gameController.isStepPause){ //计步暂停 gameController.isStepPause = false; gameController.showSkillTip(false); }else { //计步减1 stepNum -= 1; } currentNum += cmd.nums * 10; this.currentNums.string = `${currentNum}`; this.surplusStepNums.string = `${stepNum}`; //通关后闪现弹窗,时长3秒 // if (cnum >= tnum){ // // this.guan++; // this.levelNum.string++; // // Toast("难度疯狂递增...",{duration:3}); // Toast(`第${this.levelNum.string-1}关已完成`,{duration:3}); // this.targetNum.string = `${cnum + 2500}`; // // this.stepNums.string = "20"; // }else { // if (snum <= 0){ // Toast(`挑战失败,最高分${cnum}`,{duration:3}) // this.currentNums.string = 0; // this.stepNums.string = 20; // this.targetNum.string = 1000; // } // } // console.log("cmd:",cmd) //分类通关目标 // let targetOneNow = cmd.oneNums; // let targetTwoNow = cmd.twoNums; // let targetThreeNow = cmd.threeNums; // console.log("targetOneNow:",targetOneNow) // this.targetOneNum.string -= targetOneNow; // this.targetTwoNum.string -= targetTwoNow; // this.targetThreeNum.string -= targetThreeNow; // let targetOneNum = this.targetOneNum.string * 1; // let targetTwoNum = this.targetTwoNum.string * 1; // let targetThreeNum = this.targetThreeNum.string * 1; // if (targetOneNum <= 0){ // this.targetOneNum.string = 0; // } // if (targetTwoNum <= 0){ // this.targetTwoNum.string = 0; // } // if (targetThreeNum <= 0){ // this.targetThreeNum.string = 0; // } // console.log("剩余步数:",this.surplusStepNums.string) //结果弹窗:类型消除 // if (this.surplusStepNums.string * 1 >= 0 && targetOneNum <= 0 && targetTwoNum <= 0 && targetThreeNum <= 0){ // // Toast(`第${this.curLevelNum}关完成`, {duration:5}) // // this.targetOneNum.string = 0; // // this.targetTwoNum.string = 0; // // this.targetThreeNum.string = 0; // // this.surplusStepNums.string = 20; // // let resultMask = cc.find("Canvas/Result") // //展示关卡 // resultMask.getChildByName("Title").getComponent(cc.Label).string = `第${this.curLevelNum}关完成`; // //展示当前分数 // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum; // //展示金币 // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 20; // //展示星星 // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 20; // // // console.log("resultTitle",resultTitle) // setTimeout(function (){ // // resultMask.active = true; // // },500); // this.curLevelNum++; // this.targetOneNum.string = 60; // this.targetTwoNum.string = 55; // this.targetThreeNum.string = 58; // this.surplusStepNums.string = 20; // cc.find("Canvas/TopResult").active = false; // } // else if (this.surplusStepNums.string * 1 == 0 && (targetOneNum > 0 && targetTwoNum > 0 && targetThreeNum > 0)) { // Toast("闯关失败!",{duration:6}) // // let resultMask = cc.find("Canvas/Result") // //展示关卡 // resultMask.getChildByName("Title").getComponent(cc.Label).string = "差一点点就成功了哦"; // //展示当前分数 // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum; // //展示金币 // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 0; // //展示星星 // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 0; // // // console.log("resultTitle",resultTitle) // setTimeout(function (){ // // resultMask.active = true; // let zoom = cc.find("Canvas/Result/BtnLayout/ToZoom") // zoom.active = false; // // },500); // this.targetOneNum.string = 60; // this.targetTwoNum.string = 55; // this.targetThreeNum.string = 58; // this.surplusStepNums.string = 20; // } //结果弹窗:boss进度条 // if (this.surplusStepNums.string * 1 >= 0 && this.progressBarFillRange == 0){ // //闯关成功 // let resultMask = cc.find("Canvas/Result") // //展示关卡 // resultMask.getChildByName("Title").getComponent(cc.Label).string = `第${this.curLevelNum}关完成`; // //展示当前分数 // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum; // //展示金币 // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 20; // //展示星星 // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 20; // // // console.log("resultTitle",resultTitle) // setTimeout(function (){ // // resultMask.active = true; // // },500); // this.curLevelNum++; // // if (this.curLevelNum > 2){ // this.surplusStepNums.string = 28; // }else { // this.surplusStepNums.string = 20; // } // // this.surplusStepNums.string = 20; // this.progressBarFillRange = 1; // this.currentNums.string = 0; // // cc.find("Canvas/TopResult").active = false; // cc.find("Canvas/BloodProgress").active = false; // } // else if (this.surplusStepNums.string * 1 == 0 && this.progressBarFillRange > 0) { // // Toast("闯关失败!",{duration:6}) // //闯关失败 // let resultMask = cc.find("Canvas/Result") // //展示关卡 // resultMask.getChildByName("Title").getComponent(cc.Label).string = "差一点点就成功了哦"; // //展示当前分数 // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum; // //展示金币 // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 0; // //展示星星 // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 0; // // // console.log("resultTitle",resultTitle) // setTimeout(function (){ // // resultMask.active = true; // //闯关失败,不展示去动物园按钮 // let zoom = cc.find("Canvas/Result/BtnLayout/ToZoom") // zoom.active = false; // // },500); // // if (this.curLevelNum > 2){ // this.surplusStepNums.string = 28; // }else { // this.surplusStepNums.string = 20; // } // // // this.surplusStepNums.string = 20; // this.progressBarFillRange = 1; // this.currentNums.string = 0; // // cc.find("Canvas/TopResult").active = false; // cc.find("Canvas/BloodProgress").active = false; // } } 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); }, start () { }, update (dt) { //顶部当前关卡展示 let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label) curLevel.string = "第" + this.curLevelNum + "关"; }, });