优化敌人动态逻辑

This commit is contained in:
admin
2023-04-28 14:54:01 +08:00
parent 5eecee380e
commit 3bfd42904c
2 changed files with 14 additions and 6 deletions

View File

@@ -23,6 +23,8 @@ export class dpComponent extends Component {
//飞行最大距离
public dp_max:number = 12;
private mx: any = 1;
start() {
this.p_an.crossFade('p_an', .5);
@@ -38,10 +40,15 @@ export class dpComponent extends Component {
//20-60秒出现的敌人如果是单个 1/2随机一种组合出现 0/2随机一种
//60秒以上 单个1/2/3随机一种组合0/1/2随机一种
/** 此类中只对敌人路线做逻辑处理,子弹发射在子弹类中 */
if(this.node.position.x>3.8) this.mx = -1;
if(this.node.position.x<-3.8) this.mx = 1;
const pos = this.node.position;
let movez = pos.z + this.dpSpeed;
this.node.setPosition(pos.x, pos.y, movez);
this.node.setPosition(this.node.position.x + 0.03 * this.mx, pos.y, movez);
if(movez > this.dp_max) this.node.destroy();
}
@@ -55,6 +62,7 @@ export class dpComponent extends Component {
/**向我方z轴靠近 */
public moveToP(){
//控制this.node.x轴逐步接近玩家的x值
}
}

View File

@@ -72,7 +72,7 @@ export class gameManager extends Component {
this.createZd();
this._new_zd_time = 0;
}
this._createDpTime += deltaTime;
if(this._createDpArr <= 2){
@@ -111,11 +111,11 @@ export class gameManager extends Component {
let t = 1;
if(randm === dpImpl.dpType.TYPE1){
p = this.dp1;
speed = this.dp1_speed;
speed = this.dp1_speed+(math.randomRange(0.01,0.02)*(math.randomRangeInt(-1,2)));
t=1;
}else{
p = this.dp2;
speed = this.dp2_speed;
speed = this.dp2_speed+(math.randomRange(0.01,0.02)*(math.randomRangeInt(-1,2)));
t=2;
}
const dp = instantiate(p);
@@ -135,7 +135,7 @@ export class gameManager extends Component {
parr[i] = instantiate(randm==1?this.dp1:this.dp2);
parr[i].setParent(this.node);
const dpc = parr[i].getComponent(dpComponent);
dpc._init(randm==1?this.dp1_speed:this.dp2_speed,n,1);
dpc._init(randm==1?this.dp1_speed+(math.randomRange(0.01,0.02)*(math.randomRangeInt(-1,2))):this.dp2_speed+(math.randomRange(0.01,0.02)*(math.randomRangeInt(-1,2))),n,1);
parr[i].setPosition(i*1.8-3.6, 1, -dpc.dp_max);
}