Rest.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. let gameConfig = require("GameConfig");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. gameStates: {
  6. default: null,
  7. type: cc.Node,
  8. serializable: true,
  9. },
  10. description: {
  11. default: null,
  12. type: cc.Node,
  13. serializable: true,
  14. },
  15. countDownlabel: {
  16. default: null,
  17. type: cc.Node,
  18. serializable: true,
  19. },
  20. smallWhiteRing: {
  21. default: null,
  22. type: cc.Node,
  23. serializable: true,
  24. },
  25. title: {
  26. default: null,
  27. type: cc.Node,
  28. serializable: true,
  29. },
  30. videoController: {
  31. default: null,
  32. type: cc.Node,
  33. serializable: true,
  34. },
  35. demostration: {
  36. default: null,
  37. type: cc.Node,
  38. serializable: true,
  39. },
  40. bigRing: {
  41. default: null,
  42. type: cc.Node,
  43. serializable: true,
  44. },
  45. countDownLabel: {
  46. default: null,
  47. type: cc.Node,
  48. serializable: true,
  49. },
  50. jumpTo: {
  51. default: null,
  52. type: cc.Node,
  53. serializable: true,
  54. },
  55. bCountDown:false,
  56. bLoadRes:false,
  57. },
  58. onLoad()
  59. {
  60. this.audioNames = [
  61. '1、前绕肩',
  62. '2、后绕肩',
  63. '3、屈膝转体热身',
  64. '4、体前曲出拳',
  65. '5、拳击站架',
  66. '6、前直拳',
  67. '7、后直拳',
  68. '8、前后滑步',
  69. '9、前后滑步前直拳',
  70. '10、上步左右直拳',
  71. '11、侧闪',
  72. '12、前摆拳',
  73. '13、后勾拳',
  74. '14、前直后勾组合拳',
  75. '15、前摆后直组合拳',
  76. '16、直勾摆组合拳',
  77. '17、摇臂',
  78. '18、侧闪后直拳',
  79. '19、交替出拳',
  80. '20、右侧肩部拉伸',
  81. '21、左侧肩部拉伸',
  82. '22、左臂拉伸',
  83. '23、右臂拉伸',
  84. '24、最后一个动作,坚持就是胜利'
  85. ];
  86. this.gStatesScp = this.gameStates.getComponent('GameStates');
  87. this.progressBarScp = this.smallWhiteRing.getComponent('ProgressBar');
  88. this.videoControllerScp = this.videoController.getComponent('SpriteVideoPlayer');
  89. this.audioControllerScp = this.node.getComponent('AudioController');
  90. this.bigRingBtn = this.bigRing.getComponent(cc.Button);
  91. this.bPress = true;
  92. this.reset();
  93. },
  94. reset()
  95. {
  96. this.round = gameConfig.rest[this.gStatesScp.currentRound];
  97. this.description.getComponent(cc.Label).string = this.round.description;
  98. this.totalTime = this.round.second;
  99. this.countDownlabel.getComponent(cc.Label).string = this.totalTime.toString();
  100. this.title.getComponent(cc.Label).string = this.round.name;
  101. this.gStatesScp.currentSoundIndex = 0;
  102. this.bLoadRes = false;
  103. this.bCountDown = false;
  104. //button
  105. this.bPress = true;
  106. this.bigRing.getComponent(cc.Button).interactable = true;
  107. this.countDownLabel.y = 0;
  108. this.jumpTo.active = false;
  109. this.bigRingBtn.interactable = false;
  110. },
  111. fire(callback)
  112. {
  113. this.reset();
  114. if(this.gStatesScp.bSinglePlayMode)
  115. {
  116. this.audioControllerScp.play('Audios/Game/Names/'+this.audioNames[this.gStatesScp.currentRound]);
  117. }
  118. //for testing
  119. if(gameConfig.rest[this.gStatesScp.currentRound].rest == 1) {
  120. this.bCountDown = true;
  121. this.onFinishAllCallback();
  122. return;
  123. }
  124. // console.log('当前资源加载完成1');
  125. this.videoControllerScp.prepareCurrentRoundVideo(this.gStatesScp.currentRound,()=>{
  126. // console.log('当前资源加载完成2');
  127. this.bLoadRes = true;
  128. if(this.bCountDown)
  129. {
  130. this.onFinishAllCallback();
  131. }
  132. //如果单独播放模式,加载完视频直接跳转
  133. if(this.gStatesScp.bSinglePlayMode)
  134. {
  135. this.onFinishAllCallback();
  136. return;
  137. }
  138. this.countDownLabel.y = 9;
  139. this.jumpTo.active = true;
  140. this.bigRingBtn.interactable = true;
  141. });
  142. this.playSound();
  143. this.progressBarScp.fire(this.totalTime);
  144. this.callback = callback;
  145. this.schedule(this.countDown, 1);
  146. },
  147. //全部操作完成调用
  148. onFinishAllCallback(){
  149. //Multiple press button
  150. if(!this.bPress) return;
  151. this.bPress = false;
  152. this.bigRing.getComponent(cc.Button).interactable = false;
  153. this.stop();
  154. this.scheduleOnce(function ()
  155. {
  156. this.callback();
  157. // this.playRound();
  158. // cc.tween(this.node)
  159. // .to(0.5, { opacity: 0})
  160. // .call(() => {
  161. // this.node.opacity = 255;
  162. // this.node.active = false;
  163. // this.callback();
  164. // })
  165. // .start();
  166. },1);
  167. },
  168. playSound()
  169. {
  170. if(gameConfig.round[this.gStatesScp.currentRound].second == 2) return;
  171. if( this.gStatesScp.curretState != this.gStatesScp.demostration) return;
  172. if(this.gStatesScp.currentSoundIndex == gameConfig.audioRest[this.gStatesScp.currentRound].length ||
  173. gameConfig.audioRest[this.gStatesScp.currentRound].length == 0
  174. ) return;
  175. let currentAudioObj = gameConfig.audioRest[this.gStatesScp.currentRound][this.gStatesScp.currentSoundIndex];
  176. if (!currentAudioObj) {
  177. return;
  178. }
  179. let currentAudioPathStr = "Audios/Game/"+currentAudioObj.name;
  180. let Self = this;
  181. this.scheduleOnce(function ()
  182. {
  183. this.audioControllerScp.playAudio(currentAudioPathStr,function () {
  184. Self.gStatesScp.currentSoundIndex++;
  185. Self.playSound();
  186. });
  187. },currentAudioObj.delay);
  188. },
  189. countDown()
  190. {
  191. if(this.totalTime==1)
  192. {
  193. this.unschedule(this.countDown);
  194. this.bCountDown = true;
  195. if(this.bLoadRes)
  196. {
  197. this.onFinishAllCallback();
  198. }
  199. return;
  200. }
  201. this.totalTime--;
  202. this.countDownlabel.getComponent(cc.Label).string = this.totalTime.toString();
  203. },
  204. stop()
  205. {
  206. this.progressBarScp.stop();
  207. }
  208. });