| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- cc.Class({
- extends: cc.Component,
- properties: {
- touchFlag: false,
- },
- 添加事件() {
- if (this._isEnemy) {
- } else {
- this.node.on(cc.Node.EventType.TOUCH_START, function () {
- if (!this.canClick)
- return;
- this.爆炸();
- }, this);
- Games.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
- if (!this.canClick)
- return;
- if (Games.checkTouch(this.node, event.getLocation())) {
- if (this.touchFlag == false) {
- this.lastPos = event.getLocation();
- this.touchFlag = true;
- }
- } else {
- if (this.touchFlag == true) {
- this.currentPos = event.getLocation();
- this.方向判断();
- }
- }
- }, this);
- }
- },
- init(parents, randomIndex) {
- this.父级 = parents;
- if (this.父级.name == "敌方父级") {
- this._isEnemy = true;
- }
- this.添加事件();
- this.reduceBloodCount = 5;
- this.目标父级 = Games.敌方;
- this.node.position = new cc.Vec2(0, -290);
- this.canClick = true;
- this.伸头();
- },
- 爆炸() {
- if (!this.canClick)
- return;
- this.canClick = false;
- ObjectPools.playSimpleAudioEngine(6);
- this.scheduleOnce(function () {
- Games.掉血(this.目标父级, this.reduceBloodCount);
- ObjectPools.炸弹回收(this.node);
- Games.随机生成(this.父级);
- }, 0.2)
- },
- 方向判断() {
- var valuex = this.currentPos.x - this.lastPos.x;
- if (Math.abs(valuex) < 5)
- return;
- this.touchFlag = false;
- this.爆炸();
- },
- 伸头() {
- var self = this;
- this.伸头动作 = cc.moveBy(0.2, cc.p(0, 160));
- this.node.runAction(this.伸头动作);
- this.scheduleOnce(function () {
- if (this.canClick) {
- this.canClick = false;
- this.unscheduleAllCallbacks();
- var finished = cc.callFunc(function () {
- self.node.stopAllActions();
- ObjectPools.炸弹回收(self.node);
- Games.随机生成(self.父级);
- });
- this.缩头动作 = cc.sequence(cc.moveBy(0.2, cc.p(0, -160)), finished);
- this.node.runAction(this.缩头动作);
- }
- }, 2);
- },
- });
|