let library = require("../Library"); let gameConfig = require("GameConfig"); cc.Class({ extends: cc.Component, properties: { gameStates: { default: null, type: cc.Node, serializable: true, }, totalTime: { default: null, type: cc.Label, serializable: true, }, timeProgress: { default: null, type: cc.Node, serializable: true, }, countDown: { default: null, type: cc.Label, serializable: true, }, }, start () { this.init(); this.fireTick(); }, init() { //init node this.gameStatesScpt = this.gameStates.getComponent('GameStates'); this.totalTime.string = library.formatSeconds(this.gameStatesScpt.currentTime); this.timeProgressScpt = this.timeProgress.getComponent('ProgressBar'); this.countDownNum = 3; this.gameStatesScpt.curretState = this.gameStatesScpt.playing; this.lastAppearMouse = null; }, fireTick() { this.schedule(this.tick, 1); }, tick() { if(this.gameStatesScpt.currentTime==0) { this.untick(); this.gameOver(); return; } //total time this.gameStatesScpt.currentTime--; this.totalTime.string = library.formatSeconds(this.gameStatesScpt.currentTime); this.timeProgressScpt.setValue(1-(this.gameStatesScpt.currentTime/gameConfig.roundTime)); this.checkCurrentLV(); //countdown if(this.countDownNum<0) return; if(this.countDownNum==0) { this.countDown.string = ''; this.startComeOutMouse(); } else { this.countDown.string = this.countDownNum.toString(); } this.countDownNum--; }, untick() { this.unschedule(this.tick); }, checkCurrentLV() { let c_percentage = (1-this.gameStatesScpt.currentTime/gameConfig.roundTime)*100; let percentage = gameConfig.comeOutAiInLv[this.gameStatesScpt.currentLv].percentage; if(c_percentage>=percentage && this.gameStatesScpt.currentLvgStates.hiddenMouseArr.length) { num = gStates.hiddenMouseArr.length; } //随机1-num 出地鼠保证出地鼠不是看起来都是 同样的数量 好看 if(gStates.hiddenMouseArr.length!=0) { num = library.randomInt(1,num); } //创建地鼠 for(let i=0;i=gStates.hiddenMouseArr.length) { index = 0; } else { aMouse = gStates.hiddenMouseArr[index+1]; } } self.lastAppearMouse = aMouse; let aMouseScp = aMouse.getComponent('Actor'); aMouseScp.spawn(aMouse,appearDur,function (aMouse) { aMouseScp.die(); if(i==num-1) { self.scheduleOnce(function () { self.startComeOutMouse(); },lv[gStates.currentLv].duration); } }); } }, gameOver() { this.gameStatesScpt.curretState = this.gameStatesScpt.finished; } });