SkillShotgun.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  43. let y = this.sprite.mAtkSite.worldY
  44. let pos = cc.v2(x, y);
  45. let sfNode = cc.instantiate(sf)
  46. sfNode.angle = this.sprite.wAngle
  47. sfNode.setPosition(pos);
  48. sfNode.parent = this.sprite.node
  49. let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton)
  50. startSpine.setCompleteListener(() => {
  51. startSpine.setCompleteListener(null);
  52. sfNode.destroy()
  53. callback()
  54. });
  55. if(startSpine.findAnimation('skill')){
  56. startSpine.setAnimation(0, 'skill', false);
  57. }else{
  58. startSpine.setAnimation(0, 'atk', false);
  59. }
  60. //----开始动画播放结束
  61. this.sprite.playAction(SpriteActionType.atk, false, () => {
  62. this.AI.walk(this.range);
  63. });
  64. let tp = target.node.getPosition();
  65. for (let i = 0; i < this.count; i++) {
  66. this.fire(i, tp);
  67. }
  68. }
  69. public fire(index, tp: cc.Vec2) {
  70. this.fireBullet(index, tp);
  71. }
  72. private fireBullet(index, p2) {
  73. for (let i = 0; i < this.bcount; i++) {
  74. cc.tween(this).sequence(
  75. cc.delayTime(i * this.btime),
  76. cc.callFunc(() => {
  77. this.fireBulletByTime(index, p2);
  78. })
  79. ).start();
  80. }
  81. }
  82. private fireBulletByTime(index, p2) {
  83. let node = cc.instantiate(this.mBullet);
  84. node.group = 'bullet'
  85. let sprite = this.sprite
  86. let x = sprite.node.x + sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  87. let y = sprite.node.y + sprite.mAtkSite.worldY
  88. let pos = cc.v2(x, y);
  89. node.setPosition(pos);
  90. let bObject = node.getComponent(BObject);
  91. bObject.setSprite(this.sprite);
  92. bObject.speed = this.speed;
  93. node.parent = this.sprite.map.mSprites;
  94. let p1 = node.getPosition();
  95. let angle = CMath.getAngle(p1, p2);
  96. let cur = index - Math.floor(this.count / 2);
  97. angle += cur * this.rotate;
  98. bObject._skillData = this._skillData
  99. bObject.fireAngle(angle);
  100. }
  101. }