HeroControl.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. const PlayerStateStatic = require('PlayerState');
  2. const GameStatesStatic = require('GameStates');
  3. const MOVE_RIGHT = 2;
  4. cc.macro.ENABLE_TILEDMAP_CULLING = false;
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. InitialPositionY: 0,
  9. PlayerStateScript: null,
  10. jumps: 2,
  11. acceleration: 2500,
  12. jumpSpeed: 600,
  13. drag: 600,
  14. CharactorScript: null,
  15. javelinTag: false,
  16. PerfectGrade: 0,
  17. isPlayingBoos: false,
  18. CameraNode: {
  19. default: null,
  20. type: cc.Node
  21. },
  22. Cushion30AndBunker1M: {//标枪起跳
  23. default: null,
  24. type: cc.Prefab
  25. },
  26. javetemp_Hero: {//标枪起跳
  27. default: null,
  28. type: cc.Prefab
  29. },
  30. javetemp_Rivel: {//标枪起跳
  31. default: null,
  32. type: cc.Prefab
  33. },
  34. sendFrameDataTag: false,
  35. longJumpCount: 0,//跳远加的距离
  36. takeOffDistance: 0,//跳远开始的距离。
  37. isChangeSpeed: false,//是否正在改变速度
  38. timer: 0.3,//计时时间
  39. HeroIsStop:false,//hero是否停止状态
  40. },
  41. onEnable: function () {
  42. cc.director.getPhysicsManager().attachDebugDrawToCamera(this);
  43. },
  44. onDisable: function () {
  45. cc.director.getPhysicsManager().detachDebugDrawFromCamera(this);
  46. },
  47. onLoad: function () {
  48. this.init = cc.find("init");
  49. this.fadeTag = false;
  50. this.javeCount = 0;// parseInt(Math.random()*10+30);
  51. this.node.setLocalZOrder(1000);
  52. this.body = this.getComponent(cc.RigidBody);
  53. this.speed = cc.p(0, 0);
  54. this._moveFlags = -1;
  55. this.PlayerStateScript = this.node.getComponent("PlayerState");
  56. var Player = this.node.getChildByName('Player');
  57. this.CharactorScript = Player.getComponent("Charactor");
  58. this.PlayerStateScript.CurrentSpeed = this.PlayerStateScript.InitialSpeed;
  59. //踉跄 被拽过去的tag 如果是 true 就不重置速度 如果是 如果是 false 就充值速度
  60. this.CameraNode = cc.find('CamerarMennager');
  61. },
  62. SetCurrentSpeed: function (SpeedValue) {
  63. if (SpeedValue > this.PlayerStateScript.MaxSpeed) return;
  64. if (SpeedValue < 0) return;
  65. this.PlayerStateScript.CurrentSpeed = SpeedValue;
  66. return SpeedValue;
  67. },
  68. SetCurrentSpeed_noRestrictions: function (SpeedValue) {
  69. this.PlayerStateScript.CurrentSpeed = SpeedValue;
  70. },
  71. SetCurrentSpeed_max: function (SpeedValue) {
  72. var seed = (SpeedValue * 420) / this.PlayerStateScript.MaxSpeed;
  73. this.PlayerStateScript.CurrentSpeed = seed + 1800;
  74. return this.PlayerStateScript.CurrentSpeed * (SpeedValue / this.PlayerStateScript.MaxSpeed);
  75. },
  76. SetCurrentSpeed_max_jumpLong: function (SpeedValue) {
  77. var seed = (SpeedValue * 200) / this.PlayerStateScript.MaxSpeed;
  78. this.PlayerStateScript.CurrentSpeed = seed + 800;
  79. return this.PlayerStateScript.CurrentSpeed * (SpeedValue / this.PlayerStateScript.MaxSpeed);
  80. },
  81. SetCurrentSpeedInitialSpeed: function () {
  82. this.PlayerStateScript.CurrentSpeed = this.PlayerStateScript.InitialSpeed;
  83. },
  84. SetSpeedToZeroAndIdle: function () {
  85. this.HeroIsStop = true;//玩家停止
  86. this.SetCurrentSpeed(0);
  87. this.idle();
  88. },
  89. SetCurrentSpeedAndAnimation: function (SpeedValue) {
  90. this.CharactorScript.setType();
  91. var CurrentSpeed = this.SetCurrentSpeed(SpeedValue);
  92. var state = PlayerStateStatic.SpeedRangeForAnimation;
  93. if (CurrentSpeed >= state.SlowSpeed[0] && CurrentSpeed <= state.SlowSpeed[1]) {
  94. this.CharactorScript.SetCurrentAnimationIdx(0);
  95. }
  96. if (CurrentSpeed >= state.MiddleSpeed[0] && CurrentSpeed <= state.MiddleSpeed[1]) {
  97. this.CharactorScript.SetCurrentAnimationIdx(1);
  98. }
  99. if (CurrentSpeed >= state.HightSpeed[0] && CurrentSpeed <= state.HightSpeed[1]) {
  100. this.CharactorScript.SetCurrentAnimationIdx(2);
  101. }
  102. },
  103. SetCurrentSpeed_set: function (SpeedValue) {
  104. this.CharactorScript.setType();
  105. if (SpeedValue > this.PlayerStateScript.MaxSpeed) return;
  106. if (SpeedValue < 0) return;
  107. this.SetCurrentSpeed(SpeedValue);
  108. var CurrentSpeed = this.PlayerStateScript.CurrentSpeed;
  109. // cc.log("设置 速度",CurrentSpeed ,cc.find('Canvas').getComponent('GameStates').bServer);
  110. var state = PlayerStateStatic.SpeedRangeForAnimation;
  111. if (CurrentSpeed >= state.SlowSpeed[0] && CurrentSpeed <= state.SlowSpeed[1]) {
  112. this.CharactorScript.SetCurrentAnimationIdx_set(0);
  113. }
  114. if (CurrentSpeed >= state.MiddleSpeed[0] && CurrentSpeed <= state.MiddleSpeed[1]) {
  115. this.CharactorScript.SetCurrentAnimationIdx_set(1);
  116. }
  117. if (CurrentSpeed >= state.HightSpeed[0] && CurrentSpeed <= state.HightSpeed[1]) {
  118. this.CharactorScript.SetCurrentAnimationIdx_set(2);
  119. }
  120. },
  121. //就是跑步 加上速度
  122. SetCurrentSpeed_noType: function (SpeedValue) {
  123. if (SpeedValue > this.PlayerStateScript.MaxSpeed) return;
  124. if (SpeedValue < 0) return;
  125. this.SetCurrentSpeed(SpeedValue);
  126. this.CharactorScript.type = 0;
  127. this.CharactorScript.SetCurrentAnimationIdx_set(0);
  128. },
  129. SpeedUp: function (SpeedUpValue) {
  130. if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
  131. // return;
  132. var ToSpeed = this.PlayerStateScript.CurrentSpeed + SpeedUpValue;
  133. this.SetCurrentSpeedAndAnimation(ToSpeed);
  134. var data = { FunctionName: 'SetCurrentSpeedAndAnimation', Speed: ToSpeed, "CurrentPositionX": this.node.position.x };
  135. cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
  136. },
  137. ResetSpeed: function () {
  138. if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
  139. var ASpeed = this.PlayerStateScript.InitialSpeed;
  140. this.SetCurrentSpeedAndAnimation(ASpeed);
  141. },
  142. ResetSpeed_noType_lerp: function (dt) {
  143. if (this.isChangeSpeed) {
  144. var ASpeed = this.PlayerStateScript.InitialSpeed;
  145. var CSpeed = this.PlayerStateScript.CurrentSpeed;
  146. var speedFactor = (ASpeed - CSpeed) * 0.4;
  147. this.timer -= dt;//timer =0.3
  148. if (this.timer <= 0) {
  149. this.timer = 0.3;
  150. CSpeed += speedFactor;
  151. if (CSpeed <= ASpeed) {
  152. this.unschedule(this.resetSpeedCallBack);
  153. CSpeed = ASpeed;
  154. this.isChangeSpeed = false;
  155. }
  156. console.log("ResetSpeed_noType", CSpeed);
  157. this.SetCurrentSpeed_noType(CSpeed);
  158. }
  159. }
  160. },
  161. ResetSpeed_noType_lerp_Stop: function () {
  162. this.isChangeSpeed = false;
  163. },
  164. ResetSpeed_noType: function () {
  165. if(this.HeroIsStop){
  166. console.log('当前玩家是停止状态,不能设置ResetSpeed_noType!');
  167. return;
  168. }
  169. var ASpeed = this.PlayerStateScript.InitialSpeed;
  170. this.SetCurrentSpeed_noType(ASpeed);
  171. },
  172. ResetSpeed_set: function () {
  173. this.SetCurrentSpeed_set(this.PlayerStateScript.InitialSpeed);
  174. },
  175. //todo 根据当前 速度设置 动作
  176. SetCurrentSpeedAction: function () {
  177. // if(!bDebug) return;
  178. if (!cc.find('Canvas').getComponent('GameStates').bServer) return;
  179. this.SetCurrentSpeedAndAnimation(this.PlayerStateScript.CurrentSpeed);
  180. },
  181. HeroJump: function (callBack) {
  182. if ("camera_ai" == cc.director.getScene().name) {
  183. this.HeroJumpAnimation(callBack);
  184. return;
  185. }
  186. var Hero = cc.find("Hero");
  187. var NetworkSocket = Hero.getComponent('NetworkSocket');
  188. var data = {};
  189. if (this.node.name === 'Hero') {
  190. data = { FunctionName: 'HeroJumpHeroAnimation' };
  191. NetworkSocket.sendSyncData(JSON.stringify(data));
  192. }
  193. this.HeroJumpAnimation(callBack);
  194. },
  195. HeroJumpAnimation: function (callBack) {
  196. var Player = this.node.getChildByName('Player');
  197. Player.getComponent("Charactor").setOnHurdlingListener(callBack);
  198. this.playAudioByName("Hei");
  199. },
  200. EnableHeroMoving: function (bMoving) {
  201. if (bMoving) {
  202. this._moveFlags = MOVE_RIGHT;
  203. this.PlayerStateScript.CurrentSpeed= this.PlayerStateScript.InitialSpeed;
  204. }
  205. else {
  206. this._moveFlags = -1;
  207. }
  208. },
  209. WriggleControl: function (dt) {
  210. if (this.WriggleTag) {
  211. // cc.log("减速",this.PlayerStateScript.CurrentSpeed);
  212. if (this.PlayerStateScript.CurrentSpeed >= this.PlayerStateScript.InitialSpeed) {
  213. this.PlayerStateScript.CurrentSpeed -= dt * 300;
  214. } else {
  215. this.WriggleTag = false;
  216. this.SetCurrentSpeed_set(this.PlayerStateScript.CurrentSpeed);
  217. }
  218. }
  219. },
  220. //todo 开启加速
  221. addSeendTempControl: function () {
  222. if (this.addSeendTempTag) {
  223. return;
  224. }
  225. if (this.PlayerStateScript.CurrentSpeed <= 400) {
  226. this.addSeendCurrentSpeed = this.PlayerStateScript.CurrentSpeed;
  227. this.PlayerStateScript.CurrentSpeed += 400;
  228. // cc.log("加速了吗",this.PlayerStateScript.CurrentSpeed);
  229. this.addSeendTempTag = true;
  230. }
  231. },
  232. addSeendTemp: function (dt) {
  233. if (this.addSeendTempTag) {
  234. // cc.log("减速",this.PlayerStateScript.CurrentSpeed);
  235. if (this.addSeendCurrentSpeed <= this.PlayerStateScript.CurrentSpeed) {
  236. this.PlayerStateScript.CurrentSpeed -= dt * 200;
  237. // cc.log("加速了吗-",dt);
  238. } else {
  239. this.addSeendTempTag = false;
  240. }
  241. }
  242. },
  243. HeroLongJump: function (name) {
  244. // console.log("HeroLongJump==", this.longJumpCount);
  245. // var Hero = cc.find("Hero");
  246. // var NetworkSocket = Hero.getComponent('NetworkSocket');
  247. // var data = {};
  248. var longJumpData = {
  249. name: "Hero",
  250. longJumpCount: this.longJumpCount,//跳的距离
  251. takeOffDistance: this.takeOffDistance,//蓝区域跳的距离范围
  252. }
  253. // if (this.node.name === 'Hero') {
  254. // data = { FunctionName: 'HeroLongJumpHeroAnimation', netData: longJumpData };
  255. // NetworkSocket.sendSyncData(JSON.stringify(data));
  256. // }
  257. this.HeroLongJumpAnimation(longJumpData);
  258. this.playAudioByName("Hei");
  259. },
  260. HeroLongJumpAnimation: function (tempData) {
  261. var Player = this.node.getChildByName('Player');
  262. var Hero = cc.find(tempData.name);
  263. //扔标枪 计数算法 todo
  264. var UIControl = cc.find("UIControl").getComponent("UIControl");
  265. // var Hero = cc.find('Hero');
  266. var PlayerStateScript = Hero.getComponent("PlayerState");
  267. PlayerStateScript.TouchControlEnableTouch = false;
  268. this.SetCurrentSpeed(0);
  269. this.javelinTag = true;
  270. var jumpDistance = 3 + tempData.longJumpCount; //跳了多少米
  271. var jumpPixelSpeed = jumpDistance > 4 ? 900 : 600;
  272. var jumpDistancePixel = jumpDistance * 240 + tempData.takeOffDistance;//1m约等于 240像素,并且加上 开始的距离
  273. var jumpTimer = jumpDistancePixel / jumpPixelSpeed;//跳远的时间
  274. var actionMoveBy = cc.moveBy(jumpTimer, cc.p(jumpDistancePixel, 0));
  275. this.node.runAction(actionMoveBy);
  276. var jumpHeight = (jumpDistance - 3) * 10 + 100;//100是固定高度
  277. var actionBy = cc.jumpBy(jumpTimer, 0, 0, jumpHeight, 1);
  278. console.log("跳远的距离====:", jumpDistance, this.takeOffDistance);
  279. // console.log("跳远的距离:",jumpDistance);
  280. PlayerStateScript.EndDistance = jumpDistance;//记录位置信息
  281. PlayerStateScript.JumpTimer = jumpTimer;
  282. Player.getComponent("Charactor").node.runAction(actionBy);
  283. //跳远开始
  284. Player.getComponent("Charactor").setOnLongJumpListener(jumpTimer);
  285. // if (Hero.name == "Hero") {
  286. // UIControl.startDistance_Hero(0, Hero, true);
  287. // }
  288. if (Hero.name == "Hero") {
  289. UIControl.startDistance_Hero(0, Hero, true);
  290. }
  291. this.SetCurrentSpeed(0);
  292. //跳远结束
  293. Player.getComponent("Charactor").setTimeOutLongJumpListener(function () {
  294. this.SetCurrentSpeed(0);
  295. // CustomLog("当前 玩家", Hero.name, "跳远结束");
  296. // if (Hero.name == "Hero") {
  297. // UIControl.startDistance_Hero(0, Hero, false);
  298. // }
  299. setTimeout(function () {
  300. if (!this.javelinTag) {
  301. return;
  302. }
  303. // Player.getComponent("Charactor").setAnimation(0, Player.getComponent("Charactor").statusArr_longjump[6], false);
  304. Player.getComponent("Charactor").spine.timeScale = 1;//跳远落地后动画的播放速度,timeScale越大,速度越快
  305. }.bind(this), 500);
  306. setTimeout(function () {
  307. if (!this.javelinTag) {
  308. return;
  309. }
  310. this.ResetSpeed();
  311. }.bind(this), 1000);
  312. this.playAudioByName("JumpDown");
  313. this.resetPerfectGrade();//踉跄则重置perfect等级
  314. }.bind(this));
  315. },
  316. StopPlayerAllSchedule: function () {
  317. // var GameMode = cc.find('Canvas').getComponent('GameMode');
  318. var GameStates = cc.find('Canvas').getComponent('GameStates');
  319. var Hero = cc.find('Hero');
  320. var Rivel = cc.find('Rivel');
  321. var HeroControl = Hero.getComponent('HeroControl');
  322. var RivelControl = Rivel.getComponent('HeroControl');
  323. var HeroCharactor = Hero.getChildByName('Player').getComponent('Charactor');
  324. var RivelCharactor = Rivel.getChildByName('Player').getComponent('Charactor');
  325. HeroCharactor.unscheduleAllCallbacks();
  326. RivelCharactor.unscheduleAllCallbacks();
  327. Hero.stopAllActions();
  328. Rivel.stopAllActions();
  329. HeroControl.javelinTag = false;
  330. RivelControl.javelinTag = false;
  331. HeroControl.CameraNode.parent = Hero;
  332. GameStates.bStopAllAnimationAndSchedule = true;
  333. HeroControl.SetSpeedToZeroAndIdle();
  334. RivelControl.SetSpeedToZeroAndIdle();
  335. this.schedule(function () {
  336. GameStates.bStopAllAnimationAndSchedule = false;
  337. }, 1, 0);
  338. },
  339. //踉跄 摔倒
  340. Stagger: function () {
  341. this.StaggerAnimation();
  342. // cc.log("踉跄 本地",this.node);
  343. // var data = { FunctionName: 'StaggerAnimation', PositionX: this.node.convertToWorldSpaceAR(cc.Vec2.ZERO).x };
  344. // cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
  345. this.playAudioByName("Boos");
  346. this.resetPerfectGrade();
  347. this.resetLv();
  348. },
  349. resetLv : function () {
  350. cc.find("Shade").getComponent('Shade').FadeInAndOut(function ()
  351. {
  352. cc.log("黑屏");
  353. this.init.getComponent("init").initGame();
  354. }.
  355. bind(this),function ()
  356. {
  357. cc.log("亮屏");
  358. }.bind(this));
  359. },
  360. StaggerAnimation: function () {
  361. if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
  362. if (this.PlayerStateScript.BStagger) return;
  363. this.PlayerStateScript.BStagger = !this.PlayerStateScript.BStagger;
  364. //踉跄+减速
  365. var Player = this.node.getChildByName('Player');
  366. Player.getComponent("Charactor").setOnTripListener();
  367. this.SetCurrentSpeedAndAnimation(0);
  368. // this.ResetSpeed();
  369. // this.schedule(this.StaggerAnimationSchedule, 0.5, 0);
  370. },
  371. StaggerAnimationSchedule: function () {
  372. if (cc.find('Canvas').getComponent('GameStates').bStopAllAnimationAndSchedule) return;
  373. this.PlayerStateScript.BStagger = !this.PlayerStateScript.BStagger;
  374. if (this.PlayerStateScript.BStagger) {
  375. return;
  376. }
  377. // this.ResetSpeed();
  378. },
  379. unSchedules: function () {
  380. this.unschedule(this.StaggerAnimationSchedule);
  381. },
  382. StaggerAnimationUnch: function () {
  383. this.unschedule(this.StaggerAnimationSchedule);
  384. },
  385. SendSyncHeroPosition: function () {
  386. var Hero = cc.find("Hero");
  387. var PositionStr = Hero.position.x.toString();
  388. var data = { FunctionName: 'Hero', PositionX: PositionStr, Speed: Hero.getComponent('PlayerState').CurrentSpeed };
  389. cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
  390. },
  391. SendSyncRivelPosition: function () {
  392. var Rivel = cc.find("Rivel");
  393. var PositionStr = Rivel.position.x.toString();
  394. var Hero = cc.find("Hero");
  395. var data = { FunctionName: 'Rivel', PositionX: PositionStr, Speed: Hero.getComponent('PlayerState').CurrentSpeed };
  396. cc.find('Canvas').getComponent('GameMode').SynchronizationFun(data);
  397. },
  398. // called every frame, uncomment this function to activate update callback
  399. update: function (dt) {
  400. var PlayerCollisionLine = this.node.getChildByName('Player').getChildByName('PlayerCollisionLine');
  401. if (PlayerCollisionLine) {
  402. if (!PlayerCollisionLine.active) {
  403. if (this.node.position.x - this.node.getComponent('PlayerState').AtStartLinePositionX > 100) {
  404. PlayerCollisionLine.active = true;
  405. }
  406. }
  407. }
  408. var Hero = cc.find("Hero");
  409. // var DistanceBetweenMeAndRival = Hero.x;
  410. // var absDistanceBetweenMeAndRival = Math.abs(Math.floor(DistanceBetweenMeAndRival));
  411. //
  412. //
  413. // // cc.log("这是多少",dt);
  414. // //这里注释一下,屏幕宽720,一半为360,人物宽65,相加为425,也就是说对手与自己距离425像素外则需显示头像
  415. // if (DistanceBetweenMeAndRival > 425) {//大于425,则头像在右边
  416. // cc.find('UIControl').getComponent('GameUI').displayRivalHead(false);
  417. // }
  418. // if (DistanceBetweenMeAndRival < -425) {//小于425,则头像在左边
  419. // cc.find('UIControl').getComponent('GameUI').displayRivalHead(true);
  420. // }
  421. // if (DistanceBetweenMeAndRival > -425 && DistanceBetweenMeAndRival < 425) {
  422. // cc.find('UIControl').getComponent('GameUI').hideRivalHead();
  423. // }
  424. // this.speed = this.body.linearVelocity;
  425. // this.speed = cc.p(-50,0);
  426. // cc.log("刚体X",this.speed);
  427. var Level = cc.find("Level");
  428. Level.getComponent('LevelControl').SetDistance(this.node.getPosition().x);
  429. if (this._moveFlags === MOVE_RIGHT) {
  430. if (this.node.scaleX < 0) {
  431. this.node.scaleX *= -1;
  432. }
  433. var PlayerPositionX = this.node.getPositionX();
  434. PlayerPositionX += 1 * dt * this.PlayerStateScript.CurrentSpeed;
  435. this.node.setPositionX(PlayerPositionX);
  436. }
  437. if (this.jumps > 0 && this._up) {
  438. this.speed.y = this.jumpSpeed;
  439. this.jumps--;
  440. }
  441. //Stop at start line
  442. var PlayerState = this.node.getComponent('PlayerState');
  443. // var StartLineStopPositionArray = PlayerState.StartLineStopPositionArray;
  444. // if (StartLineStopPositionArray.length != 0) {
  445. // var StartLineStopPositionOriginalX = PlayerState.StartLineStopPositionArray[0];
  446. // var StartLineStopPositionX = PlayerState.StartLineStopPositionArray[0];
  447. // if (this.node.name == 'Hero') {
  448. // StartLineStopPositionX -= 30;
  449. // }
  450. // if ((this.node.position.x - StartLineStopPositionX) >-10) {
  451. //
  452. // if (this.node.name == 'Hero') {
  453. // // console.log("Hero 停!!");
  454. // this.SetSpeedToZeroAndIdle();
  455. // this.node.setPositionX(StartLineStopPositionX);
  456. // PlayerState.StartLineStopPositionArray.shift();
  457. //
  458. // var GameStates = cc.find('Canvas').getComponent('GameStates');
  459. // var GameMode = cc.find('Canvas').getComponent('GameMode');
  460. // var CurrentPlayerNode = this.node;
  461. // GameStates.StartLinePositionX = StartLineStopPositionOriginalX;
  462. // var data = { FunctionName: 'SetStartLinePositionX', StartLinePositionX: StartLineStopPositionOriginalX };
  463. // GameMode.SynchronizationFun(data);
  464. // if (GameStates.bServer) {
  465. // GameStates.EnterStartLinePlayersArray.push(CurrentPlayerNode);
  466. // GameMode.CheckPlayersDistance(true);
  467. // }
  468. // else {
  469. // var data = { FunctionName: 'CheckPlayersDistance', StartLinePositionX: StartLineStopPositionOriginalX };
  470. // GameMode.SynchronizationFun(data);
  471. // }
  472. // // if (GameStates.bServer) {
  473. // // GameStates.EnterStartLinePlayersArray.push(CurrentPlayerNode);
  474. // // var data = { FunctionName: 'SetStartLinePositionX', StartLinePositionX: StartLineStopPositionOriginalX };
  475. // // GameMode.SynchronizationFun(data);
  476. // // GameMode.CheckPlayersDistance(true);
  477. //
  478. // // console.log("this.node.name GameStates.bServer ", this.node.name);
  479. // // }
  480. // // else {
  481. // // var data = { FunctionName: 'CheckPlayersDistance', StartLinePositionX: StartLineStopPositionOriginalX };
  482. // // GameMode.SynchronizationFun(data);
  483. //
  484. // // console.log("this.node.name GameStates.bClient", this.node.name);
  485. // // }
  486. // }
  487. // }
  488. // }
  489. //Reduce speed at Finish line
  490. var FinishLineReduceSpeedPositionArray = PlayerState.FinishLineReduceSpeedPositionArray;
  491. if (FinishLineReduceSpeedPositionArray.length != 0) {
  492. var FinishLineStopPositionX = PlayerState.FinishLineReduceSpeedPositionArray[0];
  493. if ((this.node.position.x - FinishLineStopPositionX) >-10) {
  494. if(!this.HeroIsStop){//当前玩家是停止状态,不能设置ResetSpeed_noType
  495. this.ResetSpeed_noType();
  496. if (this.node.name == 'Hero') {
  497. var NetworkSocket = cc.find('Hero').getComponent('NetworkSocket');
  498. var data = {};
  499. data = { FunctionName: 'FinishLineReduceSpeedPositionArray' };
  500. // console.log("hero 减速!!!");
  501. NetworkSocket.sendSyncData(JSON.stringify(data));
  502. }
  503. }
  504. // console.log("Name:",this.node.name);
  505. // this.isChangeSpeed = true;//开启减速
  506. PlayerState.FinishLineReduceSpeedPositionArray.shift();
  507. }
  508. }
  509. // this.ResetSpeed_noType_lerp(dt);
  510. // this.javelinUpDate();
  511. // var da = {
  512. // p : this.node.getPositionX()
  513. // };
  514. // this.sendFrameDatas(da);
  515. this._up = false;
  516. this.body.linearVelocity = this.speed;
  517. this.WriggleControl(dt);
  518. this.addSeendTemp(dt);
  519. if (!cc.find('Canvas').getComponent('GameStates').BStartGame) return;
  520. if (this.node.name != 'Rivel') return;
  521. var SyschroAtionArray = this.PlayerStateScript.SyschroAtionArray;
  522. if (SyschroAtionArray.length > 0) {
  523. CustomLog("现在里面有设么没处理的", SyschroAtionArray);
  524. if (SyschroAtionArray[0].FunctionName === 'StaggerAnimation') {
  525. this.StaggerAnimation();
  526. // cc.log("踉跄 网络",this.node);
  527. SyschroAtionArray.shift();
  528. }
  529. else if (SyschroAtionArray[0].FunctionName === 'SetCurrentSpeedAndAnimation') {
  530. this.SetCurrentSpeedAndAnimation(SyschroAtionArray[0].Speed);
  531. SyschroAtionArray.shift();
  532. }
  533. else if ('ResetSpeed' === SyschroAtionArray[0].FunctionName) {
  534. this.ResetSpeed_noType();
  535. SyschroAtionArray.shift();
  536. }
  537. else if ('SetSpeedToZeroAndIdle' === SyschroAtionArray[0].FunctionName) {
  538. this.SetSpeedToZeroAndIdle();
  539. SyschroAtionArray.shift();
  540. }
  541. else if (SyschroAtionArray[0].FunctionName === 'HeroLongJumpHeroAnimation') {//todo 跳远
  542. var Hero = cc.find('Rivel');
  543. var HeroControl = Hero.getComponent("HeroControl");
  544. var tempData = SyschroAtionArray[0].netData;
  545. var longJumpData = {
  546. name: "Rivel",
  547. longJumpCount: tempData.longJumpCount,//跳的距离
  548. takeOffDistance: tempData.takeOffDistance,//蓝区域跳的距离范围
  549. }
  550. HeroControl.HeroLongJumpAnimation(longJumpData);
  551. // console.log("我现在 处理 跳远 2 ", SyschroAtionArray[0].FunctionName, tempData);
  552. // CustomLog("我现在 处理 跳远 2 ", SyschroAtionArray[0].FunctionName);
  553. SyschroAtionArray.shift();
  554. }
  555. else if (SyschroAtionArray[0].FunctionName === 'SetCurrentSpeed_max_jumpLong') {
  556. // CustomLog("跳远设置速度");
  557. //todo 标记2
  558. this.seend = this.PlayerStateScript.CurrentSpeed;
  559. this.SetCurrentSpeed_max_jumpLong(this.seend);
  560. SyschroAtionArray.shift();
  561. }
  562. else if (SyschroAtionArray[0].FunctionName === 'HeroJumpHeroAnimation') {
  563. this.HeroJumpAnimation();
  564. SyschroAtionArray.shift();
  565. }
  566. else if (SyschroAtionArray[0].FunctionName === 'PerfectHurdleBandRailing') {
  567. // CustomLog("跨栏 撞倒","PerfectHurdleBandRailing");
  568. var data = SyschroAtionArray[0];
  569. var Hero = cc.find("Hero");
  570. var NetworkSocket = Hero.getComponent('NetworkSocket');
  571. CustomLog("跨栏 撞倒", data);
  572. var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
  573. SyschroAtionArray.shift();
  574. if (Obj == null) {
  575. return;
  576. }
  577. Obj.getComponent("Barrier").FallingDown();
  578. }
  579. else if (SyschroAtionArray[0].FunctionName === 'PerfectHurdleBandBarrier') {
  580. // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
  581. var data = SyschroAtionArray[0];
  582. var Hero = cc.find("Hero");
  583. var NetworkSocket = Hero.getComponent('NetworkSocket');
  584. // CustomLog("跨栏 撞倒",data);
  585. var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
  586. SyschroAtionArray.shift();
  587. if (Obj == null) {
  588. return;
  589. }
  590. Obj.getComponent("Barrier").FallingDown();
  591. }
  592. else if (SyschroAtionArray[0].FunctionName === 'ShakeBarrier') {
  593. // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
  594. var data = SyschroAtionArray[0];
  595. var Hero = cc.find("Hero");
  596. var NetworkSocket = Hero.getComponent('NetworkSocket');
  597. // CustomLog("跨栏 晃",data);
  598. var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
  599. SyschroAtionArray.shift();
  600. if (Obj == null) {
  601. return;
  602. }
  603. Obj.getComponent("Barrier").Shake();
  604. }
  605. else if (SyschroAtionArray[0].FunctionName === 'upBike') {
  606. // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
  607. // cc.log("上车 网络", this.node);
  608. this.SetCurrentSpeed(0);
  609. this.upBike();
  610. var Charactor = this.node.getChildByName('Player');
  611. var CharactorScript = Charactor.getComponent("Charactor");
  612. setTimeout(function () {
  613. CharactorScript.spine.timeScale = 1;
  614. cc.find('Canvas').getComponent('GameStates').CurrentProgress = GameStatesStatic.GameProgress.RideBike;
  615. this.SetCurrentSpeed(PlayerStateStatic.SpeedRangeForAnimation.SlowSpeed[1]);
  616. }.bind(this), 600);
  617. SyschroAtionArray.shift();
  618. }
  619. else if (SyschroAtionArray[0].FunctionName === 'downBikeHero') {
  620. // CustomLog("跨栏 撞倒","PerfectHurdleBandBarrier");
  621. SyschroAtionArray.shift();
  622. }
  623. else if (SyschroAtionArray[0].FunctionName === 'upJavelinHeroAnimation') {
  624. var data = SyschroAtionArray[0];
  625. var NetworkSocket = Hero.getComponent('NetworkSocket');
  626. CustomLog("捡起来标枪");
  627. var Obj = NetworkSocket.GetSyncObj(data.ParentName, data.ObjName, data.PositionX);
  628. this.upJavelin();
  629. this.SetCurrentSpeed(PlayerStateStatic.SpeedRangeForAnimation.SlowSpeed[1]);
  630. if (Obj != null) {
  631. Obj.active = false;
  632. }
  633. cc.find('Canvas').getComponent('GameStates').CurrentProgress = GameStatesStatic.GameProgress.Javelin;
  634. SyschroAtionArray.shift();
  635. }
  636. else if (SyschroAtionArray[0].FunctionName === 'Herojavelin') {
  637. // this.javelinRivel("Rivel");
  638. SyschroAtionArray.shift();
  639. }
  640. else if (SyschroAtionArray[0].FunctionName === 'Restrictions') {
  641. this.SetCurrentSpeed_noRestrictions(600);
  642. SyschroAtionArray.shift();
  643. }
  644. else if (SyschroAtionArray[0].FunctionName === 'upJavelinend') {
  645. this.SetCurrentSpeed_noRestrictions(SyschroAtionArray[0].Speed);
  646. SyschroAtionArray.shift();
  647. }
  648. else if (SyschroAtionArray[0].FunctionName === 'JavelinData') {
  649. this.javelinRivel("Rivel" ,SyschroAtionArray[0].JavelinData,SyschroAtionArray[0].JaveCount);
  650. SyschroAtionArray.shift();
  651. }
  652. }
  653. },
  654. upJavelin: function () {
  655. var Charactor = this.node.getChildByName('Player');
  656. var CharactorScript = Charactor.getComponent("Charactor");
  657. CharactorScript.upJavelin();
  658. this.SetCurrentSpeedAction();
  659. },
  660. javelinUpDate: function () {
  661. // var PlayerState = this.node.getComponent('PlayerState');
  662. // // cc.log("",this.node.name);
  663. // cc.log("创建出来的标枪 333 Rivel",PlayerState.JavePositionArray_Rivel);
  664. // if (this.node.name=="Rivel") {
  665. // var Rivelarr = PlayerState.JavePositionArray_Rivel;
  666. // if (Rivelarr.length != 0) {
  667. // cc.log("局标枪",this.node.name,(this.node.position.x - Rivelarr[0].px));
  668. // if (Math.abs(this.node.position.x - Rivelarr[0].px) < 10)
  669. // {
  670. // if (Rivelarr[0].node != null) {
  671. // Rivelarr[0].node.active = false;
  672. // }
  673. // // this.upJavelin();
  674. //
  675. // PlayerState.JavePositionArray_Rivel.shift();
  676. // }
  677. // }
  678. //
  679. // }
  680. // else if (this.node.name=="Hero") {
  681. // var Heroarr = PlayerState.JavePositionArray_Hero;
  682. // if (Heroarr.length != 0) {
  683. // if (Math.abs(this.node.position.x - Heroarr[0].px) < 10)
  684. // {
  685. //
  686. // PlayerState.JavePositionArray_Rivel.shift();
  687. // }
  688. // }
  689. // }
  690. // var FinishLineReduceSpeedPositionArray = PlayerState.FinishLineReduceSpeedPositionArray;
  691. // if (FinishLineReduceSpeedPositionArray.length != 0)
  692. // {
  693. // var FinishLineStopPositionX = PlayerState.FinishLineReduceSpeedPositionArray[0];
  694. //
  695. // if (Math.abs(this.node.position.x - FinishLineStopPositionX.px) < 10)
  696. // {当前jave
  697. // this.node.getComponent('HeroControl').ResetSpeed_noType();
  698. // PlayerState.FinishLineReduceSpeedPositionArray.shift();
  699. // }
  700. // }
  701. },
  702. upBike: function () {
  703. var Charactor = this.node.getChildByName('Player');
  704. var CharactorScript = Charactor.getComponent("Charactor");
  705. CharactorScript.upBike();
  706. this.SetCurrentSpeedAction();
  707. },
  708. upJavelin_go: function (callBack) {
  709. var Charactor = this.node.getChildByName('Player');
  710. var CharactorScript = Charactor.getComponent("Charactor");
  711. CharactorScript.upJavelin_go(callBack);
  712. this.playAudioByName("Hei");
  713. },
  714. idle: function (callBack) {
  715. var Charactor = this.node.getChildByName('Player');
  716. var CharactorScript = Charactor.getComponent("Charactor");
  717. CharactorScript.idle(callBack);
  718. },
  719. readyRun: function (callBack) {
  720. var Charactor = this.node.getChildByName('Player');
  721. var CharactorScript = Charactor.getComponent("Charactor");
  722. CharactorScript.readyRun(callBack);
  723. },
  724. addidle: function (callBack) {
  725. var Charactor = this.node.getChildByName('Player');
  726. var CharactorScript = Charactor.getComponent("Charactor");
  727. CharactorScript.addidle(callBack);
  728. },
  729. idleadd: function (callBack) {
  730. var Charactor = this.node.getChildByName('Player');
  731. var CharactorScript = Charactor.getComponent("Charactor");
  732. CharactorScript.idleadd(callBack);
  733. },
  734. playAudioByName: function (AudioName) {
  735. var AudioSource = this.getAudioSourceByName(AudioName);
  736. if (AudioSource != null) {
  737. if (AudioName == "Boos") {//踉跄时的音效:若正在播放此音效则不能播放;
  738. if (this.isPlayingBoos == false) {
  739. this.isPlayingBoos = true;
  740. AudioSource.play();
  741. this.scheduleOnce(function () {
  742. this.isPlayingBoos = false;
  743. }, AudioSource.getDuration());
  744. }
  745. } else {
  746. AudioSource.play();
  747. }
  748. }
  749. },
  750. stopAudioByName: function (AudioName) {
  751. var AudioSource = this.getAudioSourceByName(AudioName);
  752. if (AudioSource != null) {
  753. AudioSource.stop();
  754. }
  755. },
  756. getAudioSourceByName: function (AudioName) {
  757. var HeroPlayer = null;
  758. // cc.log(AudioName);
  759. if (this.node.name == "Hero") {
  760. if (cc.find('Hero').getChildByName('Player') != null) {
  761. HeroPlayer = cc.find('Hero').getChildByName('Player');
  762. if (HeroPlayer.getChildByName("MyAudio") != null) {
  763. var AudioControlScript = HeroPlayer.getChildByName('MyAudio').getComponent("AudioControl");
  764. if (AudioControlScript.getAudioSourceByName(AudioName) != null) {
  765. var AudioSource = AudioControlScript.getAudioSourceByName(AudioName);
  766. return AudioSource;
  767. }
  768. }
  769. }
  770. }
  771. },
  772. addPerfectGradeAndPlay: function () {
  773. if (this.PerfectGrade < 10) {
  774. this.PerfectGrade += 1;
  775. }
  776. this.playAudioByName("Perfect" + this.PerfectGrade);
  777. },
  778. resetPerfectGrade: function () {
  779. this.PerfectGrade = 0;
  780. },
  781. javelin: function () {
  782. //获取场景
  783. var scene = cc.director.getScene();
  784. // cc.log("父亲",scene);
  785. var charactor = scene.getChildByName("Hero").getChildByName("Player").getComponent("Charactor");
  786. // cc.log("有么",charactor);
  787. var HeroControl = scene.getChildByName("Hero").getComponent("HeroControl");
  788. // console.log("javelin");
  789. if (HeroControl != null) {
  790. var Player = scene.getChildByName("Hero").getChildByName("Player");
  791. //扔标枪
  792. HeroControl.upJavelin_go();
  793. this.seend = HeroControl.PlayerStateScript.CurrentSpeed;
  794. setTimeout(function () {
  795. // cc.log("标枪预制 1",this.javelin_prefab);
  796. var tPrefab = this.tPrefabs = cc.instantiate(this.javelin_prefab);
  797. // cc.log("标枪预制 2",tPrefab);
  798. var Level = cc.find("Level");
  799. var Hero = cc.find("Hero");
  800. //扔标枪 计数算法 todo
  801. var UIControl = cc.find("UIControl").getComponent("UIControl");
  802. UIControl.startDistance(1, Hero, true);
  803. tPrefab.parent = Hero;
  804. tPrefab.zIndex = 999;
  805. tPrefab.setPosition(100, -50);
  806. var HeroControl = scene.getChildByName("Hero").getComponent("HeroControl");
  807. var data = {
  808. duration: 3.5,
  809. position: 0,
  810. y: -70,
  811. height: 500,
  812. jumps: 1
  813. };
  814. tPrefab.getComponent("Charactor_javeLin").javelin(data, function () {
  815. var datas = {
  816. duration: 1,
  817. position: -1000,
  818. y: 0
  819. };
  820. this.javelinmoveHero(datas, Player);
  821. HeroControl.SetCurrentSpeed(this.seend + 1000);
  822. console.log("Start Javelin;")
  823. }.bind(this), function () {
  824. console.log("End Javelin;")
  825. var Level = cc.find("Level");
  826. HeroControl.SetCurrentSpeed(0);
  827. var datas = {
  828. duration: 2,
  829. position: 1000,
  830. y: 0
  831. };
  832. charactor.readyRun();
  833. //人物进场
  834. this.javelinmoveHero(datas, Player, null, function () {
  835. var p = tPrefab.getBoundingBoxToWorld();
  836. tPrefab.parent = Level;
  837. tPrefab.setPosition(p.x - 360, p.y - 640);
  838. // CustomLog("现在坐标 父类",p,p1,tPrefab.getBoundingBoxToWorld());
  839. HeroControl.SetCurrentSpeed(500);
  840. UIControl.startDistance(1, Hero, false);
  841. }.bind(this));
  842. }.bind(this));
  843. this.node.destroy();
  844. }.bind(this), 500);
  845. }
  846. },
  847. javelinmove: function (data, view, starListener, endListener) {
  848. var actionBy = cc.moveBy(data.duration, data.position, data.y);
  849. var start = cc.callFunc(function () {
  850. if (starListener != null) {
  851. starListener();
  852. }
  853. }.bind(this), this);
  854. var stop = cc.callFunc(function () {
  855. if (endListener != null) {
  856. endListener();
  857. }
  858. }.bind(this), this);
  859. var myAction = cc.sequence(start, actionBy, stop);
  860. view.runAction(myAction);
  861. },
  862. javelinRivel: function (name, javalinData, JaveCount) {
  863. // console.log("javelin rivel;");
  864. //获取场景
  865. var scene = cc.director.getScene();
  866. // cc.log("父亲",scene);
  867. var charactor = scene.getChildByName(name).getChildByName("Player").getComponent("Charactor");
  868. // cc.log("有么",charactor);
  869. var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
  870. HeroControl.javelinTag = true;
  871. console.log("javelin rivel;");
  872. if (HeroControl != null) {
  873. var Hero = scene.getChildByName(name);
  874. //扔标枪
  875. HeroControl.upJavelin_go();
  876. HeroControl.idleadd();
  877. HeroControl.SetCurrentSpeed(0);
  878. // return;
  879. setTimeout(function () {
  880. HeroControl = scene.getChildByName(name).getComponent("HeroControl");
  881. if (!HeroControl.javelinTag) {
  882. return;
  883. }
  884. var tPrefab = cc.instantiate(this.javetemp_Rivel);
  885. tPrefab.parent = cc.director.getScene();//中部PK积分显示后隐藏
  886. this.addCamera(tPrefab);
  887. tPrefab.active = true;
  888. tPrefab.isTag = true;
  889. tPrefab.zIndex = 999;
  890. tPrefab.setPosition(Hero.x, Hero.y + 100);
  891. var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
  892. var x = 1440 + JaveCount * 72;
  893. var data = javalinData;
  894. tPrefab.javeTime = data.duration;
  895. var datas = {
  896. duration: data.duration,
  897. position: x,
  898. y: 0
  899. };
  900. tPrefab.getChildByName("jave").getComponent("Charactor_javeLin").javelin(data, function () {
  901. if (!HeroControl.javelinTag) {
  902. tPrefab.isTag = null;
  903. return;
  904. }
  905. HeroControl.javelinmoveHero(datas, tPrefab);
  906. }.bind(this), function () {
  907. tPrefab.isTag = null;
  908. if (!HeroControl.javelinTag) {
  909. tPrefab.isTag = null;
  910. return;
  911. }
  912. HeroControl.javelinmoveHero_act(datas);
  913. if (tPrefab.x - this.node.x > 3000) {
  914. this.node.x = tPrefab.x-720;
  915. }
  916. charactor.readyRun();
  917. }.bind(this));
  918. }.bind(this), 150);
  919. }
  920. },
  921. //计算height,和duration
  922. javelinData: function (x) {
  923. var MiddleX = x / 2;
  924. var highest = Math.sqrt(x * x - MiddleX * MiddleX) - x;
  925. highest = highest < 0 ? -highest : highest;
  926. highest += 120;
  927. // console.log("标枪的x值=", x, "this.javeCount=", this.javeCount, "highest==", highest);
  928. var tempDuration = x > 5000 ? 4 : 2;
  929. var data = {
  930. duration: tempDuration,
  931. position: 0,
  932. y: -70,
  933. height: highest,//600
  934. jumps: 1
  935. };
  936. return data;
  937. },
  938. javelinHero: function (name) {
  939. //获取场景
  940. var scene = cc.director.getScene();
  941. // cc.log("父亲",scene);
  942. var charactor = scene.getChildByName(name).getChildByName("Player").getComponent("Charactor");
  943. // cc.log("有么",charactor);
  944. var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
  945. var Hero = cc.find(name);
  946. var NetworkSocket = Hero.getComponent('NetworkSocket');
  947. // cc.log("有没有",HeroControl.javelinTag);
  948. HeroControl.javelinTag = true;
  949. if (HeroControl != null) {
  950. var Hero = scene.getChildByName(name);
  951. //扔标枪
  952. HeroControl.upJavelin_go();
  953. var UIControl = cc.find("UIControl").getComponent("UIControl");
  954. HeroControl.idleadd();
  955. HeroControl.SetCurrentSpeed(0);
  956. var x = 1440 + this.javeCount * 72;
  957. var data = this.javelinData(x);
  958. //同步数据给rivel
  959. // var NetData = { FunctionName: 'JavelinData', JavelinData: data, JaveCount: this.javeCount };
  960. // NetworkSocket.sendSyncData(JSON.stringify(NetData));
  961. // return;
  962. setTimeout(function () {
  963. cc.log('看一下走到哪了');
  964. HeroControl = scene.getChildByName(name).getComponent("HeroControl");
  965. // cc.log("到终点",HeroControl.javelinTag);
  966. if (!HeroControl.javelinTag) {
  967. return;
  968. }
  969. var tPrefab = cc.instantiate(this.javetemp_Hero);
  970. tPrefab.parent = cc.director.getScene();//中部PK积分显示后隐藏
  971. tPrefab.active = true;
  972. tPrefab.isTag = true;
  973. cc.log(HeroControl.CameraNode+'**************');
  974. HeroControl.CameraNode.parent = tPrefab;
  975. this.addCamera(tPrefab);
  976. tPrefab.zIndex = 999;
  977. tPrefab.setPosition(Hero.x, Hero.y);
  978. var HeroControl = scene.getChildByName(name).getComponent("HeroControl");
  979. var datas = {
  980. duration: data.duration,
  981. position: x,
  982. y: 0
  983. };
  984. tPrefab.getChildByName("jave").getComponent("Charactor_javeLin").javelin(data, function () {
  985. if (!HeroControl.javelinTag) {
  986. tPrefab.isTag = null;
  987. return;
  988. }
  989. tPrefab.javeTime = data.duration;
  990. UIControl.startDistance_Hero(1, tPrefab, true);
  991. HeroControl.javelinmoveHero(datas, tPrefab);
  992. cc.log("变速 扔标枪1", HeroControl.PlayerStateScript.CurrentSpeed);
  993. }.bind(this), function () {
  994. if (!HeroControl.javelinTag) {
  995. tPrefab.isTag = null;
  996. return;
  997. }
  998. //
  999. cc.log("标枪和人的距离", tPrefab.x,this.node.x);
  1000. HeroControl.javelinmoveHero_act(datas);
  1001. if (tPrefab.x - this.node.x > 3000) {
  1002. this.node.x = tPrefab.x-720;
  1003. }
  1004. tPrefab.isTag = null;
  1005. tPrefab.getComponent("CollideHurdleBand_javelinemove").cameraNodeTag = true;
  1006. // cc.log("标枪结束",tPrefab.x);
  1007. this.stopAudioByName("JavelinFlying");//停止标枪飞的声音
  1008. this.playAudioByName("JavelinDown");//播放标枪落地的声音
  1009. // UIControl.startDistance_Hero(1, tPrefab, false);
  1010. UIControl.setCallBack_Hero(function (m) {
  1011. }.bind(this));
  1012. charactor.readyRun();
  1013. // cc.log("到终点",HeroControl.javelinTag);
  1014. var p1 = tPrefab.getPosition();
  1015. }.bind(this));
  1016. }.bind(this), 150);
  1017. }
  1018. },
  1019. javelinmoveRivel: function (data, view, starListener, endListener) {
  1020. var actionBy = cc.moveBy(data.duration, data.position, data.y);
  1021. var start = cc.callFunc(function () {
  1022. if (starListener != null) {
  1023. starListener();
  1024. }
  1025. }.bind(this), this);
  1026. var stop = cc.callFunc(function () {
  1027. if (endListener != null) {
  1028. endListener();
  1029. }
  1030. }.bind(this), this);
  1031. var myAction = cc.sequence(start, actionBy, stop);
  1032. view.runAction(myAction);
  1033. },
  1034. javelinmoveHero: function (data, view, starListener, endListener) {
  1035. // console.log("javelinMoveHero = ", data);
  1036. var actionBy = cc.moveBy(data.duration, data.position, data.y);
  1037. var start = cc.callFunc(function () {
  1038. if (starListener != null) {
  1039. starListener();
  1040. }
  1041. }.bind(this), this);
  1042. var stop = cc.callFunc(function () {
  1043. if (endListener != null) {
  1044. endListener();
  1045. }
  1046. }.bind(this), this);
  1047. var myAction = cc.sequence(start, actionBy, stop);
  1048. view.runAction(myAction);
  1049. },
  1050. javelinmoveHero_act: function (data) {
  1051. var speed = data.position / (data.duration + 1);
  1052. // cc.log("速度是",speed);
  1053. this.SetCurrentSpeed_noRestrictions(speed);
  1054. },
  1055. downBikeHero: function (name) {
  1056. var charactor = cc.find(name).getChildByName("Player").getComponent("Charactor");
  1057. if (charactor != null) {
  1058. charactor.downBike(function () {
  1059. charactor.readyRun();
  1060. }.bind(this));
  1061. // charactor.readyRun();
  1062. // charactor.idleadd();
  1063. // cc.find(name).getComponent('HeroControl').SetCurrentSpeed(0);
  1064. cc.find(name).getComponent("PlayerState").enableTouch = false;
  1065. }
  1066. },
  1067. downBikeRivel: function (name) {
  1068. var charactor = cc.find(name).getChildByName("Player").getComponent("Charactor");
  1069. if (charactor != null) {
  1070. charactor.downBike(function () {
  1071. }.bind(this));
  1072. charactor.idleadd();
  1073. cc.find(name).getComponent('HeroControl').SetCurrentSpeed(0);
  1074. cc.find(name).getComponent("PlayerState").enableTouch = false;
  1075. }
  1076. },
  1077. addCamera: function (node) {
  1078. if(cc.find("CamerarMennager")!=null){
  1079. var CamerarMennager = cc.find("CamerarMennager").getComponent('CamerarMennager');
  1080. CamerarMennager.addTargets(node);
  1081. }else{
  1082. cc.log('******************');
  1083. }
  1084. // var CameraNode = cc.find("Hero").getChildByName("CameraNode");
  1085. var Hero;
  1086. var CameraNode;
  1087. var javetemp_Hero;
  1088. if (cc.find("Hero").getChildByName("CameraNode") != null) {
  1089. Hero = cc.find("Hero").getChildByName("CameraNode").getComponent("cc.Camera")
  1090. }
  1091. if (cc.find("CameraNode") != null) {
  1092. CameraNode = cc.find("CameraNode").getComponent("cc.Camera");
  1093. }
  1094. if (cc.find("javetemp_Hero") != null) {
  1095. if (cc.find("javetemp_Hero").getChildByName("CameraNode") != null) {
  1096. javetemp_Hero = cc.find("javetemp_Hero").getChildByName("CameraNode").getComponent("cc.Camera");
  1097. }
  1098. }
  1099. cc.log('node name ',node.name,"现在检查","Hero",Hero,"CameraNode",CameraNode,"javetemp_Hero",javetemp_Hero);
  1100. if (Hero != null) {
  1101. var Camera = cc.find("Hero").getChildByName("CameraNode").getComponent("cc.Camera");
  1102. Camera.addTarget(node);
  1103. cc.log('11111****');
  1104. }
  1105. else if (CameraNode != null) {
  1106. var Camera = cc.find("CameraNode").getComponent("cc.Camera");
  1107. Camera.addTarget(node);
  1108. cc.log('22222****');
  1109. }
  1110. else if (javetemp_Hero != null) {
  1111. var Camera = cc.find("javetemp_Hero").getChildByName("CameraNode").getComponent("cc.Camera");
  1112. Camera.addTarget(node);
  1113. cc.log('33333****');
  1114. }
  1115. },
  1116. //发送帧同步
  1117. sendFrameDatas: function (data) {
  1118. var Rivel = cc.find("Rivel");
  1119. var Hero = cc.find("Hero");
  1120. var NetworkSocket = Hero.getComponent('NetworkSocket');
  1121. if (!cc.find('Canvas').getComponent('GameStates').bServer) {
  1122. data.PlayerStates = 'Server';
  1123. }
  1124. if (cc.find('Canvas').getComponent('GameStates').bServer) {
  1125. data.PlayerStates = 'Client';
  1126. }
  1127. NetworkSocket.sendFrameData(JSON.stringify(data));
  1128. }
  1129. });