teaching.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. var ObjectPool = require("ObjectPool");
  2. // Learn cc.Class:
  3. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  4. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  5. // Learn Attribute:
  6. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  7. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  8. // Learn life-cycle callbacks:
  9. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  10. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  11. cc.Class({
  12. extends: cc.Component,
  13. properties: {
  14. 对象池: {
  15. default: null,
  16. type: ObjectPool
  17. },
  18. 拳套: cc.Node,
  19. 拳套蓝: cc.Node,
  20. 我方分数: cc.Label,
  21. },
  22. // LIFE-CYCLE CALLBACKS:
  23. onLoad () {
  24. Games = this;
  25. },
  26. quan(){
  27. this.glovesDragon = this.拳套.getComponent(dragonBones.ArmatureDisplay);
  28. this.glovesDragonlan = this.拳套蓝.getComponent(dragonBones.ArmatureDisplay);
  29. },
  30. start () {
  31. // Log.info("我方都有什么", this.我方);
  32. // this.spotlamps = [
  33. // {
  34. // x : -230,
  35. // y : -72
  36. // },
  37. // {
  38. // x : -18.1,
  39. // y : 192.4
  40. // },
  41. // {
  42. // x : 162,
  43. // y : -63
  44. // }
  45. // ]
  46. ObjectPools._init();
  47. this.我方 = UtilsNode.getNode("我方父级",this.node)
  48. app.myDishuPool = [];
  49. // setTimeout(function () {
  50. // window.spotlamp.setPandShowAll(true,this.spotlamps);
  51. // }.bind(this),500)
  52. // setTimeout(function () {
  53. // window.spotlamp.setPandShowAll(false,this.spotlamps);
  54. // }.bind(this),5000)
  55. // Log.info("应该会掉",this.StartLishen)
  56. if (this.StartLishen) {
  57. this.StartLishen();
  58. }
  59. this.quan();
  60. },
  61. setScore : function(player,score){
  62. if (player == 0) {
  63. this.我方分数.string = score;
  64. this.我方分数.getComponent(cc.Animation).play();
  65. }else {
  66. this.敌方分数.string = score;
  67. }
  68. },
  69. setStartLishen(StartLishen){
  70. this.StartLishen = StartLishen;
  71. },
  72. 随机生成(index,父级,Pool) {
  73. // Log.info("走的是这个吧",index)
  74. // let temp = this.checkDishuPool(Pool);
  75. let temp = index;
  76. //现在就返回给 正常的地鼠
  77. let type = 1;
  78. type = 0;
  79. // console.log("现在是什么" , 父级.name ,"判断结果哪个是空的可以上地鼠的",temp , Pool);
  80. if (temp == -1) {
  81. return;
  82. }
  83. // let randomIndex = [0,1];
  84. let dishuType = [0, 1];
  85. var parents = 父级.children[temp].getChildByName("Mask");
  86. var ran = Math.ceil(Math.random() * 100);
  87. var randomShapeIndex = parseInt(Math.random() * 4, 10) + 1;
  88. if (Pool[temp] == null) {
  89. var item = this.对象池.生成教育地鼠();
  90. item.parent = parents;
  91. // if (parents.children.length == 0) {
  92. //
  93. // } else {
  94. // // this.随机生成(父级);
  95. // return;
  96. // }
  97. // console.log("给的什么","状态数组", i,"状态",dishuType[i]);
  98. item.getComponent("dishu_teaching").init(父级, randomShapeIndex);
  99. item.getComponent("dishu_teaching").initData(temp, type, dishuManager.setConf(0),Pool);
  100. // Log.info("父类是谁",parents)
  101. // if (ran > 95 && ran < 100) {
  102. // var item = this.对象池.生成炸弹();
  103. // // Pool[temp] = item.getComponent("zhadan");
  104. // item.parent = parents;
  105. // // if (parents.children.length == 0) {
  106. // //
  107. // // } else {
  108. // // // this.随机生成(父级);
  109. // // return;
  110. // // }
  111. // item.getComponent("zhadan").init(父级, randomShapeIndex);
  112. // item.getComponent("zhadan").initData(temp, type, dishuManager.setConf(this.checkTime()),Pool);
  113. //
  114. // } else {
  115. //
  116. // var item = this.对象池.生成教育地鼠();
  117. //
  118. // item.parent = parents;
  119. //
  120. // // if (parents.children.length == 0) {
  121. // //
  122. // // } else {
  123. // // // this.随机生成(父级);
  124. // // return;
  125. // // }
  126. // // console.log("给的什么","状态数组", i,"状态",dishuType[i]);
  127. // item.getComponent("dishu").init(父级, randomShapeIndex);
  128. // item.getComponent("dishu").initData(temp, type, dishuManager.setConf(this.checkTime()),Pool);
  129. // // console.log("对象池有什么", this.对象池.getDishuPool());
  130. //
  131. // }
  132. }
  133. // for (var i = 0; i <randomIndex.length ; i++) {
  134. //
  135. //
  136. //
  137. // }
  138. },
  139. 连击播放(p, obj, str) {
  140. for (var i = 0; i < obj.children.length; i++) {
  141. var exp = obj.children[i];
  142. var labelstr = exp.getChildByName("New Label").getComponent(cc.Label);
  143. labelstr.string = str;
  144. if (exp.active == false) {
  145. exp.position = p;
  146. exp.active = true;
  147. break;
  148. }
  149. }
  150. },
  151. 随机生成ZD(index,父级,Pool) {
  152. Log.info("走的是这个吧",index)
  153. // let temp = this.checkDishuPool(Pool);
  154. let temp = index;
  155. //现在就返回给 正常的地鼠
  156. let type = 1;
  157. type = 1;
  158. // console.log("现在是什么" , 父级.name ,"判断结果哪个是空的可以上地鼠的",temp , Pool);
  159. if (temp == -1) {
  160. return;
  161. }
  162. // let randomIndex = [0,1];
  163. let dishuType = [0, 1];
  164. var parents = 父级.children[temp].getChildByName("Mask");
  165. var ran = Math.ceil(Math.random() * 100);
  166. var randomShapeIndex = parseInt(Math.random() * 4, 10) + 1;
  167. if (Pool[temp] == null) {
  168. var item = this.对象池.生成教育炸弹();
  169. // Pool[temp] = item.getComponent("zhadan");
  170. item.parent = parents;
  171. // if (parents.children.length == 0) {
  172. //
  173. // } else {
  174. // // this.随机生成(父级);
  175. // return;
  176. // }
  177. // Log.info("现在是 教育炸弹",item)
  178. item.getComponent("zhadan_teaching").init(父级, randomShapeIndex);
  179. item.getComponent("zhadan_teaching").initData(temp, type, dishuManager.setConf(0),Pool);
  180. }
  181. // for (var i = 0; i <randomIndex.length ; i++) {
  182. //
  183. //
  184. //
  185. // }
  186. },
  187. 掉血(父级, 血量) {
  188. Log.info("死亡掉血")
  189. if (this.BeAttackedLishen) {
  190. this.BeAttackedLishen()
  191. }
  192. tip.tiplayoutc.playOut();
  193. // utils.isMobile(function () {
  194. // if (manager_android_js.gamestatus == 3) {
  195. // return;
  196. // }
  197. // }.bind(this));
  198. //
  199. //
  200. // // console.log("哪一方", 父级.name, "血量", 血量, "");
  201. // if (父级.name == this.我方.name) {
  202. // // 炸弹爆炸时分数不加
  203. // if (血量 == 0) {
  204. //
  205. // // this.Effect = cc.find("Effect");
  206. // // this.Effect.getComponent("Effect").setShow();
  207. // // CameraManager.startAnimation();
  208. // // var 当前血量 = this.我方血条.getComponent(cc.ProgressBar).progress;
  209. // // 当前血量 -= 1 * this.life;
  210. // // // 当前血量 = 当前血量.toFixed(1);
  211. // // this.我方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  212. // //
  213. // // console.log("点到炸弹_", 父级.name, "当前血量_", 当前血量);
  214. // // if (当前血量 <= 0.009) {
  215. // // 当前血量 = 0;
  216. // // this.我方血条.getComponent(cc.ProgressBar).progress = 0;
  217. // // this.游戏失败();
  218. // //
  219. // // }
  220. // // console.log("地鼠下去了");
  221. // // timer.setTime(-10);
  222. // return;
  223. // }
  224. // // var 分数 = parseInt(this.我方分数.string);
  225. // // 分数++;
  226. // // this.我方分数.string = 分数.toString();
  227. // //
  228. // // var 当前血量 = this.敌方血条.getComponent(cc.ProgressBar).progress;
  229. // // 当前血量 -= 血量 * this.life;
  230. // // // 当前血量 = 当前血量.toFixed(1);
  231. // // console.log("点到地鼠_", 父级.name, "当前血量_", 当前血量);
  232. // // if (当前血量 <= 0.009) {
  233. // // 当前血量 = 0;
  234. // // this.敌方血条.getComponent(cc.ProgressBar).progress = 0;
  235. // // this.游戏成功();
  236. // // return;
  237. // // }
  238. // // this.敌方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  239. //
  240. //
  241. // } else {
  242. // // 炸弹爆炸时分数不加
  243. // if (血量 == 0) {
  244. // // this.Effect = cc.find("Effect");
  245. // // this.Effect.getComponent("Effect").setShow();
  246. // // var 当前血量 = this.敌方血条.getComponent(cc.ProgressBar).progress;
  247. // // 当前血量 -= 1 * this.life;
  248. // // // 当前血量 = 当前血量.toFixed(1);
  249. // // this.敌方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  250. // // console.log("点到炸弹_", 父级.name, "当前血量_", 当前血量);
  251. // // if (当前血量 <= 0.009) {
  252. // // 当前血量 = 0;
  253. // // this.敌方血条.getComponent(cc.ProgressBar).progress = 0;
  254. // // this.游戏成功();
  255. // //
  256. // // }
  257. // // console.log("点到炸弹了");
  258. // // CameraManager.startAnimation();
  259. // // timer.setTime(-15);
  260. // return;
  261. //
  262. // }
  263. // // var 分数 = parseInt(this.敌方分数.string);
  264. // // 分数++;
  265. // // this.敌方分数.string = 分数.toString();
  266. // //
  267. // // var 当前血量 = this.我方血条.getComponent(cc.ProgressBar).progress;
  268. // // 当前血量 -= 血量 * this.life;
  269. // // // 当前血量 = 当前血量.toFixed(1);
  270. // // console.log("点到地鼠_", 父级.name, "当前血量_", 当前血量);
  271. // // if (当前血量 <= 0.009) {
  272. // // 当前血量 = 0;
  273. // // this.我方血条.getComponent(cc.ProgressBar).progress = 0;
  274. // // this.游戏失败();
  275. // // return;
  276. // // }
  277. // // this.我方血条.getComponent(cc.ProgressBar).progress = 当前血量;
  278. //
  279. //
  280. // }
  281. },
  282. setBeAttackedLishen(BeAttackedLishen){
  283. this.BeAttackedLishen = BeAttackedLishen;
  284. }
  285. // update (dt) {},
  286. });