106 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-10-23 18:56:01 +08:00
import { v2 } from "cc";
import { Vec2 } from "cc";
2023-10-26 03:06:44 +08:00
import { GTowards } from "../base/GObject";
2023-10-23 18:56:01 +08:00
//阵法类
export class GTactical{
tactical:number[][];
2023-10-26 03:06:44 +08:00
//阵容朝向
towards:GTowards;
2023-10-23 18:56:01 +08:00
//阵法位置
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)],
];
2023-10-26 03:06:44 +08:00
constructor(tactical:number[][],towards:GTowards = GTowards.RIGHT){
2023-10-23 18:56:01 +08:00
this.tactical = tactical;
2023-10-26 03:06:44 +08:00
this.towards = towards;
2023-10-23 18:56:01 +08:00
}
//获取阵法
static getTactical(isReversed:boolean = false): GTactical{
let tactical = [
2023-10-26 03:06:44 +08:00
[0,4,3],
2023-10-28 18:50:06 +08:00
[6,0,1],
2023-10-26 03:06:44 +08:00
[0,5,2],
2023-10-23 18:56:01 +08:00
];
if(isReversed){
tactical = this.getTacticalFlipX(tactical);
2023-10-26 03:06:44 +08:00
return new GTactical(tactical,GTowards.LEFT);
2023-10-23 18:56:01 +08:00
}
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);
2023-10-26 03:06:44 +08:00
return new GTactical(tactical,GTowards.LEFT);
2023-10-23 18:56:01 +08:00
}
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);
2023-10-26 03:06:44 +08:00
return new GTactical(tactical,GTowards.LEFT);
2023-10-23 18:56:01 +08:00
}
return new GTactical(tactical);
}
//阵法取反
static getTacticalFlipX(tactical:number[][]){
return tactical.map(row => row.reverse());
}
//返回阵法位置
getPosition(index:number,father:Vec2 = v2(0,0)){
2023-10-24 02:32:06 +08:00
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{
2023-10-23 18:56:01 +08:00
for(let i = 0;i < 3;i++){
for(let j = 0;j < 3;j++){
let tag = this.tactical[i][j];
if(tag == index){
2023-10-24 02:32:06 +08:00
return v2(j,i);
2023-10-23 18:56:01 +08:00
}
}
}
2023-10-24 02:32:06 +08:00
return null;
}
//返回我在第几排
getRow(index:number):number{
let pos;
if(pos = this.getXY(index)){
return pos.y;
}
2023-10-23 18:56:01 +08:00
return null;
}
}