SkillCharge.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * 冲锋
  3. */
  4. import CMath from "../../../../util/CMath";
  5. import FSprite, { SpriteActionType } from "../FSprite";
  6. import PSprite from "../PSprite";
  7. import ChargeCollision from "./ChargeCollision";
  8. import SkillBase from "./SkillBase";
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class SkillCharge extends SkillBase {
  12. @property({
  13. type:cc.Node,
  14. displayName: '预警显示'
  15. })
  16. mRedGo: cc.Node = null;
  17. /**
  18. * 预警延时
  19. */
  20. @property({
  21. displayName: '预警延时'
  22. })
  23. public dtime = 2;
  24. /**
  25. * 冲刺消耗的时间
  26. */
  27. @property({
  28. displayName: '冲刺消耗的时间'
  29. })
  30. public ctime = 0.7;
  31. onLoad(){
  32. super.onLoad();
  33. this.mRedGo.active = false;
  34. }
  35. public exe(target:FSprite,callback:()=>void){
  36. this.time = new Date().getTime();
  37. // this.sprite.setDir({x:0,y:0});
  38. this.mRedGo.active = true;
  39. let p1 = this.node.getPosition();
  40. let p2 = target.node.getPosition();
  41. let angle = CMath.getAngle(p1,p2);
  42. this.mRedGo.angle = angle*180/Math.PI;
  43. if(target instanceof PSprite){
  44. target.tangentMove(this.sprite.node);
  45. }
  46. cc.tween(this.node).sequence(
  47. cc.delayTime(this.dtime),
  48. cc.callFunc(()=>{
  49. this.mRedGo.active = false;
  50. this.moveGO(angle,callback);
  51. })
  52. ).start();
  53. }
  54. private moveGO(angle,callback:()=>void){
  55. this.sprite.playAction(SpriteActionType.atk,false,()=>{
  56. // this.AI.walk(this.range);
  57. this.sprite.playAction(SpriteActionType.stand,true)
  58. });
  59. let pos = cc.v2();
  60. let length = this.mRedGo.width;
  61. pos.x = length*Math.cos(angle);
  62. pos.y = length*Math.sin(angle);
  63. //copy当前碰撞区域,创建子弹打出去
  64. let boxCollider = this.node.getComponent(cc.PhysicsBoxCollider);
  65. let node = new cc.Node();
  66. node.x = this.node.x;
  67. node.y = this.node.y;
  68. node.group = 'bullet'
  69. let rigidBody = node.addComponent(cc.RigidBody);
  70. rigidBody.type = cc.RigidBodyType.Dynamic;
  71. // rigidBody.allowSleep = false;
  72. rigidBody.enabledContactListener = true;
  73. let physicsBoxCollider = node.addComponent(cc.PhysicsBoxCollider);
  74. physicsBoxCollider.sensor = true;
  75. physicsBoxCollider.size = boxCollider.size.clone();
  76. physicsBoxCollider.offset = boxCollider.offset.clone();
  77. let chargeCollision = node.addComponent(ChargeCollision);
  78. chargeCollision.skillBase = this;
  79. node.parent = this.sprite.ff.mMap.mSprites;
  80. cc.tween(this.node).sequence(
  81. cc.moveBy(this.ctime,pos),
  82. cc.callFunc(()=>{
  83. })
  84. ).start();
  85. cc.tween(node).sequence(
  86. cc.moveBy(this.ctime,pos),
  87. cc.callFunc(()=>{
  88. node.destroy();
  89. callback()
  90. })
  91. ).start();
  92. }
  93. }