LevelControl.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. PlayerDistance: 0,
  5. LastLoadedLvIndex: 0,
  6. TargetNum: 720 * 2,
  7. BgPrefabArray: [],
  8. AllBgPrefabArray: [],
  9. BAllSceneLoaded: false,
  10. PlayerInTheZone: 'None',
  11. PrePlayerInLvIndex: 0,
  12. CurrentPlayerInLvIndex: 0,
  13. FrontEnableLvIndex: 0,
  14. HasTiped: false,
  15. HasGetTipPositionX: false,
  16. TipLocationX: -1,
  17. SprintStartLinePositionX: 0,
  18. LongJumpStartLinePositionX: 0,
  19. HurdleStartLinePositionX: 0,
  20. JavelinStartLinePositionX: 0,
  21. RideBikeStartLinePositionX: 0,
  22. //起点 todo
  23. SprintStartLine: {//短跑起点
  24. default: null,
  25. type: cc.Prefab
  26. },
  27. LongJumpStartLine: {//跳远起点
  28. default: null,
  29. type: cc.Prefab
  30. },
  31. HurdleStartLine: {//跨栏起点
  32. default: null,
  33. type: cc.Prefab
  34. },
  35. JavelinStartLine: {//标枪起点
  36. default: null,
  37. type: cc.Prefab
  38. },
  39. BikeStartLine: {//骑车起点
  40. default: null,
  41. type: cc.Prefab
  42. },
  43. //终点 todo
  44. FinishLine_Sprint: {//短跑终点线
  45. default: null,
  46. type: cc.Prefab
  47. },
  48. LongJumpFinishLine: {//跳远终点
  49. default: null,
  50. type: cc.Prefab
  51. },
  52. FinishLine_Hurdle: {//跨栏终点
  53. default: null,
  54. type: cc.Prefab
  55. },
  56. JavelinFinishLine: {//标枪终点线
  57. default: null,
  58. type: cc.Prefab
  59. },
  60. // BikeFinishLine
  61. FinishLine_Bike: {//骑车终点
  62. default: null,
  63. type: cc.Prefab
  64. },
  65. // Hero: {
  66. // default: null,
  67. // type: cc.Node
  68. // },
  69. Canvas: {
  70. default: null,
  71. type: cc.Node
  72. },
  73. Blank: {//空白
  74. default: null,
  75. type: cc.Prefab
  76. },
  77. AccelerationBand30InTheMiddle: {//大加居中
  78. default: null,
  79. type: cc.Prefab
  80. },
  81. Cushion30AndRailingInTheMiddle: {//大缓跨栏居中
  82. default: null,
  83. type: cc.Prefab
  84. },
  85. JavelinModel: {//标枪模型
  86. default: null,
  87. type: cc.Prefab
  88. },
  89. LongAccelerationBand10ColumnTheLeftHalf1: {//长10加前半部分
  90. default: null,
  91. type: cc.Prefab
  92. },
  93. LongAccelerationBand10ColumnTheRightHalf2: {//长10加后半部分
  94. default: null,
  95. type: cc.Prefab
  96. },
  97. JavelinDistanceFirst: {//标枪计距带起点
  98. default: null,
  99. type: cc.Prefab
  100. },
  101. JavelinDistanceMiddle: {//标枪计距带中部10M-100M
  102. default: null,
  103. type: cc.Prefab
  104. },
  105. JavelinDistanceLast: {//标枪计距带尾部110M
  106. default: null,
  107. type: cc.Prefab
  108. },
  109. Cushion30AndBunker1M: {//沙坑1M
  110. default: null,
  111. type: cc.Prefab
  112. },
  113. Bunker2to4M: {//沙坑2-4M
  114. default: null,
  115. type: cc.Prefab
  116. },
  117. Bunker5to7M: {//沙坑5-7M
  118. default: null,
  119. type: cc.Prefab
  120. },
  121. Bunker8to10M: {//沙坑8-10M
  122. default: null,
  123. type: cc.Prefab
  124. },
  125. Bunker11M: {//沙坑11M
  126. default: null,
  127. type: cc.Prefab
  128. },
  129. BikeModelToTheRight: {//自行车模型
  130. default: null,
  131. type: cc.Prefab
  132. },
  133. TwoAcceleration30s: {//两个大加1
  134. default: null,
  135. type: cc.Prefab
  136. },
  137. Acceleration30AndAcceleration20: {//两个大加2
  138. default: null,
  139. type: cc.Prefab
  140. },
  141. Acceleration20ToTheLeft: {//一个大加靠左
  142. default: null,
  143. type: cc.Prefab
  144. },
  145. LongAccelerationBand7Column: {//长7加1
  146. default: null,
  147. type: cc.Prefab
  148. },
  149. LongAccelerationBand10ColumnTheLeftHalf3: {//长10带边框1左半部分
  150. default: null,
  151. type: cc.Prefab
  152. },
  153. LongAccelerationBand10ColumnTheRightHalf4: {//长10带边框1右半部分
  154. default: null,
  155. type: cc.Prefab
  156. },
  157. LongAccelerationBand10ColumnTheLeftHalf5: {//长10带边框2左大半部分
  158. default: null,
  159. type: cc.Prefab
  160. },
  161. LongAccelerationBand10ColumnTheRightHalfAndLeftHalf6: {//长10带边框2右半部分及长10带边框3左小半部分
  162. default: null,
  163. type: cc.Prefab
  164. },
  165. LongAccelerationBand10ColumnTheRightHalf7: {//长10带边框3右半部分
  166. default: null,
  167. type: cc.Prefab
  168. },
  169. LongAccelerationBand10ColumnTheLeftHalf8: {//长10带边框4左半部分
  170. default: null,
  171. type: cc.Prefab
  172. },
  173. LongAccelerationBand10ColumnTheRightHalf9: {//长10带边框4右半部分
  174. default: null,
  175. type: cc.Prefab
  176. },
  177. AccelerationBand20InTheMiddle: {//中加居中
  178. default: null,
  179. type: cc.Prefab
  180. },
  181. AccelerationBand10InTheMiddle: {//小加居中
  182. default: null,
  183. type: cc.Prefab
  184. },
  185. JumpDownBike: {//下自行车
  186. default: null,
  187. type: cc.Prefab
  188. },
  189. JavelinBeginJump: {//标枪起跳
  190. default: null,
  191. type: cc.Prefab
  192. },
  193. LocationLine: {
  194. default: null,
  195. type: cc.Prefab
  196. },
  197. YellowBG: {
  198. default: null,
  199. type: cc.Prefab
  200. },
  201. wriggle_prefab: {
  202. default: null,
  203. type: cc.Prefab
  204. },
  205. javeBg_prefab: {
  206. default: null,
  207. type: cc.Prefab
  208. },
  209. JavalinDistance: 0,
  210. PrefabNumLabel: {
  211. default: null,
  212. type: cc.Prefab
  213. },
  214. PlayerInLvIndexLabel: {
  215. default: null,
  216. type: cc.Prefab
  217. },
  218. _GameUI: null,
  219. _getHero: null,
  220. _getRivel: null,
  221. _getJavetempHero: null,
  222. _getJavetempRivel: null,
  223. },
  224. onLoad: function () {
  225. this._GameUI = cc.find('UIControl').getComponent('GameUI');
  226. this._getHero = cc.find('Hero');
  227. this._getRivel = cc.find('Rivel');
  228. this._getJavetempHero = cc.find('javetemp_Hero');
  229. this._getJavetempRivel = cc.find('javetemp_Rivel');
  230. this.TipLocationX = -1;
  231. this.TargetNum = 720 * 3;
  232. this.JavalinDistance = 10;
  233. this.YellowBGArr = [];
  234. this.arrJavelin = [];
  235. // this.HasTiped = false;
  236. // this.testArr(false);
  237. // var data = {
  238. // gameLv: 0,
  239. // startPositionX: 0
  240. // }
  241. // this.setStart(data);
  242. // this.PreLoad();
  243. // var CameraNode = cc.find("CameraNode");
  244. // var Hero = cc.find("Hero");
  245. // CameraNode.parent = Hero;
  246. // setTimeout(function () {
  247. // this.onKeyDown();
  248. // }.bind(this), 5000);
  249. },
  250. start() {
  251. // this.scheduleOnce(function () {
  252. // 这里的 this 指向 component
  253. this.testArr(false);
  254. var data = {
  255. gameLv: 0,
  256. startPositionX: 0
  257. }
  258. this.setStart(data);
  259. this.PreLoad();
  260. // var CameraNode = cc.find("CameraNode");
  261. // var Hero = cc.find("Hero");
  262. // CameraNode.parent = Hero;
  263. // }, 0);
  264. },
  265. //可以设置 加载几个项目
  266. setStart: function (data) {
  267. // cc.log('就是看下setStart执行几次。。。。。。。。。。。。。');
  268. if (data.gameLv == 1) {
  269. // cc.log('跨栏项目初始化!!!!!!!!!!!!!!');
  270. }
  271. this.HasGetTipPositionX = false;
  272. this.TipLocationX = -1;
  273. this.tempArr = [];
  274. if (data == null) {
  275. } else {
  276. for (var i = 0; i < this.BgPrefabArray.length; i++) {
  277. if (this.BgPrefabArray[0]) {
  278. // this.BgPrefabArray[i].destroy();
  279. this.BgPrefabArray.shift();
  280. }
  281. }
  282. for (var i = 0; i < this.YellowBGArr.length; i++) {
  283. if (this.YellowBGArr[0]) {
  284. // this.YellowBGArr[i].destroy();
  285. this.YellowBGArr.shift();
  286. }
  287. }
  288. setTimeout(function () {
  289. this.delJaveLin();
  290. }.bind(this), 5000);
  291. // for (var i = 0; i < this.AllBgPrefabArray.length; i++) {
  292. // this.AllBgPrefabArray[i].destroy();
  293. // }
  294. // this.BgPrefabArray = [];
  295. // this.AllBgPrefabArray = [];
  296. // cc.log("要比赛的是什么",this.BgPrefabArr[0]);
  297. //
  298. if (data.gameLv == 0) {
  299. this.addPushArr(this.BgPrefabArr[0]);
  300. this.addPushArr(this.BgPrefabArr[1]);
  301. } else if (data.gameLv == 1) {
  302. this.addPushArr(this.BgPrefabArr[2]);
  303. this.addPushArr(this.BgPrefabArr[3]);
  304. } else if (data.gameLv == 2) {
  305. this.addPushArr(this.BgPrefabArr[4]);
  306. }
  307. }
  308. // cc.log("要比赛的是什么 1",this.tempArr);
  309. //
  310. this.AllBgPrefabArray = this.tempArr;
  311. // CustomLog("要比赛的是什么 1", this.AllBgPrefabArray);
  312. // cc.log("要比赛的是什么 2",this.AllBgPrefabArray);
  313. for (var i = 0; i < 4; i++) {
  314. this.LastLoadedLvIndex = i + 1;
  315. var tPrefab = cc.instantiate(this.tempArr[i]);
  316. tPrefab.parent = this.node;
  317. tPrefab.setAnchorPoint(0.5, 0.5);
  318. tPrefab.setLocalZOrder(-i);
  319. tPrefab.setPosition(data.startPositionX + i * (720), 0);
  320. // cc.log('prefab name is '+tPrefab.name+' and X is '+tPrefab.position.x);
  321. // cc.log('name is '+tPrefab.name+' ***************************************for loop');
  322. this.BgPrefabArray.push(tPrefab);
  323. // this.AddIndexLabelToPrefab(i*(720));//此为预制体添加数字标签,正式项目可注释
  324. this.setStartLine(tPrefab);
  325. }
  326. },
  327. addJaveLin: function (javeLin) {
  328. this.arrJavelin.push(javeLin);
  329. },
  330. delJaveLin: function () {
  331. if (this.arrJavelin&&this.arrJavelin.length != 0) {
  332. for (var i = 0; i < this.arrJavelin.length; i++) {
  333. this.arrJavelin[i].destroy();
  334. }
  335. }
  336. },
  337. addPushArr: function (arr) {
  338. for (var i = 0; i < arr.length; i++) {
  339. var node = arr[i];
  340. this.tempArr.push(node);
  341. }
  342. },
  343. testArr: function (b) {
  344. this.BgPrefabArr = [];
  345. //测试在这里修改
  346. if (b) {
  347. this.BgPrefabArr[0] = [
  348. //短跑
  349. this.Blank,//空白
  350. this.SprintStartLine,//短跑起点
  351. // this.AccelerationBand30InTheMiddle,//短跑5个大加
  352. // this.AccelerationBand30InTheMiddle,
  353. // this.AccelerationBand30InTheMiddle,
  354. // this.AccelerationBand30InTheMiddle,
  355. // this.AccelerationBand30InTheMiddle,
  356. this.AccelerationBand20InTheMiddle,//3个中加
  357. this.AccelerationBand20InTheMiddle,
  358. this.AccelerationBand20InTheMiddle,
  359. this.FinishLine_Sprint,//终点线
  360. ];
  361. this.BgPrefabArr[1] = [
  362. // 跳远
  363. this.LongJumpStartLine,//跳远起点
  364. this.AccelerationBand30InTheMiddle,//4个大加
  365. this.AccelerationBand30InTheMiddle,
  366. // this.AccelerationBand30InTheMiddle,
  367. // this.AccelerationBand30InTheMiddle,
  368. // this.AccelerationBand20InTheMiddle,//3个中加
  369. // this.AccelerationBand20InTheMiddle,
  370. // this.AccelerationBand20InTheMiddle,
  371. // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  372. // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  373. // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  374. // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  375. this.Cushion30AndBunker1M,//沙坑1M
  376. this.Bunker2to4M,//沙坑2-4M
  377. this.Bunker5to7M,//沙坑5-7M
  378. this.Bunker8to10M,//沙坑8-10M
  379. this.Bunker11M,//沙坑11M
  380. this.LongJumpFinishLine,//终点线
  381. this.Blank,//空白
  382. ];
  383. this.BgPrefabArr[2] = [
  384. // 跨栏
  385. this.HurdleStartLine,//跨栏起点
  386. this.Blank,//空白
  387. this.AccelerationBand30InTheMiddle,//连续4个大加交替4个大缓跨栏
  388. // this.Cushion30AndRailingInTheMiddle,//连续4个大加交替4个大缓跨栏
  389. // this.Blank,//空白
  390. // this.Blank,//空白
  391. // this.AccelerationBand30InTheMiddle,
  392. // this.Cushion30AndRailingInTheMiddle,
  393. // this.Blank,//空白
  394. // this.AccelerationBand30InTheMiddle,
  395. // this.Cushion30AndRailingInTheMiddle,
  396. // this.Blank,//空白
  397. // this.AccelerationBand30InTheMiddle,
  398. // this.Cushion30AndRailingInTheMiddle,
  399. // this.Blank,//空白
  400. // this.AccelerationBand30InTheMiddle,
  401. this.Cushion30AndRailingInTheMiddle,
  402. this.Blank,//空白
  403. this.FinishLine_Hurdle,//终点线
  404. this.Blank,//空白
  405. ];
  406. this.BgPrefabArr[3] = [
  407. // 标枪
  408. this.JavelinStartLine,//标枪起点
  409. this.JavelinModel,//标枪模型 vvvvv
  410. this.AccelerationBand30InTheMiddle,//4个大加
  411. // this.AccelerationBand30InTheMiddle,
  412. // this.AccelerationBand30InTheMiddle,
  413. // this.AccelerationBand30InTheMiddle,
  414. // this.AccelerationBand20InTheMiddle,//3个中加
  415. // this.AccelerationBand20InTheMiddle,
  416. // this.AccelerationBand20InTheMiddle,
  417. // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  418. // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  419. // this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  420. // this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  421. this.javeBg_prefab,//起跳
  422. this.JavelinDistanceFirst,//标枪距离计算起点
  423. this.JavelinDistanceMiddle,//标枪距离计算中间部分共10个
  424. this.JavelinDistanceMiddle,
  425. this.JavelinDistanceMiddle,
  426. this.JavelinDistanceMiddle,
  427. this.JavelinDistanceMiddle,
  428. this.JavelinDistanceMiddle,
  429. this.JavelinDistanceMiddle,
  430. this.JavelinDistanceMiddle,
  431. this.JavelinDistanceMiddle,
  432. this.JavelinDistanceMiddle,
  433. this.JavelinDistanceLast,//标枪距离计算末尾部分*/
  434. this.JavelinFinishLine,//终点线
  435. this.Blank,//空白
  436. ];
  437. this.BgPrefabArr[4] = [
  438. //骑车
  439. this.BikeStartLine,//骑车起点
  440. this.BikeModelToTheRight,//自行车模型
  441. this.TwoAcceleration30s,//3个大加2个中加
  442. // this.Acceleration30AndAcceleration20,//
  443. // this.Acceleration20ToTheLeft,//
  444. this.LongAccelerationBand7Column,//1个长7
  445. // this.LongAccelerationBand10ColumnTheLeftHalf3,//4个长10
  446. // this.LongAccelerationBand10ColumnTheRightHalf4,//
  447. // this.LongAccelerationBand10ColumnTheLeftHalf5,//
  448. // this.LongAccelerationBand10ColumnTheRightHalfAndLeftHalf6,//
  449. // this.LongAccelerationBand10ColumnTheRightHalf7,//
  450. // this.LongAccelerationBand10ColumnTheLeftHalf8,//
  451. // this.LongAccelerationBand10ColumnTheRightHalf9,//
  452. this.Blank,//
  453. this.FinishLine_Bike,//终点线
  454. this.Blank,//
  455. this.Blank,//
  456. this.Blank,//
  457. ]
  458. } else {
  459. this.BgPrefabArr[0] = [
  460. //短跑
  461. this.Blank,//空白
  462. this.SprintStartLine,//短跑起点
  463. this.AccelerationBand30InTheMiddle,//短跑5个大加
  464. this.AccelerationBand30InTheMiddle,
  465. this.AccelerationBand30InTheMiddle,
  466. this.AccelerationBand30InTheMiddle,
  467. this.AccelerationBand30InTheMiddle,
  468. this.AccelerationBand20InTheMiddle,//3个中加
  469. this.AccelerationBand20InTheMiddle,
  470. this.AccelerationBand20InTheMiddle,
  471. this.FinishLine_Sprint,//终点线
  472. this.Blank,//空白
  473. ];
  474. this.BgPrefabArr[1] = [
  475. // 跳远
  476. this.LongJumpStartLine,//跳远起点
  477. this.AccelerationBand30InTheMiddle,//4个大加
  478. this.AccelerationBand30InTheMiddle,
  479. this.AccelerationBand30InTheMiddle,
  480. this.AccelerationBand30InTheMiddle,
  481. this.AccelerationBand20InTheMiddle,//3个中加
  482. this.AccelerationBand20InTheMiddle,
  483. this.AccelerationBand20InTheMiddle,
  484. this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  485. this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  486. this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  487. this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  488. this.Cushion30AndBunker1M,//沙坑1M
  489. this.Bunker2to4M,//沙坑2-4M
  490. this.Bunker5to7M,//沙坑5-7M
  491. this.Bunker8to10M,//沙坑8-10M
  492. this.Bunker11M,//沙坑11M
  493. this.LongJumpFinishLine,//终点线
  494. this.Blank,//空白
  495. ];
  496. this.BgPrefabArr[2] = [
  497. // 跨栏
  498. this.HurdleStartLine,//跨栏起点
  499. this.Blank,//空白
  500. this.AccelerationBand30InTheMiddle,//连续4个大加交替4个大缓跨栏
  501. this.Cushion30AndRailingInTheMiddle,//连续4个大加交替4个大缓跨栏
  502. this.Blank,//空白
  503. this.Blank,//空白
  504. this.AccelerationBand30InTheMiddle,
  505. this.Cushion30AndRailingInTheMiddle,
  506. this.Blank,//空白
  507. this.AccelerationBand30InTheMiddle,
  508. this.Cushion30AndRailingInTheMiddle,
  509. this.Blank,//空白
  510. this.AccelerationBand30InTheMiddle,
  511. this.Cushion30AndRailingInTheMiddle,
  512. this.Blank,//空白
  513. this.AccelerationBand30InTheMiddle,
  514. this.Cushion30AndRailingInTheMiddle,
  515. this.Blank,//空白
  516. this.FinishLine_Hurdle,//终点线
  517. this.Blank,//空白
  518. ];
  519. this.BgPrefabArr[3] = [
  520. // 标枪
  521. this.JavelinStartLine,//标枪起点
  522. this.JavelinModel,//标枪模型 vvvvv
  523. this.AccelerationBand30InTheMiddle,//4个大加
  524. this.AccelerationBand30InTheMiddle,
  525. this.AccelerationBand30InTheMiddle,
  526. this.AccelerationBand30InTheMiddle,
  527. this.AccelerationBand20InTheMiddle,//3个中加
  528. this.AccelerationBand20InTheMiddle,
  529. this.AccelerationBand20InTheMiddle,
  530. this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  531. this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  532. this.LongAccelerationBand10ColumnTheLeftHalf1,//长10加前半部分
  533. this.LongAccelerationBand10ColumnTheRightHalf2,//长10加后半部分
  534. this.javeBg_prefab,//起跳
  535. this.JavelinDistanceFirst,//标枪距离计算起点
  536. this.JavelinDistanceMiddle,//标枪距离计算中间部分共10个
  537. this.JavelinDistanceMiddle,
  538. this.JavelinDistanceMiddle,
  539. this.JavelinDistanceMiddle,
  540. this.JavelinDistanceMiddle,
  541. this.JavelinDistanceMiddle,
  542. this.JavelinDistanceMiddle,
  543. this.JavelinDistanceMiddle,
  544. this.JavelinDistanceMiddle,
  545. this.JavelinDistanceMiddle,
  546. this.JavelinDistanceLast,//标枪距离计算末尾部分*/
  547. this.JavelinFinishLine,//终点线
  548. this.Blank,//空白
  549. ];
  550. this.BgPrefabArr[4] = [
  551. //骑车
  552. this.BikeStartLine,//骑车起点
  553. this.BikeModelToTheRight,//自行车模型
  554. this.TwoAcceleration30s,//3个大加2个中加
  555. this.Acceleration30AndAcceleration20,//
  556. this.Acceleration20ToTheLeft,//
  557. this.LongAccelerationBand7Column,//1个长7
  558. this.LongAccelerationBand10ColumnTheLeftHalf3,//4个长10
  559. this.LongAccelerationBand10ColumnTheRightHalf4,//
  560. this.LongAccelerationBand10ColumnTheLeftHalf5,//
  561. this.LongAccelerationBand10ColumnTheRightHalfAndLeftHalf6,//
  562. this.LongAccelerationBand10ColumnTheRightHalf7,//
  563. this.LongAccelerationBand10ColumnTheLeftHalf8,//
  564. this.LongAccelerationBand10ColumnTheRightHalf9,//
  565. this.Blank,//
  566. this.FinishLine_Bike,//终点线
  567. this.Blank,//
  568. this.Blank,//
  569. this.Blank,//
  570. ]
  571. }
  572. },
  573. PreLoad: function () {
  574. var aPrefab = cc.instantiate(this.YellowBG);//开始时加载一个长加速带的黄色区域,后面再次加载就不会卡
  575. aPrefab.parent = this.node;
  576. aPrefab.setPosition(-1000, 1000);
  577. aPrefab.destroy();
  578. var aPrefab = cc.instantiate(this._GameUI.UIPKScore);//开始时加载一下PK分数
  579. aPrefab.parent = this.node;
  580. aPrefab.setPosition(-1000, 1000);
  581. aPrefab.destroy();
  582. // CustomLog("我加载了几次");
  583. // var bPrefab = cc.instantiate(this.PlayerInLvIndexLabel);//显示更前面的角色的LevelIndex。防止地图未加载。调试时用,正式版则注释掉
  584. // bPrefab.parent = cc.find('UITop');
  585. // bPrefab.setPosition(360,0);
  586. // this.PlayerInLvIndexLabel = bPrefab;
  587. },
  588. onKeyDown: function (event) {
  589. if (event == null) {
  590. return;
  591. }
  592. switch (event.keyCode) {
  593. case cc.KEY.a:
  594. cc.log('Press a key');
  595. var Hero = cc.find('Hero');
  596. var Rivel = cc.find('Rivel');
  597. var HeroHeroControl = Hero.getComponent("HeroControl");
  598. var RivelHeroControl = Rivel.getComponent("HeroControl");
  599. HeroHeroControl.SetSpeedToZeroAndIdle();
  600. RivelHeroControl.SetSpeedToZeroAndIdle();
  601. HeroHeroControl.javelinTag = false;
  602. RivelHeroControl.javelinTag = false;
  603. Hero.getChildByName('Player').stopAllActions();
  604. Rivel.getChildByName('Player').stopAllActions();
  605. Hero.getChildByName('Player').setPositionY(-132);
  606. Rivel.getChildByName('Player').setPositionY(-37);
  607. break;
  608. }
  609. },
  610. SetDistance: function (aPlayerDistance) {
  611. if (this.PlayerDistance === aPlayerDistance)
  612. return;
  613. this.PlayerDistance = aPlayerDistance;
  614. // console.log('aPlayerDistance =',aPlayerDistance);
  615. },
  616. SetLocationLine: function (PlayerCollisionLinePosition) {
  617. var aPrefab = cc.instantiate(this.LocationLine);
  618. aPrefab.parent = this.node;
  619. aPrefab.setPosition(PlayerCollisionLinePosition);
  620. },
  621. CreateYellowBG: function (PlayerCollisionLinePosition) {
  622. var aPrefab = cc.instantiate(this.YellowBG);
  623. aPrefab.parent = this.node;
  624. this.YellowBGArr.push(aPrefab);
  625. // aPrefab.setAnchorPoint(0.5, 0.5);
  626. aPrefab.setPosition(PlayerCollisionLinePosition);
  627. return aPrefab;
  628. },
  629. displayTimerMiddlePKScore: function (player) {//显示隐藏比分
  630. if (player.name === 'Hero') {
  631. var MyScore = this._getHero.getComponent("PlayerState").TerminalPoint;
  632. var RivalScore = this._getRivel.getComponent("PlayerState").TerminalPoint;
  633. if (MyScore == 0 && RivalScore == 0) {
  634. return;
  635. }
  636. this._GameUI.displayTimerMiddlePKScore(MyScore, RivalScore, 0);
  637. }
  638. },
  639. sortNumber: function (a, b) {
  640. return b - a
  641. },
  642. update: function (dt) {
  643. // cc.log(this.BgPrefabArray);
  644. //var str = '["同意","不同意"]';
  645. //var str2 = "test";
  646. //var str3 = "xixixi";
  647. // var data = { FunctionName: 'PushPlayerToEnterFinishLinePlayersArray' };
  648. // var value = "{\"id\":\""+json[i].id+"\",\"text\":\""+json[i].text+"\"},"
  649. // var value = "{"+str2+":"+str3+"}";
  650. //var value = "{"+str2+":"+str3+"}";
  651. // var test3 = value.parseJSON();
  652. // var test = JSON.stringify(value);
  653. // var test2 = JSON.parse(test.test);
  654. // cc.log(test3);
  655. // cc.log(this.StartLinesPositionXJson.LongJump);
  656. // var str = '0123456StartLine';
  657. // var SubToStrIndex = str.length-9;
  658. // cc.log(str.substring(0,SubToStrIndex));
  659. //cc.log('提示'+this.HasTiped+' 获取位置'+this.HasGetTipPositionX+' 提示位置'+this.TipLocationX+' hero位置'+cc.find('Hero').position.x);
  660. if (this.HasTiped == false) {
  661. if (this.TipLocationX != -1) {
  662. var HeroPositionX = this._getHero.position.x;
  663. if (HeroPositionX >= this.TipLocationX) {
  664. //cc.log('执行了###################');
  665. //cc.log(this.TipLocationX+'****'+HeroPositionX);
  666. this._GameUI.hideTimerTipOfLongAcceleration(3);//长加速带长按提示
  667. this.HasTiped = true;
  668. }
  669. }
  670. }
  671. // cc.log('提示'+this.HasTiped+' 获取位置'+this.HasGetTipPositionX+' 提示位置'+this.TipLocationX+' hero位置'+cc.find('Hero').position.x);
  672. // cc.log(this.TipLocationX + '=前面是提示位置后面是hero位置=' + cc.find('Hero').position.x);
  673. if (this.AllBgPrefabArray.length - 1 == this.LastLoadedLvIndex) return;
  674. var MaxPositionX = 0;
  675. // var MiniPosiitonX = 0;
  676. var HeroPositionX = this._getHero.position.x;//cc.find('Hero').position.x;
  677. var RivelPositionX = this._getRivel.position.x;// cc.find('Rivel').position.x;
  678. var JavalinHero = this._getJavetempHero;//cc.find('javetemp_Hero');
  679. var JavalinHeroPositionX = 0;
  680. var JavalinRivel = this._getJavetempRivel;//cc.find('javetemp_Rivel');
  681. var JavalinRivelPositionX = 0;
  682. var arr = [];
  683. if (JavalinHero != null || JavalinRivel != null) {
  684. if (JavalinHero != null && JavalinRivel != null) {
  685. if (JavalinHero.isTag) {
  686. JavalinHeroPositionX = JavalinHero.position.x;
  687. arr.push(JavalinHeroPositionX);
  688. }
  689. if (JavalinRivel.isTag) {
  690. JavalinRivelPositionX = JavalinRivel.position.x;
  691. arr.push(JavalinRivelPositionX);
  692. }
  693. arr.push(HeroPositionX);
  694. arr.push(RivelPositionX);
  695. }
  696. else if (JavalinHero != null) {
  697. if (JavalinHero.isTag) {
  698. JavalinHeroPositionX = JavalinHero.position.x;
  699. arr.push(JavalinHeroPositionX);
  700. }
  701. arr.push(HeroPositionX);
  702. arr.push(RivelPositionX);
  703. }
  704. else if (JavalinRivel != null) {
  705. if (JavalinRivel.isTag) {
  706. JavalinRivelPositionX = JavalinRivel.position.x;
  707. arr.push(JavalinRivelPositionX);
  708. }
  709. arr.push(HeroPositionX);
  710. arr.push(RivelPositionX);
  711. }
  712. //冒泡排序 HeroPositionX RivelPositionX JavalinHeroPositionX JavalinRivelPositionX
  713. arr.sort(this.sortNumber);
  714. MaxPositionX = arr[0];
  715. // MiniPosiitonX = arr[arr.length - 1];
  716. // CustomLog("现在的数组是","max",MaxPositionX,"min",MiniPosiitonX);
  717. // CustomLog("现在的数组是","arr",arr.length);
  718. }
  719. else {
  720. if (RivelPositionX - HeroPositionX > 0) {
  721. MaxPositionX = RivelPositionX;
  722. // MiniPosiitonX = HeroPositionX;
  723. }
  724. else {
  725. MaxPositionX = HeroPositionX;
  726. // MiniPosiitonX = RivelPositionX;
  727. }
  728. }
  729. var csPositionX = MaxPositionX + 360;
  730. this.CurrentPlayerInLvIndex = Math.floor(csPositionX / 720);
  731. // if(this.PlayerInLvIndexLabel!=null){
  732. // this.PlayerInLvIndexLabel.getChildByName('label').getComponent(cc.Label).string = this.CurrentPlayerInLvIndex;//设置更前面的角色的levelIndex值,调试用。
  733. // }
  734. // cc.log(this.LastLoadedLvIndex-this.CurrentPlayerInLvIndex)
  735. // cc.log('x=',this.CurrentPlayerInLvIndex-this.PrePlayerInLvIndex)
  736. // cc.log("last is "+this.LastLoadedLvIndex+' and currentP is '+this.CurrentPlayerInLvIndex+' and PrePlayer is '+this.PrePlayerInLvIndex);
  737. if (this.LastLoadedLvIndex - this.CurrentPlayerInLvIndex < 2 &&
  738. this.CurrentPlayerInLvIndex != this.PrePlayerInLvIndex) {
  739. //汪汪开图
  740. this.addMap();
  741. // this.LastLoadedLvIndex++;
  742. // // CustomLog("这个对象",this.BgPrefabArray[this.BgPrefabArray.length-1]);
  743. // var LastLvPositionX = this.BgPrefabArray[this.BgPrefabArray.length - 1].position.x;
  744. // var NewLvPositionX = LastLvPositionX + 720;
  745. // CustomLog("新创建出来的 放到什么地方了",NewLvPositionX);
  746. // var tempArr= this.AllBgPrefabArray[this.LastLoadedLvIndex-1];
  747. // CustomLog("不够了",tempArr);
  748. // var tPrefab = cc.instantiate(tempArr);
  749. // // cc.log(this.AllBgPrefabArray[this.LastLoadedLvIndex].name+"======name"+this.LastLoadedLvIndex);
  750. // tPrefab.parent = this.node;
  751. // tPrefab.setAnchorPoint(0.5, 0.5);
  752. // tPrefab.setLocalZOrder(-this.LastLoadedLvIndex);
  753. // tPrefab.setPosition(NewLvPositionX, 0);
  754. // // this.BgPrefabArray.shift().destroy();
  755. // this.BgPrefabArray.push(tPrefab);
  756. // // cc.log(tPrefab.name+"======name");
  757. // if (tPrefab.name == 'JavelinDistanceMiddle') {
  758. // var aLabel = tPrefab.getChildByName("JavelinDistanceNUM");
  759. // var Labelcomp = aLabel.getComponent(cc.Label);
  760. // Labelcomp.string = this.JavalinDistance.toString();
  761. // this.JavalinDistance += 10;
  762. // }
  763. // this.AddIndexLabelToPrefab(NewLvPositionX);//此为预制体添加数字标签,正式项目可注释
  764. }
  765. this.PrePlayerInLvIndex = this.CurrentPlayerInLvIndex;
  766. // var MiniPlayerInIndex = Math.floor(MiniPosiitonX/720);
  767. //
  768. // // CustomLog("现在的数组是 索引",this.FrontEnableLvIndex);
  769. // if(MiniPlayerInIndex-this.FrontEnableLvIndex>2)
  770. // {
  771. // // cc.log('this.FrontEnableLvIndex='+this.FrontEnableLvIndex);
  772. // // this.BgPrefabArray.shift().destroy();
  773. // // CustomLog("删除东西",this.BgPrefabArray[this.FrontEnableLvIndex]);
  774. // this.BgPrefabArray[this.FrontEnableLvIndex].destroy();
  775. //
  776. // // cc.log(this.BgPrefabArray.length);
  777. // this.FrontEnableLvIndex++;
  778. //
  779. //
  780. // }
  781. },
  782. addMap: function () {
  783. var lastIndex = this.AllBgPrefabArray.length - 1 - this.LastLoadedLvIndex;
  784. var tempIndex = 0;
  785. if (lastIndex > 3) {
  786. tempIndex = 3;
  787. } else {
  788. tempIndex = lastIndex;
  789. }
  790. for (var i = 0; i < tempIndex; i++) {
  791. this.LastLoadedLvIndex++;
  792. // cc.log("现在匹配是多少LastLoadedLvIndex",this.LastLoadedLvIndex);
  793. // CustomLog("这个对象",this.BgPrefabArray[this.BgPrefabArray.length-1]);
  794. var LastLvPositionX = this.BgPrefabArray[this.BgPrefabArray.length - 1].position.x;
  795. // cc.log("现在匹配是多少LastLvPositionX",LastLvPositionX);
  796. var NewLvPositionX = LastLvPositionX + 720;
  797. // cc.log("现在匹配是多少NewLvPositionX",NewLvPositionX);
  798. var tPrefab = cc.instantiate(this.AllBgPrefabArray[this.LastLoadedLvIndex]);
  799. // cc.log(this.AllBgPrefabArray[this.LastLoadedLvIndex].name+"======name"+this.LastLoadedLvIndex+'.......'+this.HasTiped);
  800. // cc.log("现在要出来什么",this.CurrentPlayerInLvIndex,i,tPrefab);
  801. tPrefab.parent = this.node;
  802. tPrefab.setAnchorPoint(0.5, 0.5);
  803. tPrefab.setLocalZOrder(-this.LastLoadedLvIndex);
  804. tPrefab.setPosition(NewLvPositionX, 0);
  805. if (this.HasTiped == false) {
  806. if (this.HasGetTipPositionX == false) {
  807. if (tPrefab.name == 'LongAccelerationBand10ColumnTheLeftHalf1') {
  808. var tPrefabX = tPrefab.position.x;
  809. this.TipLocationX = tPrefabX;
  810. //cc.log(this.TipLocationX+'===============');
  811. this.HasGetTipPositionX = true;
  812. }
  813. }
  814. }
  815. var str = tPrefab.name;
  816. if (str.indexOf("StartLine") != -1) {
  817. var SubToStrIndex = str.length - 9;
  818. var StartLineName = str.substring(0, SubToStrIndex);
  819. var StartLinesPositionX = tPrefab.position.x + 720;
  820. this.SetStartLinesPositionX(StartLineName, StartLinesPositionX);
  821. }
  822. // cc.log("现在要出来什么",this.CurrentPlayerInLvIndex,i,tPrefab,NewLvPositionX);
  823. // this.BgPrefabArray.shift().destroy();
  824. this.BgPrefabArray.push(tPrefab);
  825. // cc.log(tPrefab.name+"===========================================================name");
  826. if (tPrefab.name == 'JavelinDistanceMiddle') {
  827. var aLabel = tPrefab.getChildByName("JavelinDistanceNUM");
  828. var Labelcomp = aLabel.getComponent(cc.Label);
  829. Labelcomp.string = this.JavalinDistance.toString();
  830. this.JavalinDistance += 10;
  831. }
  832. // this.AddIndexLabelToPrefab(NewLvPositionX);//此为预制体添加数字标签,正式项目可注释
  833. this.setStartLine(tPrefab);
  834. }
  835. },
  836. SetStartLinesPositionX: function (StartLineName, StartLinesPositionX) {
  837. // cc.log('name is '+StartLineName+' and x is '+StartLinesPositionX);
  838. if ('Sprint' == StartLineName) {
  839. this.SprintStartLinePositionX = StartLinesPositionX;
  840. } else if ('LongJump' == StartLineName) {
  841. this.LongJumpStartLinePositionX = StartLinesPositionX;
  842. } else if ('Hurdle' == StartLineName) {
  843. this.HurdleStartLinePositionX = StartLinesPositionX;
  844. } else if ('Javelin' == StartLineName) {
  845. this.JavelinStartLinePositionX = StartLinesPositionX;
  846. } else if ('RideBike' == StartLineName) {
  847. this.RideBikeStartLinePositionX = StartLinesPositionX;
  848. }
  849. },
  850. AddIndexLabelToPrefab: function (NewLvPositionX) {
  851. /** **/
  852. var PrefabNumLabelInstance = cc.instantiate(this.PrefabNumLabel);
  853. PrefabNumLabelInstance.parent = this.node;
  854. PrefabNumLabelInstance.setAnchorPoint(0, 0.5);
  855. PrefabNumLabelInstance.setLocalZOrder(1000);
  856. PrefabNumLabelInstance.setPosition(NewLvPositionX, 0);
  857. this.BgPrefabArray.push(PrefabNumLabelInstance);
  858. PrefabNumLabelInstance.getChildByName('MyNumLeft').getComponent(cc.Label).string = 'Left ' + this.LastLoadedLvIndex;
  859. PrefabNumLabelInstance.getChildByName('MyNumRight').getComponent(cc.Label).string = 'Right ' + this.LastLoadedLvIndex;
  860. /** **/
  861. },
  862. setP: function (tPrefab) {
  863. if (tPrefab.getChildByName("New Node") != null) {
  864. if (tPrefab.getChildByName("New Node").getComponent(cc.RigidBody) != null) {
  865. // CustomLog("gangti",tPrefab);
  866. tPrefab.getChildByName("New Node").getComponent(cc.RigidBody).syncPosition();
  867. }
  868. }
  869. },
  870. /**
  871. * 这个是设置 每一个 项目开头的 位置的方法
  872. */
  873. setStartLine: function (node) {
  874. switch (node.name) {
  875. case "SprintStartLine":
  876. case "LongJumpStartLine":
  877. case "HurdleStartLine":
  878. case "JavelinStartLine":
  879. case "BikeStartLine":
  880. this.tempStartNode = node;
  881. CustomLog("现在是啥啊", this.tempStartNode.name, node.x);
  882. break;
  883. }
  884. }
  885. });