BBObject.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import FSprite from "../object/FSprite";
  2. import BObject from "./BObject";
  3. /**
  4. * 炸弹
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class BBObject extends BObject {
  9. private isOver = false
  10. onBeginContact(contact: cc.PhysicsContact, self, other) {
  11. if(this.isOver){
  12. return
  13. }
  14. if (self.node == this.node) {
  15. if (other.tag != 0) {
  16. } else if (other.node.group == 'map') {//撞到地图
  17. this.isOver = true
  18. this.__destroy()
  19. } else {
  20. if (this.sprite && this.sprite.isValid && this.sprite.hp > 0 &&
  21. this.sprite.node.group != other.node.group) {
  22. if (self.isValid && other.node.isValid) {
  23. this.isOver = true
  24. this.__destroy()
  25. }
  26. }
  27. }
  28. }
  29. }
  30. public __destroy() {
  31. super.__destroy()
  32. this.roundHit()
  33. }
  34. /**
  35. * 炸开后周围受到伤害
  36. */
  37. public roundHit() {
  38. let ff = this.sprite.ff
  39. let mGroup = this.sprite.getEnemyGroup();
  40. let nodes = ff.mMap.getSprites();
  41. for (let i = 0; i < nodes.length; i++) {
  42. const node = nodes[i];
  43. let target = node.getComponent(FSprite);
  44. if (target && node.active && target.isActive && target.hp > 0 && target.node.group == mGroup) {
  45. let dis = cc.Vec2.distance(this.node.getPosition(), node.getPosition());
  46. if (dis < 300) {
  47. if (target.hp > 0) {
  48. if (target != null && target.isActive) {
  49. this.sprite.atkjs(target, this._skillData);
  50. super.__destroy()
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }