CollideBikeDown.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. const PlayerState = require('PlayerState');
  2. //todo 上车没时间解释了
  3. var BarrierSuperClass = require("BarrierSuper");
  4. cc.Class({
  5. extends:BarrierSuperClass,
  6. properties: {
  7. inTag1 : false,
  8. inTag2 : false,
  9. HAHANum:0,
  10. bHasCompared:false,
  11. },
  12. start: function () {
  13. this.finshPlayers = [];
  14. this.bHasCompared = false;
  15. cc.find('Canvas').getComponent('GameStates').EnterFinishLinePlayersArray = [];
  16. cc.find('Canvas').getComponent('GameMode').bHasAddScore = false;
  17. },
  18. onLoad : function () {
  19. this.finshPlayers = [];
  20. this.bHasCompared = false;
  21. cc.find('Canvas').getComponent('GameStates').EnterFinishLinePlayersArray = [];
  22. cc.find('Canvas').getComponent('GameMode').bHasAddScore = false;
  23. },
  24. onCollisionEnter: function (other)
  25. {
  26. if(other.node.name === 'PlayerCollisionLine') {
  27. if (other.node.parent.parent.name == "Hero") {
  28. var GmaeStates = cc.find('Canvas').getComponent('GameStates');
  29. var GameMode = cc.find('Canvas').getComponent('GameMode');
  30. if(!GmaeStates.bServer){
  31. var data = { FunctionName: 'addScore',PlayerName:'Hero'};
  32. GameMode.SynchronizationFun(data);
  33. }
  34. else{
  35. GameMode.addScore(cc.find('Hero'))
  36. }
  37. // this.TimerWinOrLose();
  38. var Hero = cc.find("Hero");
  39. var HeroControl = Hero.getComponent("HeroControl");
  40. HeroControl.downBikeHero("Hero");
  41. var data = {FunctionName:'downBikeHero',EndPositionX: Hero.x};
  42. GameMode.SynchronizationFun(data);
  43. }
  44. }
  45. },
  46. TimerWinOrLose:function(){
  47. this.callback = function () {
  48. var MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
  49. var RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
  50. if (MyScore+RivalScore == 5) {
  51. this.unschedule(this.callback);
  52. this.PlayWinAudio(MyScore,RivalScore);
  53. cc.log("==========55555555=========");
  54. }
  55. else{
  56. cc.log("+++++++++++++++++++MyScore is "+MyScore+" and RivalScore is "+RivalScore);
  57. }
  58. }
  59. this.schedule(this.callback, 1);
  60. },
  61. PlayWinAudio:function(MyScore,RivalScore){
  62. this.scheduleOnce(function() {
  63. var NetworkSocket = cc.find('Hero').getComponent("NetworkSocket");
  64. MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
  65. RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
  66. cc.find('UIControl').getComponent('GameUI').hideTimerMiddlePKScore(MyScore,RivalScore,0);
  67. if(MyScore > RivalScore){
  68. cc.find('UIControl').getComponent('GameUI').displayUIWin();
  69. cc.find('UIControl').getComponent('GameUI').playFireworks();
  70. cc.find('Hero').getComponent('HeroControl').playAudioByName("Cheers");
  71. var data = {
  72. isSelf : 2
  73. }
  74. NetworkSocket.quitGame(data);
  75. }else {
  76. cc.find('UIControl').getComponent('GameUI').displayUILose();
  77. cc.find('Hero').getComponent('HeroControl').playAudioByName("Boos");
  78. var data = {
  79. isSelf : 1
  80. }
  81. NetworkSocket.quitGame(data);
  82. }
  83. }, 0.1);
  84. if (!this.inTag1) {
  85. this.inTag1 = true;
  86. } else {
  87. return;
  88. }
  89. },
  90. onCollisionEnter2: function (other) {//旧的
  91. // cc.log("进来的是什么",other.node.name);
  92. if(other.node.name === 'PlayerCollisionLine'||other.node.name == "PlayerCollisionLine_end") {
  93. if (other.node.parent.parent.name == "Hero") {
  94. this.scheduleOnce(function() {
  95. var MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
  96. var RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
  97. cc.log("MyScore is "+MyScore+" And RivalScore is "+RivalScore);
  98. cc.find('UIControl').getComponent('GameUI').hideTimerMiddlePKScore(MyScore,RivalScore,0);
  99. if(MyScore > RivalScore){
  100. cc.find('UIControl').getComponent('GameUI').displayUIWin();
  101. cc.find('UIControl').getComponent('GameUI').playFireworks();
  102. cc.find('Hero').getComponent('HeroControl').playAudioByName("Cheers");
  103. }else {
  104. cc.find('UIControl').getComponent('GameUI').displayUILose();
  105. cc.find('Hero').getComponent('HeroControl').playAudioByName("Boos");
  106. }
  107. }, 0.1);
  108. if (!this.inTag1) {
  109. this.inTag1 = true;
  110. } else {
  111. return;
  112. }
  113. var Hero = cc.find("Hero");
  114. var NetworkSocket = Hero.getComponent('NetworkSocket');
  115. var HeroControl = Hero.getComponent("HeroControl");
  116. HeroControl.downBikeHero("Hero");
  117. var data = {FunctionName:'downBikeHero'};
  118. NetworkSocket.sendSyncData(JSON.stringify(data));
  119. this.finshPlayers.push(other.node.parent.parent);
  120. cc.log("**********hero*******");
  121. }
  122. if (other.node.parent.parent.name == "Rivel") {
  123. if (!this.inTag2) {
  124. this.inTag2 = true;
  125. } else {
  126. return;
  127. }
  128. var Hero = cc.find("Hero");
  129. var NetworkSocket = Hero.getComponent('NetworkSocket');
  130. var HeroControl = Hero.getComponent("HeroControl");
  131. HeroControl.downBikeRivel("Rivel",other);
  132. this.finshPlayers.push(other.node.parent.parent);
  133. cc.log("**********Rivel*******");
  134. }
  135. if (this.finshPlayers.length == 1) {
  136. cc.find('Canvas').getComponent('GameMode').addScore(other.node.parent.parent);
  137. cc.log("addScore*****finshPlayers0*"+this.finshPlayers[0].name);
  138. }
  139. }
  140. },
  141. javelinmoveRivel : function (data,view,starListener,endListener) {
  142. var actionBy = cc.moveBy(data.duration, data.position, data.y);
  143. var start = cc.callFunc(function () {
  144. if (starListener!=null) {
  145. starListener();
  146. }
  147. }.bind(this), this);
  148. var stop = cc.callFunc(function () {
  149. if (endListener!=null) {
  150. endListener();
  151. }
  152. }.bind(this), this);
  153. var myAction = cc.sequence(start,actionBy,stop);
  154. view.runAction(myAction);
  155. },
  156. javelinmoveHero : function (data,view,starListener,endListener) {
  157. var actionBy = cc.moveBy(data.duration, data.position, data.y);
  158. var start = cc.callFunc(function () {
  159. if (starListener!=null) {
  160. starListener();
  161. }
  162. }.bind(this), this);
  163. var stop = cc.callFunc(function () {
  164. if (endListener!=null) {
  165. endListener();
  166. }
  167. }.bind(this), this);
  168. var myAction = cc.sequence(start,actionBy,stop);
  169. view.runAction(myAction);
  170. },
  171. });