123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- import {CELL_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
- },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.levelNum.string = 9; //关卡
- this.surplusStepNums.string = 20; //剩余步数
- // this.targetOneNum.string = 60;
- // this.targetTwoNum.string = 55;
- // this.targetThreeNum.string = 58;
- //当前的关卡数
- // let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label)
- this.curLevelNum = this.levelNum.string * 1 + 1;
- // 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");
- //分数统计
- 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}`;
- // 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.curLevelNum++;
- // 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.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;
- }
- }
- 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 () {
- // console.log("one:",this.targetOneNum.string)
- // console.log("two:",this.targetTwoNum.string)
- // console.log("three:",this.targetThreeNum.string)
- },
- update (dt) {
- let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label)
- // this.curLevelNum = this.levelNum.string * 1 + 1;
- curLevel.string = "第" + this.curLevelNum + "关";
- },
- });
|