DESKTOP-5RP3AKU\Jisol 6ebed0b45e 重构继承关系
2023-11-01 02:01:35 +08:00

115 lines
2.7 KiB
TypeScript

import { v2 } from "cc";
import { Vec2 } from "cc";
import { GTowards } from "../base/GObject";
//阵法类
export class GTactical{
tactical:number[][];
//阵容朝向
towards:GTowards;
//位置偏差
offset:Vec2;
//阵法位置
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,offset:Vec2 = Vec2.ZERO){
this.tactical = tactical;
this.towards = towards;
this.offset = offset;
}
setOffset(offset:Vec2):this{
this.offset = offset;
return this;
}
//获取阵法
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 = this.offset){
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;
}
}