123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import CMath from "../../../../util/CMath";
- import BObject from "../../bullet/BObject";
- import FSprite,{SpriteActionType} from "../FSprite";
- import SkillBase from "./SkillBase";
- /**
- * 旋转发射子弹
- */
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class SkillRotate extends SkillBase {
- @property({
- displayName: '每次发射子弹数量'
- })
- public count = 10;
- @property({
- displayName: '每颗子弹间隔时间'
- })
- public btime = 0.1;
- @property({
- displayName: '每颗子弹旋转弧度'
- })
- public rotate = 0.2;
- @property({
- type:cc.Prefab,
- displayName: '子弹'
- })
- mBullet:cc.Prefab = null;
- /**
- * 释放技能
- */
- public exe(target:FSprite,callback:()=>void){
- this.time = new Date().getTime();
- // this.sprite.setDir({x:0,y:0});
-
- //-----播放开始动画
- let bNode = cc.instantiate(this.mBullet)
- let bobject = bNode.getComponent(BObject)
- bobject.distance = this.range
- let sf = bobject.mStartEffect
- let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
- let y = this.sprite.mAtkSite.worldY
- let pos = cc.v2(x, y);
- let sfNode = cc.instantiate(sf)
- sfNode.angle = this.sprite.wAngle
- sfNode.setPosition(pos);
- sfNode.parent = this.sprite.node
- let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton)
- startSpine.setCompleteListener(() => {
- startSpine.setCompleteListener(null);
- sfNode.destroy()
- callback()
- });
- if(startSpine.findAnimation('skill')){
- startSpine.setAnimation(0, 'skill', false);
- }else{
- startSpine.setAnimation(0, 'atk', false);
- }
- //----开始动画播放结束
- this.sprite.playAction(SpriteActionType.atk,false,()=>{
- // this.AI.walk(this.range);
- this.sprite.playAction(SpriteActionType.stand,true)
- });
- let tp = target.node.getPosition();
- for (let i = 0; i < this.count; i++) {
- this.fire(i,tp);
- }
- }
- private fire(index,tp:cc.Vec2){
- cc.tween(this).sequence(
- cc.delayTime(index*this.btime),
- cc.callFunc(()=>{
- this.fireBullet(index,tp);
- })
- ).start();
-
- }
- private fireBullet(index,p2){
- let node = cc.instantiate(this.mBullet);
- node.group = 'bullet';
- let x = this.node.x+this.sprite.mAtkSite.worldX*this.sprite.spine.node.scaleX
- let y = this.node.y+this.sprite.mAtkSite.worldY
- let pos = cc.v2(x,y);
- node.setPosition(pos);
- let bObject = node.getComponent(BObject);
- bObject.setSprite(this.sprite);
- bObject.speed = this.speed;
- bObject.distance = this.range
- node.parent = this.sprite.map.mSprites;
- let p1 = node.getPosition();
- let angle = CMath.getAngle(p1,p2);
- let cur = index - this.count/2;
- angle += cur*this.rotate;
- bObject.fireAngle(angle);
- }
- }
|