| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- let gameConfig = require("GameConfig");
- let library = require("../Library");
- let webView = require("../WebView");
- cc.Class({
- extends: cc.Component,
- properties: {
- gameStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- gameMode: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- rest: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- demostration: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- main: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- onLoad()
- {
- let self = this;
- this.gStatesScp = this.gameStates.getComponent('GameStates');
- this.gameModeScp = this.gameMode.getComponent('GameMode');
- this.restScp = this.rest.getComponent('Rest');
- // this.demostrationScp = this.demostration.getComponent('Demostration');
- this.mainScp = this.main.getComponent('Main');
- this.bCd = true;
- if(cc.sys.isMobile)
- {
- webView.init(this.node,function () {
- let aMode = self.matchIndex();
- if(aMode == -1)
- {
- self.gStatesScp.bSinglePlayMode = false;
- }
- else
- {
- self.gStatesScp.currentRound = aMode;
- }
- webView.onBindHitBoxingPost();
- webView.onAddQuitModalListener();//添加退出事件
- self.node.on('onBoxingPostHit',self.onBoxingPostHit,self);
- self.node.on('onQuit',self.onQuit,self);
- self.node.on('onQuitModal',self.onQuitModal,self);
- self.playRest();
- });
- }
- },
- start()
- {
- if(!cc.sys.isMobile) this.playRest();
- },
- matchIndex()
- {
- let arr = gameConfig.videoNameArr;
- for(let i=0;i<arr.length;i++)
- {
- if(arr[i]==webView.videoName)
- {
- return i;
- }
- }
- return -1;
- },
- playRest()
- {
- let self = this;
- // this.playRound();
- this.restScp.fire(function () {
- self.playRound();
- cc.tween(self.rest)
- .to(0.5, { opacity: 0})
- .start();
- });
- },
- // playDemo()
- // {
- // let self = this;
- // // play demo
- // this.rest.active = false;
- // this.demostration.active = true;
- // this.demostration.opacity = 255;
- //
- // this.demostrationScp.play(function () {
- // self.playRound();
- // });
- // },
- playRound()
- {
- this.mainScp.resetRound();
- this.mainScp.startPlay();
- },
- triggleCombo(self)
- {
- self.mainScp.combScp.triggleCombo();
- },
- unTriggleCombo()
- {
- self.mainScp.combScp.unTriggleCombo();
- },
- jar()
- {
- // console.log("jar");
- for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
- {
- if(this.gStatesScp.hightLightActionArr[i].nameIndex == 0)
- {
- this.gStatesScp.hightLightActionArr[i].hit();
- this.gStatesScp.hightLightActionArr.splice(i,1);
- break;
- }
- }
- },
- leftHook()
- {
- // console.log("leftHook");
- for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
- {
- if(this.gStatesScp.hightLightActionArr[i].nameIndex == 1)
- {
- this.gStatesScp.hightLightActionArr[i].hit();
- this.gStatesScp.hightLightActionArr.splice(i,1);
- break;
- }
- }
- },
- rightHook()
- {
- // console.log("rightHook");
- for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
- {
- if(this.gStatesScp.hightLightActionArr[i].nameIndex == 1)
- {
- this.gStatesScp.hightLightActionArr[i].hit();
- this.gStatesScp.hightLightActionArr.splice(i,1);
- break;
- }
- }
- },
- hit()
- {
- for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
- {
- this.gStatesScp.hightLightActionArr[i].hit();
- this.gStatesScp.hightLightActionArr.splice(i,1);
- break;
- }
- },
- onBoxingPostHit(data)
- {
- if(this.bCd) return;
- this.bCd = true;
- let self = this;
- this.scheduleOnce(function () {
- self.bCd = false;
- },0.1);
- if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
- // console.log('data.ename='+data.ename);
- if(data.ename == 'hit')
- {
- this.hit();
- }
- },
- //页面退出回调
- onQuit(data)
- {
- // console.log('onQuit=',data);
- let kCal = this.gStatesScp.hitCount*webView.kCalUnit;
- console.log('score=',this.gStatesScp.hitCount);
- console.log('currentTime=',this.gStatesScp.currentTime);
- console.log('kCal=',kCal.toString());
- },
- //弹出框回调
- onQuitModal(res)
- {
- if (res.data.confirm) {
- let kCal = this.gStatesScp.hitCount*webView.kCalUnit;
- webView.uploadInfo(this.gStatesScp.hitCount, this.gStatesScp.currentTime, kCal);
- webView.closeGame();
- }else if(res.data.cancel){
- // console.log("取消");
- }
- },
- });
|