CollideBikeDown.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 GameMode = cc.find('Canvas').getComponent('GameMode');
  29. var GameStates = cc.find('Canvas').getComponent('GameStates');
  30. //这里是传给服务器判断的值,比如当前玩家的奔跑时间
  31. // let testDate = new Date();
  32. // let dateTime = testDate.getTime();//获取当前时间(从1970.1.1开始的毫秒数)
  33. // cc.log(dateTime,'当前毫秒数');
  34. if(GameStates.uploadValue ==0) {
  35. GameStates.uploadValue = cc.find('Hero').x;
  36. }
  37. let inputValue = GameStates.uploadValue;
  38. var finishData = { FunctionName: 'callFinishLine'};
  39. GameMode.SynchronizationFun(finishData);
  40. let deltaValue = GameMode.bikeDeltaValue;//毫秒
  41. if(!GameStates.bServer){
  42. var data = { FunctionName: 'addScore',PlayerName:'Hero',value:inputValue,deltaValue:deltaValue};
  43. GameMode.SynchronizationFun(data);
  44. // cc.log("--我是client,我发送给server请求加分--javelin当前项目是"+cc.find('Canvas').getComponent('GameStates').strCureentLevel);
  45. }
  46. else{
  47. GameMode.addScore(cc.find('Hero'),inputValue,true,deltaValue)
  48. }
  49. GameMode.isUploaded = true;
  50. var Hero = cc.find("Hero");
  51. var HeroControl = Hero.getComponent("HeroControl");
  52. HeroControl.downBikeHero("Hero");
  53. var data = {FunctionName:'downBikeHero',EndPositionX: Hero.x ,isCollision:true,isStop:false};
  54. GameMode.SynchronizationFun(data);
  55. }
  56. }
  57. },
  58. // TimerWinOrLose:function(){
  59. // this.callback = function () {
  60. // var MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
  61. // var RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
  62. // if (MyScore+RivalScore == 5) {
  63. // this.unschedule(this.callback);
  64. // this.PlayWinAudio(MyScore,RivalScore);
  65. // cc.log("==========55555555=========");
  66. // }
  67. // else{
  68. // cc.log("+++++++++++++++++++MyScore is "+MyScore+" and RivalScore is "+RivalScore);
  69. // }
  70. // }
  71. // this.schedule(this.callback, 1);
  72. // },
  73. // PlayWinAudio:function(MyScore,RivalScore){
  74. // this.scheduleOnce(function() {
  75. // var NetworkSocket = cc.find('Hero').getComponent("NetworkSocket");
  76. // MyScore = cc.find('Hero').getComponent("PlayerState").TerminalPoint;
  77. // RivalScore = cc.find('Rivel').getComponent("PlayerState").TerminalPoint;
  78. // cc.find('UIControl').getComponent('GameUI').hideTimerMiddlePKScore(MyScore,RivalScore,0);
  79. // if(MyScore > RivalScore){
  80. // cc.find('UIControl').getComponent('GameUI').displayUIWin();
  81. // cc.find('UIControl').getComponent('GameUI').playFireworks();
  82. // cc.find('Hero').getComponent('HeroControl').playAudioByName("Cheers");
  83. // var data = {
  84. // isSelf : 2
  85. // }
  86. // NetworkSocket.quitGame(data);
  87. // }else {
  88. // cc.find('UIControl').getComponent('GameUI').displayUILose();
  89. // cc.find('Hero').getComponent('HeroControl').playAudioByName("Boos");
  90. // var data = {
  91. // isSelf : 1
  92. // }
  93. // NetworkSocket.quitGame(data);
  94. // }
  95. // }, 0.1);
  96. // // if (!this.inTag1) {
  97. // // this.inTag1 = true;
  98. // // } else {
  99. // // return;
  100. // // }
  101. // },
  102. // javelinmoveRivel : function (data,view,starListener,endListener) {
  103. // var actionBy = cc.moveBy(data.duration, data.position, data.y);
  104. // var start = cc.callFunc(function () {
  105. // if (starListener!=null) {
  106. // starListener();
  107. // }
  108. // }.bind(this), this);
  109. // var stop = cc.callFunc(function () {
  110. // if (endListener!=null) {
  111. // endListener();
  112. // }
  113. // }.bind(this), this);
  114. // var myAction = cc.sequence(start,actionBy,stop);
  115. // view.runAction(myAction);
  116. // },
  117. // javelinmoveHero : function (data,view,starListener,endListener) {
  118. // var actionBy = cc.moveBy(data.duration, data.position, data.y);
  119. // var start = cc.callFunc(function () {
  120. // if (starListener!=null) {
  121. // starListener();
  122. // }
  123. // }.bind(this), this);
  124. // var stop = cc.callFunc(function () {
  125. // if (endListener!=null) {
  126. // endListener();
  127. // }
  128. // }.bind(this), this);
  129. // var myAction = cc.sequence(start,actionBy,stop);
  130. // view.runAction(myAction);
  131. // },
  132. });