| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- let gameConfig = require("GameConfig");
- let library = require("../Library");
- cc.Class({
- extends: cc.Component,
- properties: {
- gameStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- gameMode: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- playerController: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- countDown: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- kCal: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- restTimeRing: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- roundCurrentTime: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- roundTxt: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- nameTxt: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- videoController: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- videoplayer: {
- default: null,
- type: cc.Node,
- serializable: true,
- },progressBar: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- comb: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- countDownAudio: {
- default: null,
- type: cc.AudioClip,
- serializable: true,
- },
- startGunAudio: {
- default: null,
- type: cc.AudioClip,
- serializable: true,
- },
- actions: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- hint: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- loopTxt: {
- default: null,
- type: cc.Label,
- serializable: true,
- },
- nextBtn: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- onLoad () {
- this.gStatesScp = this.gameStates.getComponent('GameStates');
- this.gameModeScp = this.gameMode.getComponent('GameMode');
- this.playerControllerScp = this.playerController.getComponent('PlayerController');
- this.restTimeRingScp = this.restTimeRing.getComponent('ProgressBar');
- this.videoControllerScp = this.videoController.getComponent('SpriteVideoPlayer');
- this.audioControllerScp = this.node.getComponent('AudioController');
- this.combScp = this.comb.getComponent('Combo');
- this.punchInteractScp = this.actions.getComponent('PunchInteract');
- this.hintScp = this.hint.getComponent('Hint');
- if(!this.gStatesScp.bLoop)
- {
- this.loopTxt.string = '循环';
- }
- else {
- this.loopTxt.string = '顺序';
- }
- },
- resetRound()
- {
- this.round = gameConfig.round[this.gStatesScp.currentRound];
- this.gStatesScp.curretState = this.gStatesScp.countDown;
- this.gStatesScp.bSecondOrTimes = 0;
- if(this.round.second != 0)
- {
- this.gStatesScp.bSecondOrTimes = 1;
- }
- if(this.gStatesScp.bSecondOrTimes)
- {
- this.roundCurrentTime.getComponent(cc.Label).string = this.round.second+' ″';
- }
- else
- {
- this.roundCurrentTime.getComponent(cc.Label).string = this.round.times+' ″';
- }
- this.roundTxt.getComponent(cc.Label).string = this.gStatesScp.currentRound+1;
- this.nameTxt.getComponent(cc.Label).string = this.round.name;
- this.restTimeRingScp.getComponent(cc.Sprite).fillRange = 1;
- this.gStatesScp.roundTime = 0;
- this.gStatesScp.currentSoundIndex = 0;
- this.progressBar.getComponent(cc.ProgressBar).progress = (this.gStatesScp.currentRound+1)/24;
- if(this.gStatesScp.currentRound+1==24)
- {
- this.progressBar.getComponent(cc.ProgressBar).progress = 1;
- }
- for(let i=0; i<this.gStatesScp.hightLightActionArr.length;i++)
- {
- if(this.gStatesScp.hightLightActionArr[i]&&this.gStatesScp.hightLightActionArr[i].node)
- this.gStatesScp.hightLightActionArr[i].node.destroy();
- }
- this.gStatesScp.hightLightActionArr.length = 0;
- this.nextBtn.getComponent(cc.Button).interactable = true;
- },
- // startPlay(callback)
- startPlay()
- {
- let self = this;
- // this.callback = callback;
- this.gStatesScp.curretState = self.gStatesScp.countDown;
- this.playVideo();
- this.showActionBar();
- let times = 3;
- let countDown = function()
- {
- if(times==0)
- {
- this.unschedule(countDown);
- this.scheduleOnce(function () {
- self.audioControllerScp.playAudio('Audios/Game/Others/3、GO',function () {
- self.gStatesScp.curretState = self.gStatesScp.playing;
- self.countDown.getComponent(cc.Label).string = '';
- self.playSound();
- //start
- self.playRoundBySecond();
- });
- },0.2);
- return;
- }
- times--;
- this.countDown.getComponent(cc.Label).string = (times+1).toString();
- this.audioControllerScp.play('Audios/Game/Nums/'+(times+1).toString());
- };
- this.schedule(countDown, 1);
- },
- playSound()
- {
- let self = this;
- if(this.gStatesScp.currentSoundIndex == gameConfig.audioRound[this.gStatesScp.currentRound].length ||
- gameConfig.audioRound[this.gStatesScp.currentRound].length == 0
- )
- {
- return;
- }
- let currentAudioObj = gameConfig.audioRound[this.gStatesScp.currentRound][this.gStatesScp.currentSoundIndex];
- if (!currentAudioObj) return;
- let currentAudioPathStr = "Audios/Game/"+currentAudioObj.name;
- // console.log('44444=',currentAudioObj.name);
- // console.log('xxxx=',currentAudioObj.delay);
- this.scheduleOnce(function ()
- {
- self.audioControllerScp.playAudio(currentAudioPathStr,function () {
- self.gStatesScp.currentSoundIndex++;
- self.playSound();
- });
- // console.log('44444=',currentAudioPathStr);
- // console.log('3333=',this.gStatesScp.currentRound);
- },currentAudioObj.delay);
- },
- showActionBar()
- {
- let actionPlay = gameConfig.actionPlay[this.gStatesScp.currentRound];
- if(actionPlay.length == 0)
- {
- this.actions.parent.getChildByName('BG').y = -100;
- this.actions.active = false;
- }
- else {
- this.actions.parent.getChildByName('BG').y = 0;
- this.actions.active = true;
- }
- },
- playVideo()
- {
- this.videoControllerScp.play(this.videoplayer,this.gStatesScp.currentRound,this,this.videoCompleted);
- },
- videoCompleted(self)
- {
- if(self.gStatesScp.curretState == self.gStatesScp.countDown)
- {
- self.videoControllerScp.play(self.videoplayer,self.gStatesScp.currentRound,self,self.videoCompleted);
- }else if(self.gStatesScp.curretState == self.gStatesScp.playing)
- {
- self.videoControllerScp.play(self.videoplayer,self.gStatesScp.currentRound,self,self.videoCompleted);
- self.punchInteractScp.playActions();
- }
- },
- playRoundBySecond()
- {
- //start
- let self = this;
- this.gameModeScp.fireTick();
- this.restTimeRingScp.fire(this.round.second);
- this.timer = function ()
- {
- if (this.gStatesScp.roundTime == this.round.second)
- {
- this.finished();
- return;
- }
- if(this.round.second - this.gStatesScp.roundTime == 7)
- {
- self.audioControllerScp.play('Audios/Game/Others/再坚持5秒');
- }
- this.gStatesScp.roundTime++;
- this.roundCurrentTime.getComponent(cc.Label).string = (this.gStatesScp.roundTime).toString()+' ″';
- cc.audioEngine.play(this.countDownAudio, false, 0.5);
- };
- this.schedule(this.timer, 1);
- },
- finished()
- {
- let self = this;
- this.stop();
- cc.audioEngine.play(this.startGunAudio, false, 1);
- // roundFinished
- this.gStatesScp.curretState = this.gStatesScp.default;
- if(this.gStatesScp.bLoop)
- {
- this.playerControllerScp.playRound();
- return;
- }
- this.gStatesScp.currentRound++;
- if(this.gStatesScp.currentRound == gameConfig.round.length-1)
- {
- this.gStatesScp.curretState = this.gStatesScp.default;
- //播放结束后
- this.gameModeScp.playOver();
- return;
- }
- //delay to start
- this.playerControllerScp.scheduleOnce(function()
- {
- self.playerControllerScp.rest.x += self.playerControllerScp.rest.width;
- self.playerControllerScp.rest.active = true;
- self.playerControllerScp.rest.opacity = 255;
- self.playerControllerScp.playRest();
- cc.tween(self.playerControllerScp.rest)
- .by(0.5, { position: cc.v2(-self.playerControllerScp.rest.width, 0) })
- .start()
- },1);
- },
- next(event, customEventData)
- {
- let self = this;
- //press Onetime
- let node = event.target;
- node.getComponent(cc.Button).interactable = false;
- this.stop();
- cc.audioEngine.play(this.startGunAudio, false, 1);
- // roundFinished
- this.gStatesScp.curretState = this.gStatesScp.default;
- this.gStatesScp.currentRound++;
- if(this.gStatesScp.currentRound == gameConfig.round.length-1)
- {
- this.gStatesScp.curretState = this.gStatesScp.default;
- //播放结束后
- this.gameModeScp.playOver();
- return;
- }
- //delay to start
- this.playerControllerScp.scheduleOnce(function()
- {
- self.playerControllerScp.rest.x += self.playerControllerScp.rest.width;
- self.playerControllerScp.rest.active = true;
- self.playerControllerScp.rest.opacity = 255;
- self.playerControllerScp.playRest();
- cc.tween(self.playerControllerScp.rest)
- .by(0.5, { position: cc.v2(-self.playerControllerScp.rest.width, 0) })
- .start()
- },1);
- },
- playMode(event, customEventData)
- {
- if(!this.gStatesScp.bLoop)
- {
- this.loopTxt.string = '顺序';
- this.hintScp.showHintStr('已切换到循环播放');
- }
- else {
- this.loopTxt.string = '循环';
- this.hintScp.showHintStr('已切换到顺序播放');
- }
- this.gStatesScp.bLoop = !this.gStatesScp.bLoop;
- },
- stop()
- {
- // this.unscheduleAllCallbacks();
- this.unschedule(this.timer);
- this.gameModeScp.untick();
- this.videoControllerScp.stop();
- }
- });
|