SkillRotate.ts 3.1 KB

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