PlayerController.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. let gameConfig = require("GameConfig");
  2. let library = require("../Library");
  3. let webView = require("../WebView");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. gameStates: {
  8. default: null,
  9. type: cc.Node,
  10. serializable: true,
  11. },
  12. gameMode: {
  13. default: null,
  14. type: cc.Node,
  15. serializable: true,
  16. },
  17. rest: {
  18. default: null,
  19. type: cc.Node,
  20. serializable: true,
  21. },
  22. demostration: {
  23. default: null,
  24. type: cc.Node,
  25. serializable: true,
  26. },
  27. main: {
  28. default: null,
  29. type: cc.Node,
  30. serializable: true,
  31. },
  32. },
  33. onLoad()
  34. {
  35. let self = this;
  36. this.gStatesScp = this.gameStates.getComponent('GameStates');
  37. this.gameModeScp = this.gameMode.getComponent('GameMode');
  38. this.restScp = this.rest.getComponent('Rest');
  39. // this.demostrationScp = this.demostration.getComponent('Demostration');
  40. this.mainScp = this.main.getComponent('Main');
  41. this.bCd = true;
  42. if(cc.sys.isMobile)
  43. {
  44. webView.init(this.node,function () {
  45. let aMode = self.matchIndex();
  46. if(aMode == -1)
  47. {
  48. self.gStatesScp.bSinglePlayMode = false;
  49. }
  50. else
  51. {
  52. self.gStatesScp.currentRound = aMode;
  53. }
  54. webView.onBindHitBoxingPost();
  55. webView.onAddQuitModalListener();//添加退出事件
  56. self.node.on('onBoxingPostHit',self.onBoxingPostHit,self);
  57. self.node.on('onQuit',self.onQuit,self);
  58. self.node.on('onQuitModal',self.onQuitModal,self);
  59. self.playRest();
  60. });
  61. }
  62. },
  63. start()
  64. {
  65. if(!cc.sys.isMobile) this.playRest();
  66. },
  67. matchIndex()
  68. {
  69. let arr = gameConfig.videoNameArr;
  70. for(let i=0;i<arr.length;i++)
  71. {
  72. if(arr[i]==webView.videoName)
  73. {
  74. return i;
  75. }
  76. }
  77. return -1;
  78. },
  79. playRest()
  80. {
  81. let self = this;
  82. // this.playRound();
  83. this.restScp.fire(function () {
  84. self.playRound();
  85. cc.tween(self.rest)
  86. .to(0.5, { opacity: 0})
  87. .start();
  88. });
  89. },
  90. // playDemo()
  91. // {
  92. // let self = this;
  93. // // play demo
  94. // this.rest.active = false;
  95. // this.demostration.active = true;
  96. // this.demostration.opacity = 255;
  97. //
  98. // this.demostrationScp.play(function () {
  99. // self.playRound();
  100. // });
  101. // },
  102. playRound()
  103. {
  104. this.mainScp.resetRound();
  105. this.mainScp.startPlay();
  106. },
  107. triggleCombo(self)
  108. {
  109. self.mainScp.combScp.triggleCombo();
  110. },
  111. unTriggleCombo()
  112. {
  113. self.mainScp.combScp.unTriggleCombo();
  114. },
  115. jar()
  116. {
  117. // console.log("jar");
  118. for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
  119. {
  120. if(this.gStatesScp.hightLightActionArr[i].nameIndex == 0)
  121. {
  122. this.gStatesScp.hightLightActionArr[i].hit();
  123. this.gStatesScp.hightLightActionArr.splice(i,1);
  124. break;
  125. }
  126. }
  127. },
  128. leftHook()
  129. {
  130. // console.log("leftHook");
  131. for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
  132. {
  133. if(this.gStatesScp.hightLightActionArr[i].nameIndex == 1)
  134. {
  135. this.gStatesScp.hightLightActionArr[i].hit();
  136. this.gStatesScp.hightLightActionArr.splice(i,1);
  137. break;
  138. }
  139. }
  140. },
  141. rightHook()
  142. {
  143. // console.log("rightHook");
  144. for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
  145. {
  146. if(this.gStatesScp.hightLightActionArr[i].nameIndex == 1)
  147. {
  148. this.gStatesScp.hightLightActionArr[i].hit();
  149. this.gStatesScp.hightLightActionArr.splice(i,1);
  150. break;
  151. }
  152. }
  153. },
  154. hit()
  155. {
  156. for(let i =0;i<this.gStatesScp.hightLightActionArr.length;i++)
  157. {
  158. this.gStatesScp.hightLightActionArr[i].hit();
  159. this.gStatesScp.hightLightActionArr.splice(i,1);
  160. break;
  161. }
  162. },
  163. onBoxingPostHit(data)
  164. {
  165. if(this.bCd) return;
  166. this.bCd = true;
  167. let self = this;
  168. this.scheduleOnce(function () {
  169. self.bCd = false;
  170. },0.1);
  171. if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
  172. // console.log('data.ename='+data.ename);
  173. if(data.ename == 'hit')
  174. {
  175. this.hit();
  176. }
  177. },
  178. //页面退出回调
  179. onQuit(data)
  180. {
  181. // console.log('onQuit=',data);
  182. let kCal = this.gStatesScp.hitCount*webView.kCalUnit;
  183. console.log('score=',this.gStatesScp.hitCount);
  184. console.log('currentTime=',this.gStatesScp.currentTime);
  185. console.log('kCal=',kCal.toString());
  186. },
  187. //弹出框回调
  188. onQuitModal(res)
  189. {
  190. if (res.data.confirm) {
  191. let kCal = this.gStatesScp.hitCount*webView.kCalUnit;
  192. webView.uploadInfo(this.gStatesScp.hitCount, this.gStatesScp.currentTime, kCal);
  193. webView.closeGame();
  194. }else if(res.data.cancel){
  195. // console.log("取消");
  196. }
  197. },
  198. });