SkillRotate.ts 2.9 KB

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