import { v2 } from "cc"; import { Vec2 } from "cc"; import { GTowards } from "../base/GObject"; //阵法类 export class GTactical{ tactical:number[][]; //阵容朝向 towards:GTowards; //阵法位置 static pos:Vec2[][] = [ [v2(-100,150),v2(0,150),v2(100,150)], [v2(-100,0),v2(0,0),v2(100,0)], [v2(-100,-150),v2(0,-150),v2(100,-150)], ]; constructor(tactical:number[][],towards:GTowards = GTowards.RIGHT){ this.tactical = tactical; this.towards = towards; } //获取阵法 static getTactical(isReversed:boolean = false): GTactical{ let tactical = [ [0,4,3], [6,0,1], [0,5,2], ]; if(isReversed){ tactical = this.getTacticalFlipX(tactical); return new GTactical(tactical,GTowards.LEFT); } return new GTactical(tactical); } //获取阵法 static getTactical1(isReversed:boolean = false): GTactical{ let tactical = [ [0,3,0], [0,1,0], [0,2,0], ]; if(isReversed){ tactical = this.getTacticalFlipX(tactical); return new GTactical(tactical,GTowards.LEFT); } return new GTactical(tactical); } //获取阵法 static getTactical2(isReversed:boolean = false): GTactical{ let tactical = [ [0,0,3], [0,1,0], [2,0,0], ]; if(isReversed){ tactical = this.getTacticalFlipX(tactical); return new GTactical(tactical,GTowards.LEFT); } return new GTactical(tactical); } //阵法取反 static getTacticalFlipX(tactical:number[][]){ return tactical.map(row => row.reverse()); } //返回阵法位置 getPosition(index:number,father:Vec2 = v2(0,0)){ let pos; if(pos = this.getXY(index)){ return father.clone().add(GTactical.pos[pos.y][pos.x].clone()); } return null; } //返回XY getXY(index:number):Vec2{ for(let i = 0;i < 3;i++){ for(let j = 0;j < 3;j++){ let tag = this.tactical[i][j]; if(tag == index){ return v2(j,i); } } } return null; } //返回我在第几排 getRow(index:number):number{ let pos; if(pos = this.getXY(index)){ return pos.y; } return null; } }