123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import FSprite from "../object/FSprite";
- import BObject from "./BObject";
- /**
- * 炸弹
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class BBObject extends BObject {
- private isOver = false
- onBeginContact(contact: cc.PhysicsContact, self, other) {
- if(this.isOver){
- return
- }
- if (self.node == this.node) {
- if (other.tag != 0) {
- } else if (other.node.group == 'map') {//撞到地图
- this.isOver = true
- this.__destroy()
- } else {
- if (this.sprite && this.sprite.isValid && this.sprite.hp > 0 &&
- this.sprite.node.group != other.node.group) {
- if (self.isValid && other.node.isValid) {
- this.isOver = true
- this.__destroy()
- }
- }
- }
- }
- }
- public __destroy() {
- super.__destroy()
- this.roundHit()
- }
- /**
- * 炸开后周围受到伤害
- */
- public roundHit() {
- let ff = this.sprite.ff
- let mGroup = this.sprite.getEnemyGroup();
- let nodes = ff.mMap.getSprites();
- for (let i = 0; i < nodes.length; i++) {
- const node = nodes[i];
- let target = node.getComponent(FSprite);
- if (target && node.active && target.isActive && target.hp > 0 && target.node.group == mGroup) {
- let dis = cc.Vec2.distance(this.node.getPosition(), node.getPosition());
- if (dis < 300) {
- if (target.hp > 0) {
- if (target != null && target.isActive) {
- this.sprite.atkjs(target, this._skillData);
- super.__destroy()
- }
- }
- }
- }
- }
- }
- }
|