GameMode.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. const constants = require('Constants');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. YellowBG: {
  6. default: null,
  7. type: cc.Prefab
  8. },
  9. SpawnPoint: {
  10. default: null,
  11. type: cc.Node
  12. },
  13. GameOverUI: {
  14. default: null,
  15. type: cc.Node
  16. },
  17. },
  18. onLoad() {
  19. GlobalData.gameMode = this;
  20. this.timer = 0.3;//计时时间
  21. this.IsPlayingAudio = false;
  22. },
  23. start() {
  24. },
  25. //每一个项目结束。重置需要重置的属性
  26. afterTheEndOfSports() {
  27. //音效重置
  28. var heroControl = GlobalData.game.getHeroControl();
  29. heroControl.resetPerfectGrade();
  30. //标枪的叠加距离
  31. GlobalData.game.javeCount = 0;
  32. //标枪的距离
  33. // GlobalData.game.javelinDistance = 0;
  34. //跳远的叠加距离
  35. GlobalData.game.longJumpCount = 0;
  36. //跳远的距离
  37. // GlobalData.game.longJumpDistance = 0;
  38. //项目结束时减速一次
  39. heroControl.PlayerAnimControl.IsSlowingDownSpeed = false;
  40. },
  41. //添加当前的速度值
  42. AddGameSpeed(Value) {
  43. GlobalData.game.GameSpeed += Value;
  44. if (GlobalData.game.GameSpeed >= constants.configGameSpeedMax) {
  45. GlobalData.game.GameSpeed = constants.configGameSpeedMax;
  46. }
  47. },
  48. //减速
  49. DecelerationGameSpeed(value) {
  50. },
  51. //缓慢减速
  52. DecelerationGameSpeed_lerp(dt) {
  53. var ASpeed = constants.configGameSpeedMin;
  54. var CSpeed = GlobalData.game.GameSpeed;
  55. var speedFactor = (ASpeed - CSpeed) * 0.06;
  56. CSpeed += speedFactor;
  57. this.timer -= dt;//timer =0.3
  58. // console.log(this.timer);
  59. if (this.timer <= 0) {
  60. this.timer = 0.3;
  61. if (CSpeed <= ASpeed) {
  62. CSpeed = ASpeed;
  63. }
  64. }
  65. GlobalData.game.GameSpeed = CSpeed;
  66. GlobalData.game.getHeroControl().PlayerAnimControl.JudgeBeforeSpeedChange();
  67. },
  68. //长加速带按下
  69. StartTouchLongAcceleration() {
  70. var self = this;
  71. GlobalData.game.isMustTouch = true;//点了就设置为true
  72. self.FillLongAccelerationArea();
  73. },
  74. //长加速带停止
  75. StopTouchLongAcceleration() {
  76. if (this.YellowLinePrefab != null) {
  77. this.YellowLinePrefab.getComponent('LongAcceleration').isStop = true;
  78. this.YellowLinePrefab = null;
  79. this.IsPlayingAudio = false;
  80. GlobalData.game.getHeroControl().stopAudioByName("LongAccelerationStart");
  81. // GlobalData.game.getHeroControl().Stagger();
  82. }
  83. },
  84. FillLongAccelerationArea() {
  85. if (this.IsPlayingAudio == false) {
  86. this.IsPlayingAudio = true;
  87. GlobalData.game.getHeroControl().playAudioByName("LongAccelerationStart");
  88. }
  89. var HeroControlScript = GlobalData.game.getHeroControl();
  90. var YellowLinePosition = cc.p(HeroControlScript.node.x + 390, HeroControlScript.node.y - 32);
  91. this.YellowLinePrefab = cc.instantiate(this.YellowBG);
  92. this.YellowLinePrefab.parent = this.SpawnPoint;//GlobalData.game.getHeroControl().node;//- 641 - 32
  93. this.YellowLinePrefab.setPosition(YellowLinePosition);
  94. },
  95. //游戏结束调用
  96. GameOver() {
  97. console.log('游戏结束,是否是无敌状态:', GlobalData.game.isInvincible);
  98. if (GlobalData.game.isInvincible) return;
  99. //处理人物摔倒动画 todo.....
  100. GlobalData.game.isCanTouch = false;
  101. GlobalData.game.getHeroControl().PlayerAnimControl.Stagger();
  102. GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'Over';
  103. //并且会暂停游戏
  104. GlobalData.game.PlayerState = GlobalData.GameManager.PlayerState.Stop;
  105. setTimeout(function () {
  106. GlobalData.game.State = GlobalData.GameManager.State.Over;
  107. //游戏状态结束时候,显示结束UI
  108. this.GameOverUI.active = true;
  109. this.WatchTheAdFinish(false);
  110. // this.GameOverUI.getChildByName('Ad').active = true;
  111. //sdk
  112. //是否可以播放广告
  113. if (GlobalData.currentSdk.isCanPlayAd()) {
  114. this.GameOverUI.getChildByName('Ad').active = true;
  115. }
  116. }.bind(this), 1000)
  117. },
  118. //观看完广告
  119. WatchTheAdFinish(isWatch){
  120. console.log(this.GameOverUI.getChildByName('Ad').getChildByName('continueGame').name);
  121. this.GameOverUI.getChildByName('Ad').getChildByName('continueGame').getComponent(cc.Button).interactable = isWatch;
  122. },
  123. //游戏加分
  124. // AddScore(){
  125. // GlobalData.game.GameScore =0;
  126. // }
  127. //游戏失败后,重新续命,继续游戏。
  128. ContinueTheGame() {
  129. GlobalData.game.getHeroControl().PlayerAnimControl.Idle();
  130. // console.log(GlobalData.game.PlayerRunState);
  131. switch (GlobalData.game.PlayerRunState) {
  132. case GlobalData.GameManager.PlayerRunState.NormalRun:
  133. GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'NormalRun';
  134. break;
  135. case GlobalData.GameManager.PlayerRunState.HoldJavelinRun:
  136. GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'HoldJavelinRun';
  137. break;
  138. case GlobalData.GameManager.PlayerRunState.RideElephantRun:
  139. GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'RideElephantRun';
  140. break;
  141. }
  142. GlobalData.game.getHeroControl().PlayerAnimControl.SpeedChange();
  143. //无敌时间
  144. GlobalData.game.isInvincible = true;
  145. GlobalData.game.getHeroControl().PlayerAnimControl.PlayPlayerFlashingAnim();//无敌时间人物闪烁
  146. setTimeout(function () {
  147. GlobalData.game.isInvincible = false;
  148. GlobalData.game.getHeroControl().PlayerAnimControl.StopPlayerFlashingAnim();//停止闪烁
  149. }, GlobalData.game.invincibleTime*1000);
  150. GlobalData.game.isCanTouch = true;
  151. GlobalData.game.State = GlobalData.GameManager.State.Run;
  152. //并且会暂停游戏
  153. GlobalData.game.PlayerState = GlobalData.GameManager.PlayerState.Run;
  154. this.GameOverUI.active = false;
  155. }
  156. });