dadishu.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. var ObjectPool = require("ObjectPool");
  2. window.app = {
  3. dadishu: null,
  4. myDishuPool: null,
  5. hisDishuPool: null,
  6. Camera: null,
  7. // removeAlldishu : function (index) {
  8. // // this.myDishuPool = [null,null,null]
  9. // this.dadishu.waitTime()
  10. // for (var i = 0; i < this.myDishuPool.length; i++) {
  11. // if (this.myDishuPool[i] != null) {
  12. // if (i != index) {
  13. // ObjectPools.地鼠回收(this.myDishuPool[i].node);
  14. // }
  15. //
  16. // // Log.info("地鼠盒子里面的数据是",this.myDishuPool[i])
  17. // }
  18. // }
  19. // // setTimeout(function () {
  20. // // ObjectPools.地鼠回收(this.myDishuPool[index].node);
  21. // // }.bind(this),1000)
  22. //
  23. // },
  24. // baozha(){
  25. // Log.info("爆炸")
  26. // }
  27. }
  28. window.CameraManager = {
  29. startAnimation() {
  30. app.Camera.getComponent(cc.Animation).play();
  31. }
  32. }
  33. window.dishuManager = {
  34. confs: [
  35. {
  36. top: {
  37. time: 0.2,
  38. timeScale: 3
  39. },
  40. mid: {
  41. time: 2.6,
  42. timeScale: 1
  43. },
  44. lower: {
  45. time: 0.1,
  46. timeScale: 3
  47. },
  48. },
  49. {
  50. top: {
  51. time: 0.2,
  52. timeScale: 3
  53. },
  54. mid: {
  55. time: 2,
  56. timeScale: 1
  57. },
  58. lower: {
  59. time: 0.1,
  60. timeScale: 3
  61. }
  62. },
  63. {
  64. top: {
  65. time: 0.2,
  66. timeScale: 3
  67. },
  68. mid: {
  69. time: 1.8,
  70. timeScale: 1
  71. },
  72. lower: {
  73. time: 0.1,
  74. timeScale: 3
  75. }
  76. },
  77. ],
  78. scheduleTimes : [2,1.25,1.25],
  79. num: 0,
  80. //奖励分数
  81. rewardScore : 10,
  82. setConf: function (num) {
  83. this.num = num;
  84. return this.confs[this.num];
  85. },
  86. getConf: function () {
  87. return this.confs[this.num];
  88. },
  89. setScheduleTimes: function (num) {
  90. this.num = num;
  91. return this.scheduleTimes[this.num];
  92. },
  93. getScheduleTimes: function () {
  94. // Log.info("到底是什么",this.num,this.scheduleTimes)
  95. return this.scheduleTimes[this.num];
  96. },
  97. }
  98. cc.Class({
  99. extends: cc.Component,
  100. properties: {
  101. 我方: cc.Node,
  102. 敌方: cc.Node,
  103. head1: cc.Node,
  104. head2: cc.Node,
  105. 对象池: {
  106. default: null,
  107. type: ObjectPool
  108. },
  109. 敌方血条: cc.Node,
  110. 我方血条: cc.Node,
  111. 倒计时: cc.Label,
  112. 敌方分数: cc.Label,
  113. 我方分数: cc.Label,
  114. 连击动画: cc.Node,
  115. 拳套: cc.Node,
  116. 拳套蓝: cc.Node,
  117. 计时标志: false,
  118. 爆笑音效: cc.Node,
  119. toch: cc.Node,
  120. },
  121. clickstart: function () {
  122. Games = this;
  123. this.glovesDragon = this.拳套.getComponent(dragonBones.ArmatureDisplay);
  124. this.glovesDragonlan = this.拳套蓝.getComponent(dragonBones.ArmatureDisplay);
  125. console.log(this.时分(parseInt(MySetting.match_time)));
  126. this.初始化();
  127. },
  128. clickpause: function () {
  129. cc.director.pause()
  130. // this.getComponent("dialog").setShow(1);
  131. // console.log("对话框" + this.getComponent("dialog"));
  132. },
  133. clickrestart: function () {
  134. cc.director.resume();
  135. // this.getComponent("dialog").setShow(0);
  136. },
  137. clickgameoverrestart: function () {
  138. utils.isMobile(function () {
  139. manager_android_js.gamestatus = 1;
  140. }.bind(this));
  141. // this.重新开始();
  142. if (this.restartCallBack != null) {
  143. this.restartCallBack();
  144. }
  145. },
  146. restartCallBack: function () {
  147. },
  148. setRestartCallBack: function (restartCallBack) {
  149. this.restartCallBack = restartCallBack;
  150. },
  151. //删除所有的地鼠
  152. removeAlldishu : function (index) {
  153. // this.myDishuPool = [null,null,null]
  154. app.dadishu.waitTime()
  155. for (var i = 0; i < app.myDishuPool.length; i++) {
  156. if (app.myDishuPool[i] != null) {
  157. if (i != index) {
  158. ObjectPools.地鼠回收(app.myDishuPool[i].node);
  159. }
  160. // Log.info("地鼠盒子里面的数据是",this.myDishuPool[i])
  161. }
  162. }
  163. // setTimeout(function () {
  164. // ObjectPools.地鼠回收(this.myDishuPool[index].node);
  165. // }.bind(this),1000)
  166. },
  167. onLoad() {
  168. this.dishuPool = new cc.NodePool();
  169. app.Camera = cc.find("Canvas/Main Camera");
  170. // console.log("当前摄像机",app.Camera);
  171. app.dadishu = this;
  172. app.myDishuPool = [null, null, null];
  173. utils.isMobile(function () {
  174. manager_android_js.dishunameger = this;
  175. this.toch.active = false;
  176. }.bind(this));
  177. // manager_android_js.myPlayerInfo = PlayerInfo;
  178. // console.log("人员信息 设置",PlayerInfo);
  179. // console.log("人员信息 查看",manager_android_js.myPlayerInfo);
  180. //如果是第一次就去 开启新手教学
  181. if (PlayerInfo.Left.isfirst == true) {
  182. this.getComponent("new").init();
  183. this.getComponent("new").setProcessCallback(function () {
  184. this.getComponent("ready").init();
  185. }.bind(this))
  186. } else {
  187. this.getComponent("ready").init();
  188. }
  189. // 设置头像
  190. this.setHead();
  191. MySetting.share = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3078873712,1340878922&fm=26&gp=0.jpg";
  192. // this.gameovers = this.node.getComponent("gameovers");
  193. //
  194. // this.结束界面 = this.gameovers;
  195. this.life = 1 / MySetting.life_value;
  196. console.log("每次扣血", this.life, "总血量", MySetting.life_value);
  197. // this.结束界面.hide();
  198. // this.结束界面.active = true;
  199. //
  200. // var data = {
  201. // fen1: this.我方分数.string,
  202. // fen2: this.敌方分数.string,
  203. //
  204. // type: 0
  205. //
  206. // }
  207. // this.gameovers.setDatas(data);
  208. // console.log("都有啥", this.gameovers);
  209. this.Countdown = UtilsNode.getNode("Countdown",this.node);
  210. this.Countdownc = this.Countdown.getComponent("Countdown");
  211. },
  212. setHead: function () {
  213. PlayerInfo.Left.head = utils.getNewHttpImage(PlayerInfo.Left.head);
  214. Log.info("现在头像是",PlayerInfo.Left.head)
  215. this.loadImg(this.head1, PlayerInfo.Left.head, 90, 90);
  216. // this.loadImg(this.head2, PlayerInfo.Right.head, 90, 90);
  217. },
  218. loadImg: function (container, url, w, h) {
  219. // console.log("现在进来的是什么",container,url);
  220. //
  221. // return;
  222. cc.loader.load(url, function (err, texture) {
  223. var sprite = new cc.SpriteFrame(texture);
  224. container.getComponent(cc.Sprite).spriteFrame = sprite;
  225. if (w != null) {
  226. container.width = w;
  227. }
  228. if (h != null) {
  229. container.height = h;
  230. }
  231. });
  232. },
  233. countDownTime: function () {
  234. //播放开始动画
  235. // console.log("播放开始倒计时");
  236. this.callbackcountDownTime = function () {
  237. this.clickstart();
  238. utils.isMobile(function () {
  239. manager_android_js.gamestatus = 1;
  240. }.bind(this));
  241. }
  242. this.scheduleOnce(this.callbackcountDownTime, 0.1);
  243. },
  244. 初始化() {
  245. this.gameTag = true;
  246. GameData.gameStartTime = new Date().getTime()
  247. utils.isMobile(function () {
  248. manager_android_js.gamestatus = 1;
  249. }.bind(this));
  250. Statistics.restStart();
  251. this.startAudioSource();
  252. tip = null
  253. this.敌方血条.getComponent(cc.ProgressBar).progress = 1;
  254. this.我方血条.getComponent(cc.ProgressBar).progress = 1;
  255. this.倒计 = parseInt(MySetting.match_time);
  256. this.计时标志 = true;
  257. this.敌方分数.string = 0;
  258. this.我方分数.string = 0;
  259. ObjectPools._init();
  260. this.Countdownc.setTimeInit(this.倒计);
  261. app.myDishuPool = [];
  262. for (var i = 0; i < this.我方.children.length; i++) {
  263. app.myDishuPool[i] = null
  264. }
  265. app.hisDishuPool = [];
  266. for (var i = 0; i < this.敌方.children.length; i++) {
  267. app.hisDishuPool[i] = null
  268. }
  269. // this.unschedule(this.callback);
  270. this.startLoop();
  271. Log.info("正常打地鼠")
  272. this.Countdownc.setTimeEndCallBack(function () {
  273. console.log("时间到",this.倒计);
  274. // this.倒计 = 0;
  275. this.倒计时结束();
  276. }.bind(this));
  277. this.Countdownc.setTimeUpdateCallBack(function (time) {
  278. this.倒计 = time;
  279. // console.log("倒计时",Math.floor(parseInt(time)));
  280. }.bind(this));
  281. },
  282. //根据时间的不同 上中下速度 的变更
  283. checkTime: function () {
  284. let time = 0;
  285. if (this.倒计 <= MySetting.match_time && this.倒计 > MySetting.time[0]) {
  286. } else if (this.倒计 <= MySetting.time[0] && this.倒计 > MySetting.time[1]) {
  287. time = 1;
  288. } else if (this.倒计 <= MySetting.time[1]) {
  289. time = 2;
  290. }
  291. return time;
  292. },
  293. endLoop: function () {
  294. },
  295. startLoop: function () {
  296. this.count = dishuManager.getScheduleTimes();
  297. // this.unschedule(this.callback);
  298. // console.log("现在我方 地鼠盒子", app.myDishuPool);
  299. // Log.info("什么问题",this.count)
  300. this.currld = new Date().getTime();
  301. this.callback = function () {
  302. if (this.count != dishuManager.getScheduleTimes()) {
  303. // 在第六次执行回调时取消这个计时器
  304. this.count = dishuManager.getScheduleTimes();
  305. this.unschedule(this.callback);
  306. this.startLoop();
  307. return;
  308. }
  309. // let time = new Date().getTime();
  310. // // console.log("相差时间 ",time-this.currld);
  311. // this.currld = time;
  312. this.doSomething();
  313. // this.startLoop();
  314. // this.count++;
  315. }
  316. this.schedule(this.callback, dishuManager.getScheduleTimes());
  317. },
  318. waitTime (){
  319. this.unschedule(this.callback);
  320. setTimeout(function () {
  321. if (this.gameTag) {
  322. this.startLoop();
  323. }
  324. }.bind(this),3000)
  325. },
  326. doSomething: function () {
  327. this.随机生成(this.我方,app.myDishuPool);
  328. // this.随机生成(this.敌方,app.hisDishuPool);
  329. // Log.info("现在生成地鼠",this.倒计,this.checkTime())
  330. },
  331. //开启声音
  332. startAudioSource: function () {
  333. this.getComponent(cc.AudioSource).volume = MySetting.sound_value;
  334. this.getComponent(cc.AudioSource).play();
  335. },
  336. setAudioSource: function () {
  337. this.getComponent(cc.AudioSource).volume = MySetting.sound_value;
  338. if (MySetting.sound_value == 0) {
  339. cc.audioEngine.stopAll();
  340. }
  341. },
  342. start() {
  343. },
  344. setScore : function(player,score){
  345. if (player == 0) {
  346. this.我方分数.string = score;
  347. this.我方分数.getComponent(cc.Animation).play();
  348. }else {
  349. this.敌方分数.string = score;
  350. }
  351. },
  352. // 掉血(父级, 血量) {
  353. //
  354. // utils.isMobile(function () {
  355. // if (manager_android_js.gamestatus == 3) {
  356. // return;
  357. // }
  358. // }.bind(this));
  359. //
  360. //
  361. // console.log("哪一方", 父级.name, "血量", 血量, "");
  362. // if (父级.name == this.我方.name) {
  363. // // 炸弹爆炸时分数不加
  364. // if (血量 == 0) {
  365. //
  366. //
  367. // var 当前血量 = this.敌方血条.getComponent(cc.ProgressBar).progress;
  368. // 当前血量 -= 1 * this.life;
  369. // // 当前血量 = 当前血量.toFixed(1);
  370. // this.敌方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  371. // console.log("点到炸弹_", 父级.name, "当前血量_", 当前血量);
  372. // if (当前血量 <= 0.009) {
  373. // 当前血量 = 0;
  374. // this.敌方血条.getComponent(cc.ProgressBar).progress = 0;
  375. // this.游戏成功();
  376. //
  377. // }
  378. // return;
  379. // }
  380. // var 分数 = parseInt(this.我方分数.string);
  381. // 分数++;
  382. // this.我方分数.string = 分数.toString();
  383. //
  384. // var 当前血量 = this.敌方血条.getComponent(cc.ProgressBar).progress;
  385. // 当前血量 -= 血量 * this.life;
  386. // // 当前血量 = 当前血量.toFixed(1);
  387. // console.log("点到地鼠_", 父级.name, "当前血量_", 当前血量);
  388. // if (当前血量 <= 0.009) {
  389. // 当前血量 = 0;
  390. // this.敌方血条.getComponent(cc.ProgressBar).progress = 0;
  391. // this.游戏成功();
  392. // return;
  393. // }
  394. // this.敌方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  395. //
  396. //
  397. // } else {
  398. // // 炸弹爆炸时分数不加
  399. // if (血量 == 0) {
  400. //
  401. // var 当前血量 = this.我方血条.getComponent(cc.ProgressBar).progress;
  402. // 当前血量 -= 1 * this.life;
  403. // // 当前血量 = 当前血量.toFixed(1);
  404. // this.我方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  405. //
  406. // console.log("点到炸弹_", 父级.name, "当前血量_", 当前血量);
  407. // if (当前血量 <= 0.009) {
  408. // 当前血量 = 0;
  409. // this.我方血条.getComponent(cc.ProgressBar).progress = 0;
  410. // this.游戏失败();
  411. //
  412. // }
  413. // return;
  414. //
  415. // }
  416. // var 分数 = parseInt(this.敌方分数.string);
  417. // 分数++;
  418. // this.敌方分数.string = 分数.toString();
  419. //
  420. // var 当前血量 = this.我方血条.getComponent(cc.ProgressBar).progress;
  421. // 当前血量 -= 血量 * this.life;
  422. // // 当前血量 = 当前血量.toFixed(1);
  423. // console.log("点到地鼠_", 父级.name, "当前血量_", 当前血量);
  424. // if (当前血量 <= 0.009) {
  425. // 当前血量 = 0;
  426. // this.我方血条.getComponent(cc.ProgressBar).progress = 0;
  427. // this.游戏失败();
  428. // return;
  429. // }
  430. // this.我方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  431. //
  432. //
  433. // }
  434. // },
  435. 掉血(父级, 血量) {
  436. utils.isMobile(function () {
  437. if (manager_android_js.gamestatus == 3) {
  438. return;
  439. }
  440. }.bind(this));
  441. // console.log("哪一方", 父级.name, "血量", 血量, "");
  442. if (父级.name == this.我方.name) {
  443. // 炸弹爆炸时分数不加
  444. if (血量 == 0) {
  445. // this.Effect = cc.find("Effect");
  446. // this.Effect.getComponent("Effect").setShow();
  447. // CameraManager.startAnimation();
  448. // var 当前血量 = this.我方血条.getComponent(cc.ProgressBar).progress;
  449. // 当前血量 -= 1 * this.life;
  450. // // 当前血量 = 当前血量.toFixed(1);
  451. // this.我方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  452. //
  453. // console.log("点到炸弹_", 父级.name, "当前血量_", 当前血量);
  454. // if (当前血量 <= 0.009) {
  455. // 当前血量 = 0;
  456. // this.我方血条.getComponent(cc.ProgressBar).progress = 0;
  457. // this.游戏失败();
  458. //
  459. // }
  460. // console.log("地鼠下去了");
  461. // timer.setTime(-10);
  462. return;
  463. }
  464. // var 分数 = parseInt(this.我方分数.string);
  465. // 分数++;
  466. // this.我方分数.string = 分数.toString();
  467. //
  468. // var 当前血量 = this.敌方血条.getComponent(cc.ProgressBar).progress;
  469. // 当前血量 -= 血量 * this.life;
  470. // // 当前血量 = 当前血量.toFixed(1);
  471. // console.log("点到地鼠_", 父级.name, "当前血量_", 当前血量);
  472. // if (当前血量 <= 0.009) {
  473. // 当前血量 = 0;
  474. // this.敌方血条.getComponent(cc.ProgressBar).progress = 0;
  475. // this.游戏成功();
  476. // return;
  477. // }
  478. // this.敌方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  479. } else {
  480. // 炸弹爆炸时分数不加
  481. if (血量 == 0) {
  482. // this.Effect = cc.find("Effect");
  483. // this.Effect.getComponent("Effect").setShow();
  484. // var 当前血量 = this.敌方血条.getComponent(cc.ProgressBar).progress;
  485. // 当前血量 -= 1 * this.life;
  486. // // 当前血量 = 当前血量.toFixed(1);
  487. // this.敌方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  488. // console.log("点到炸弹_", 父级.name, "当前血量_", 当前血量);
  489. // if (当前血量 <= 0.009) {
  490. // 当前血量 = 0;
  491. // this.敌方血条.getComponent(cc.ProgressBar).progress = 0;
  492. // this.游戏成功();
  493. //
  494. // }
  495. // console.log("点到炸弹了");
  496. // CameraManager.startAnimation();
  497. // timer.setTime(-15);
  498. return;
  499. }
  500. // var 分数 = parseInt(this.敌方分数.string);
  501. // 分数++;
  502. // this.敌方分数.string = 分数.toString();
  503. //
  504. // var 当前血量 = this.我方血条.getComponent(cc.ProgressBar).progress;
  505. // 当前血量 -= 血量 * this.life;
  506. // // 当前血量 = 当前血量.toFixed(1);
  507. // console.log("点到地鼠_", 父级.name, "当前血量_", 当前血量);
  508. // if (当前血量 <= 0.009) {
  509. // 当前血量 = 0;
  510. // this.我方血条.getComponent(cc.ProgressBar).progress = 0;
  511. // this.游戏失败();
  512. // return;
  513. // }
  514. // this.我方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  515. }
  516. },
  517. 游戏成功() {
  518. Statistics.playwin = PlayerInfo.Left;
  519. this.游戏结束(0);
  520. },
  521. 游戏失败() {
  522. Statistics.playwin = PlayerInfo.Right;
  523. this.游戏结束(1);
  524. },
  525. 倒计时结束() {
  526. this.unscheduleAllCallbacks();
  527. if (parseInt(this.我方分数.string) > parseInt(this.敌方分数.string)) {
  528. // console.log("胜利");
  529. this.游戏结束(0);
  530. } else if (parseInt(this.我方分数.string) == parseInt(this.敌方分数.string)) {
  531. // console.log("平局");
  532. this.游戏结束(1);
  533. } else {
  534. // console.log("失败");
  535. this.游戏结束(1);
  536. }
  537. },
  538. 游戏结束(type) {
  539. if (this.gameTag) {
  540. this.gameTag = false;
  541. }else{
  542. return;
  543. }
  544. console.log("准备跳转",this.倒计);
  545. Statistics.playtime = MySetting.match_time - this.倒计;
  546. this.unscheduleAllCallbacks();
  547. this.拳套.active = false;
  548. this.拳套蓝.active = false;
  549. // cc.director.pause();
  550. this.getComponent(cc.AudioSource).stop();
  551. cc.audioEngine.stopAll();
  552. this.setAudioSource();
  553. // utils.isMobile(function () {
  554. // if (manager_android_js.gamestatus == 3) {
  555. // return;
  556. // }
  557. // }.bind(this));
  558. // var c = this.结束界面.getChildByName('重新开始');
  559. this.计时标志 = false;
  560. var data = {
  561. fen1: this.我方分数.string,
  562. fen2: this.敌方分数.string,
  563. type: type,
  564. max: Statistics.player1.continuitymax
  565. }
  566. Statistics.player1.score = data.fen1;
  567. // Statistics.player1.score
  568. // console.log("都有啥", this.gameovers);
  569. // this.gameovers.setDatas(data);
  570. // this.glovesDragon.armature().animation.stop();
  571. for (var i = 0; i < this.连击动画.children.length; i++) {
  572. this.连击动画.children[i].active = false;
  573. }
  574. utils.getShareData(function (data) {
  575. UserInfo.args = data;
  576. // console.log("游戏产生数据" + UserInfo.args);
  577. console.log("游戏成绩" + JSON.stringify(UserInfo.args.setResult));
  578. console.log("游戏成绩 最高连击数",Statistics.player1.continuitymax);
  579. console.log("游戏成绩 打死了多少地鼠",Statistics.player1.attackCount);
  580. //
  581. // console.log("游戏数据是" + UserInfo.PlayerGameData);
  582. // console.log("游戏数据是 json" + JSON.stringify(UserInfo));
  583. // console.log("游戏数据是 args" + JSON.stringify(UserInfo.args));
  584. // console.log("假装 获得到的排行榜数据 json" + JSON.stringify(RankingListData));
  585. // utils.isMobile(function () {
  586. // Manager.chengji();
  587. // //真的数据来了 就注释此行
  588. // // this.showRankingList();
  589. // }.bind(this));
  590. // manager_android_js.chengji();
  591. utils.isMobile(function () {
  592. setTimeout(function () {
  593. //给数据到设备
  594. manager_android_js.gameover();
  595. }.bind(this),1000)
  596. }.bind(this));
  597. }.bind(this));
  598. // app.myDishuPool = [null, null, null];
  599. // app.hisDishuPool = [null, null, null];
  600. utils.isWeb(function () {
  601. setTimeout(function () {
  602. utils.toLoadScene("end");
  603. }.bind(this),1000)
  604. }.bind(this));
  605. },
  606. goToEnd : function(){
  607. utils.toLoadScene("end");
  608. },
  609. restgame: function () {
  610. if (this.restartCallBack != null) {
  611. this.restartCallBack();
  612. }
  613. },
  614. 重新开始() {
  615. // cc.director.resume();
  616. GameData.gameStartTime = new Date().getTime()
  617. Games.拳套.active = false;
  618. Games.拳套蓝.active = false;
  619. this.glovesDragon.armature().animation.stop();
  620. this.glovesDragonlan.armature().animation.stop();
  621. // this.glovesDragon.playAnimation("<None>", 1);
  622. for (var i = 0; i < this.我方.children.length; i++) {
  623. var childs = this.我方.children[i].children[0];
  624. if (childs.children.length == 1) {
  625. ObjectPools.地鼠回收(childs.children[0]);
  626. }
  627. }
  628. for (var i = 0; i < this.敌方.children.length; i++) {
  629. var childs = this.敌方.children[i].children[0];
  630. if (childs.children.length == 1) {
  631. ObjectPools.地鼠回收(childs.children[0]);
  632. }
  633. }
  634. // this.初始化();
  635. // this.结束界面.active = false;
  636. // this.结束界面.hide();
  637. },
  638. 随机生成(父级,Pool) {
  639. if (!this.gameTag) {
  640. return;
  641. }
  642. utils.isMobile(function () {
  643. if (manager_android_js.gamestatus == 3) {
  644. return;
  645. }
  646. }.bind(this));
  647. // var flag = false;
  648. // for (var i = 0; i < 父级.children.length; i++) {
  649. // var childs = 父级.children[i].children[0];
  650. // // if (父级.name == this.我方.name) {
  651. // // console.log("现在有多少炸弹和地鼠" ,childs.children);
  652. // // }
  653. // if (childs.children.length == 0) {
  654. // flag = true;
  655. // }
  656. // }
  657. // if (flag == false)
  658. // return;
  659. // var randomIndex = parseInt(Math.random() * 3, 10);
  660. // console.log("现在数字" + randomIndex );
  661. // console.log("假定0" + "左" );
  662. // console.log("假定1" + "中" );
  663. // console.log("假定2" + "右" );
  664. let temp = this.checkDishuPool(Pool);
  665. //现在就返回给 正常的地鼠
  666. let type = this.returnType();
  667. type = 0;
  668. // console.log("现在是什么" , 父级.name ,"判断结果哪个是空的可以上地鼠的",temp , Pool);
  669. if (temp == -1) {
  670. return;
  671. }
  672. // let randomIndex = [0,1];
  673. let dishuType = [0, 1];
  674. var parents = 父级.children[temp].getChildByName("Mask");
  675. var ran = Math.ceil(Math.random() * 100);
  676. var randomShapeIndex = parseInt(Math.random() * 4, 10) + 1;
  677. if (Pool[temp] == null) {
  678. if (ran > 95 && ran < 100) {
  679. var item = this.对象池.生成炸弹();
  680. // Pool[temp] = item.getComponent("zhadan");
  681. item.parent = parents;
  682. // if (parents.children.length == 0) {
  683. //
  684. // } else {
  685. // // this.随机生成(父级);
  686. // return;
  687. // }
  688. item.getComponent("zhadan").init(父级, randomShapeIndex);
  689. item.getComponent("zhadan").initData(temp, type, dishuManager.setConf(this.checkTime()),Pool);
  690. } else {
  691. var item = this.对象池.生成地鼠();
  692. item.parent = parents;
  693. // if (parents.children.length == 0) {
  694. //
  695. // } else {
  696. // // this.随机生成(父级);
  697. // return;
  698. // }
  699. // console.log("给的什么","状态数组", i,"状态",dishuType[i]);
  700. item.getComponent("dishu").init(父级, randomShapeIndex);
  701. item.getComponent("dishu").initData(temp, type, dishuManager.setConf(this.checkTime()),Pool);
  702. if (testUI) {
  703. testUI.showDishu(temp,true);
  704. }
  705. // console.log("对象池有什么", this.对象池.getDishuPool());
  706. // Log.info("父类是谁",parents)
  707. }
  708. }
  709. // for (var i = 0; i <randomIndex.length ; i++) {
  710. //
  711. //
  712. //
  713. // }
  714. },
  715. //检查 现在 地鼠池 可以出生的地鼠的位置
  716. checkDishuPool: function (pools) {
  717. let arr = [];
  718. for (var i = 0; i < pools.length; i++) {
  719. if (pools[i] == null) {
  720. arr.push(i);
  721. }
  722. }
  723. let returnNum = -1;
  724. if (arr.length > 1) {
  725. returnNum = UtilsNode.getRandom(4, null, null, arr);
  726. } else if (arr.length == 1) {
  727. returnNum = arr[0]
  728. }
  729. return returnNum;
  730. },
  731. //检查 现在 地鼠池 可以出生的地鼠的位置
  732. returnType: function () {
  733. //0是正常的地鼠 1 是干扰的地鼠
  734. let returnNum = 0;
  735. // returnNum = UtilsNode.getRandom(0, 0, 2);
  736. // console.log("现在给", returnNum);
  737. let ran = Math.ceil(Math.random() * 100);
  738. if (ran > 30 && ran < 100) {
  739. }else{
  740. returnNum = 1;
  741. }
  742. return returnNum;
  743. },
  744. checkTouch: function (target, location) {
  745. let node = target;
  746. let pointInNode = node.convertToNodeSpaceAR(location);
  747. let i, j, c = false;
  748. if (!target.getComponent(cc.PolygonCollider))
  749. return;
  750. let nvert = target.getComponent(cc.PolygonCollider).points.length;
  751. let testx = pointInNode.x;
  752. let testy = pointInNode.y;
  753. let vert = target.getComponent(cc.PolygonCollider).points;
  754. for (i = 0, j = nvert - 1; i < nvert; j = i++) {
  755. if (((vert[i].y > testy) != (vert[j].y > testy)) &&
  756. (testx < (vert[j].x - vert[i].x) * (testy - vert[i].y) / (vert[j].y - vert[i].y) + vert[i].x))
  757. c = !c;
  758. }
  759. return c;
  760. },
  761. // 输出03:05:59 时分秒
  762. 时分(result) {
  763. var h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
  764. var m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
  765. var s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
  766. //return result = h + ":" + m + ":" + s;
  767. return result = m + ":" + s;
  768. },
  769. 连击播放(p, obj, str) {
  770. for (var i = 0; i < obj.children.length; i++) {
  771. var exp = obj.children[i];
  772. var labelstr = exp.getChildByName("New Label").getComponent(cc.Label);
  773. labelstr.string = str;
  774. if (exp.active == false) {
  775. exp.position = p;
  776. exp.active = true;
  777. break;
  778. }
  779. }
  780. },
  781. update(dt) {
  782. // if (this.计时标志) {
  783. // if (this.倒计 <= 0) {
  784. // this.倒计时结束();
  785. // this.计时标志 = false;
  786. // }
  787. // this.倒计 -= dt;
  788. // var 时间 = this.时分(this.倒计);
  789. // this.倒计时.string = 时间.toString();
  790. // }
  791. },
  792. 设置() {
  793. this.爆笑音效.active = true;
  794. cc.director.pause();
  795. },
  796. });