zhadan.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. touchFlag: false,
  5. },
  6. 添加事件() {
  7. if (this._isEnemy) {
  8. } else {
  9. this.node.on(cc.Node.EventType.TOUCH_START, function () {
  10. if (!this.canClick)
  11. return;
  12. this.爆炸();
  13. }, this);
  14. Games.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
  15. if (!this.canClick)
  16. return;
  17. if (Games.checkTouch(this.node, event.getLocation())) {
  18. if (this.touchFlag == false) {
  19. this.lastPos = event.getLocation();
  20. this.touchFlag = true;
  21. }
  22. } else {
  23. if (this.touchFlag == true) {
  24. this.currentPos = event.getLocation();
  25. this.方向判断();
  26. }
  27. }
  28. }, this);
  29. }
  30. },
  31. init(parents, randomIndex) {
  32. this.父级 = parents;
  33. if (this.父级.name == "敌方父级") {
  34. this._isEnemy = true;
  35. }
  36. this.添加事件();
  37. this.reduceBloodCount = 5;
  38. this.目标父级 = Games.敌方;
  39. this.node.position = new cc.Vec2(0, -290);
  40. this.canClick = true;
  41. this.伸头();
  42. },
  43. 爆炸() {
  44. if (!this.canClick)
  45. return;
  46. this.canClick = false;
  47. ObjectPools.playSimpleAudioEngine(6);
  48. this.scheduleOnce(function () {
  49. Games.掉血(this.目标父级, this.reduceBloodCount);
  50. ObjectPools.炸弹回收(this.node);
  51. Games.随机生成(this.父级);
  52. }, 0.2)
  53. },
  54. 方向判断() {
  55. var valuex = this.currentPos.x - this.lastPos.x;
  56. if (Math.abs(valuex) < 5)
  57. return;
  58. this.touchFlag = false;
  59. this.爆炸();
  60. },
  61. 伸头() {
  62. var self = this;
  63. this.伸头动作 = cc.moveBy(0.2, cc.p(0, 160));
  64. this.node.runAction(this.伸头动作);
  65. this.scheduleOnce(function () {
  66. if (this.canClick) {
  67. this.canClick = false;
  68. this.unscheduleAllCallbacks();
  69. var finished = cc.callFunc(function () {
  70. self.node.stopAllActions();
  71. ObjectPools.炸弹回收(self.node);
  72. Games.随机生成(self.父级);
  73. });
  74. this.缩头动作 = cc.sequence(cc.moveBy(0.2, cc.p(0, -160)), finished);
  75. this.node.runAction(this.缩头动作);
  76. }
  77. }, 2);
  78. },
  79. });