import bullet from "../bullet"; import { Utils } from "../common/utils"; import { ResMgr } from "../res/resMgr"; import { ResRelease } from "../res/resRelease"; import { GameSysLogic } from "../update/gameSysLogic"; import Move from "../update/move"; import MoveTime from "../update/moveTime"; /** * 1 扇形弹幕: 开始角度(相对于向上), 角度,数量 * 2 旋转飞行: 半径 * 3 直线: 开始角度 * 4 直线后炸开: 时间,开始角度,数量 */ export class Barrage extends GameSysLogic{ parent: cc.Node; static skillNum = 1; private static _inst: Barrage; public static get inst(): Barrage { if (this._inst == null) { this._inst = new Barrage(); } return this._inst; } // 直线 async createPlayerBullet1(worldPos: cc.Vec2){ let bulletNode = await ResMgr.inst.loadPrefab('monster/bullet', this.parent); let moveCpt = Utils.getCpt(Move, bulletNode); moveCpt.dirction = cc.v2(0,1); moveCpt.speed = 500; let localPos = this.parent.convertToNodeSpaceAR(worldPos); bulletNode.setPosition(localPos); } async createPlayerBullet(worldPos: cc.Vec2){ switch(Barrage.skillNum){ case 1: this.createPlayerBullet1(worldPos); break; case 2: this.createPlayerBullet2(worldPos); break; case 3: this.createPlayerBullet3(worldPos); break; case 4: this.createPlayerBullet4(worldPos); break; } } // 扇形弹幕 async createPlayerBullet2(worldPos: cc.Vec2){ let num = 9; let angle = 60; let leftVec2 = cc.v2(0,1).rotateSelf(Utils.radian(angle/2)); let prefab = await ResMgr.inst.getPrefab('monster/bullet'); for (let index = 0; index < num; index++) { let bulletNode = ResMgr.inst.createNode(prefab, this.parent) let bulletCpt = bulletNode.getComponent(bullet); let moveCpt = Utils.getCpt(Move, bulletNode); moveCpt.dirction = leftVec2.rotate(Utils.radian(-angle / (num-1) * index)); moveCpt.speed = 500; bulletCpt.setDirction(moveCpt.dirction); let localPos = this.parent.convertToNodeSpaceAR(worldPos); bulletNode.setPosition(localPos); } } async createPlayerBullet3(worldPos: cc.Vec2){ let time = 1; let prefab = await ResMgr.inst.getPrefab('monster/bullet'); let bulletNode = ResMgr.inst.createNode(prefab, this.parent) let moveCpt = Utils.getCpt(MoveTime, bulletNode); moveCpt.dirction = cc.v2(0,1); moveCpt.speed = 500; moveCpt.overTime = time; moveCpt.call = ()=>{ let num = 10; let angle = 360; let leftVec2 = cc.v2(1,1).normalize(); for (let index = 0; index < num; index++) { let bulletNode1 = ResMgr.inst.createNode(prefab, this.parent) let bulletCpt = bulletNode1.getComponent(bullet); let moveCpt = Utils.getCpt(Move, bulletNode1); moveCpt.dirction = leftVec2.rotate(Utils.radian(-angle / (num) * index)); moveCpt.speed = 500; bulletCpt.setDirction(moveCpt.dirction); bulletNode1.setPosition(bulletNode.getPosition()); // console.log( "@@-", bulletNode1.getPosition().toString()); } bulletNode.destroy(); console.log('@@=',bulletNode.getPosition().toString()); } let localPos = this.parent.convertToNodeSpaceAR(worldPos); bulletNode.setPosition(localPos); } async createPlayerBullet4(worldPos: cc.Vec2){ let num = 8; let r = 40; let leftVec2 = cc.v2(0,1) let angle = 360; let prefab = await ResMgr.inst.getPrefab('monster/bullet'); let node = new cc.Node('cricleBullet'); this.parent.addChild(node); let moveCpt = Utils.getCpt(Move, node); moveCpt.dirction = cc.v2(0,1); moveCpt.speed = 500; let localPos = this.parent.convertToNodeSpaceAR(worldPos); node.setPosition(localPos); let t = cc.tween(node).by(1, {angle: 360}).repeatForever().start(); let isOver = ()=>{ if(cc.isValid(node, true)){ if(node.childrenCount <= 0){ t.stop(); node.destroy(); } } } for (let index = 0; index < num; index++) { let bulletNode = ResMgr.inst.createNode(prefab, node) let bulletCpt = bulletNode.getComponent(bullet); let dirction = leftVec2.rotate(Utils.radian(-angle / (num) * index)); bulletNode.setPosition(dirction.mul(r)); bulletCpt.setDirction(dirction.rotate(Utils.radian(90))); bulletNode.addComponent(ResRelease).call = function(){ setTimeout(() => { isOver(); }, 100); } } } }