SkillShotgun.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import CMath from "../../../../util/CMath";
  2. import BObject from "../../bullet/BObject";
  3. import FSprite, { SpriteActionType } from "../FSprite";
  4. import SkillBase from "./SkillBase";
  5. /**
  6. * 散弹
  7. */
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class SkillShotgun extends SkillBase {
  11. @property({
  12. displayName: '每次发射方向数'
  13. })
  14. public count = 10;
  15. @property({
  16. displayName: '每方向旋转弧度'
  17. })
  18. public rotate = 0.2;
  19. @property({
  20. displayName: '每个方向多少颗子弹'
  21. })
  22. public bcount = 3;
  23. @property({
  24. displayName: '每个子弹间隔时间'
  25. })
  26. public btime = 0.2;
  27. @property({
  28. type: cc.Prefab,
  29. displayName: '子弹'
  30. })
  31. public mBullet: cc.Prefab = null;
  32. /**
  33. * 释放技能
  34. */
  35. public exe(target: FSprite,callback:()=>void) {
  36. this.time = new Date().getTime();
  37. // this.sprite.setDir({ x: 0, y: 0 });
  38. //-----播放开始动画
  39. let bNode = cc.instantiate(this.mBullet)
  40. let bobject = bNode.getComponent(BObject)
  41. let sf = bobject.mStartEffect
  42. bobject.distance = this.range
  43. let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  44. let y = this.sprite.mAtkSite.worldY
  45. let pos = cc.v2(x, y);
  46. let sfNode = cc.instantiate(sf)
  47. sfNode.angle = this.sprite.wAngle
  48. sfNode.setPosition(pos);
  49. sfNode.parent = this.sprite.node
  50. let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton)
  51. startSpine.setCompleteListener(() => {
  52. startSpine.setCompleteListener(null);
  53. sfNode.destroy()
  54. callback()
  55. });
  56. if(startSpine.findAnimation('skill')){
  57. startSpine.setAnimation(0, 'skill', false);
  58. }else{
  59. startSpine.setAnimation(0, 'atk', false);
  60. }
  61. //----开始动画播放结束
  62. this.sprite.playAction(SpriteActionType.atk, false, () => {
  63. // this.AI.walk(this.range);
  64. this.sprite.playAction(SpriteActionType.stand,true)
  65. });
  66. let tp = target.node.getPosition();
  67. for (let i = 0; i < this.count; i++) {
  68. this.fire(i, tp);
  69. }
  70. }
  71. public fire(index, tp: cc.Vec2) {
  72. this.fireBullet(index, tp);
  73. }
  74. private fireBullet(index, p2) {
  75. for (let i = 0; i < this.bcount; i++) {
  76. cc.tween(this).sequence(
  77. cc.delayTime(i * this.btime),
  78. cc.callFunc(() => {
  79. this.fireBulletByTime(index, p2);
  80. })
  81. ).start();
  82. }
  83. }
  84. private fireBulletByTime(index, p2) {
  85. let node = cc.instantiate(this.mBullet);
  86. node.group = 'bullet'
  87. let sprite = this.sprite
  88. let x = sprite.node.x + sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  89. let y = sprite.node.y + sprite.mAtkSite.worldY
  90. let pos = cc.v2(x, y);
  91. node.setPosition(pos);
  92. let bObject = node.getComponent(BObject);
  93. bObject.setSprite(this.sprite);
  94. bObject.speed = this.speed;
  95. bObject.distance = this.range
  96. node.parent = this.sprite.map.mSprites;
  97. let p1 = node.getPosition();
  98. let angle = CMath.getAngle(p1, p2);
  99. let cur = index - Math.floor(this.count / 2);
  100. angle += cur * this.rotate;
  101. bObject._skillData = this._skillData
  102. bObject.fireAngle(angle);
  103. }
  104. }