let library = require("../Library"); let gameConfig = require("GameConfig"); cc.Class({ extends: cc.Component, properties: { gameStates: { default: null, type: cc.Node, serializable: true, }, readyGo: { default: null, type: cc.Node, serializable: true, }, totalTime: { default: null, type: cc.Label, serializable: true, }, timeProgress: { default: null, type: cc.Node, serializable: true, }, scareCrow: { default: null, type: cc.Node, serializable: true, }, result: { default: null, type: cc.Node, serializable: true, }, }, start () { this.init(); this.armatureDisplay.playAnimation("animation",1); }, init() { //init node this.gStatesScp = this.gameStates.getComponent('GameStates'); this.audioPContrScp = this.gameStates.getComponent('AudioController'); this.armatureDisplay = this.readyGo.getComponent(dragonBones.ArmatureDisplay); //获取 Armatrue this.armature = this.armatureDisplay.armature(); //添加动画监听 this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this) this.totalTime.string = library.formatSeconds(this.gStatesScp.currentTime); this.timeProgressScp = this.timeProgress.getComponent('ProgressBar'); this.gStatesScp.curretState = this.gStatesScp.playing; this.lastAppearMouse = null; }, animationEventHandler(event) { let self = this; if (event.type === dragonBones.EventObject.COMPLETE) { if (event.animationState.name === "animation") { this.getComponent(cc.AudioSource).play(); this.fireTick(); //come in cc.tween(self.scareCrow) .by(0.1, { position: cc.v2(self.scareCrow.width,self.scareCrow.y)}) .start() this.scheduleOnce(function () { this.startComeOutMouse(); },2) } } }, fireTick() { this.schedule(this.tick, 1); }, tick() { if(this.gStatesScp.currentTime==0) { this.untick(); this.gameOver(); return; } //total time this.gStatesScp.currentTime--; this.totalTime.string = library.formatSeconds(this.gStatesScp.currentTime); this.timeProgressScp.setValue(1-(this.gStatesScp.currentTime/gameConfig.roundTime)); this.checkCurrentLV(); }, untick() { this.unschedule(this.tick); }, checkCurrentLV() { let c_percentage = (1-this.gStatesScp.currentTime/gameConfig.roundTime)*100; let percentage = gameConfig.comeOutAiInLv[this.gStatesScp.currentLv].percentage; // console.log('00000=',c_percentage) // console.log('11111=',percentage) if(c_percentage>=percentage && this.gStatesScp.currentLv