This commit is contained in:
2024-08-01 17:10:59 +08:00
parent 904a60b04f
commit 7344042728

View File

@@ -52,10 +52,10 @@ export class MonsterViewComp extends CCComp {
case BoxSet.MONSTER:
switch (otherCollider.tag){
case BoxSet.HERO:
console.log("im monster other is hero");
// console.log("im monster other is hero");
this.speed = 0;
this.timer = 1;
console.log("speed:"+this.speed+" | timer:"+this.timer);
// console.log("speed:"+this.speed+" | timer:"+this.timer);
break;
case BoxSet.HERO_SKILL:
@@ -116,14 +116,10 @@ export class MonsterViewComp extends CCComp {
}
update(dt: number){
if(this.timer > 0){
this.timer -= dt;
if(this.timer <= 0){
this.speed = this.ospeed;
console.log("speed:"+this.speed);
this.timer = 0;
}
}
this.in_destroy();
this.in_stop(dt);
switch (this.type) {
case 1:
this.as.walk();
@@ -133,37 +129,45 @@ export class MonsterViewComp extends CCComp {
break;
}
if(this.camp == -1){
if(this.node.position.x < BoxSet.LETF_END){
this.node.destroy();
}else{
this.move(dt);
}
}
if(this.camp == 1){
if(this.node.position.x > BoxSet.RIGHT_END){
this.reset();
}else{
this.move(dt);
}
}
this.update_pos();
}
move(dt: number){
this.node.setPosition(this.node.position.x+dt*this.speed*this.camp, this.node.position.y, this.node.position.z);
}
/** 静止时间 */
in_stop (dt: number) {
if(this.timer > 0){
this.timer -= dt;
if(this.timer <= 0){
this.speed = this.ospeed;
this.timer = 0;
}
}
}
in_destroy(){
switch (this.camp) {
case -1:
if(this.node.position.x < BoxSet.LETF_END){
this.node.destroy();
}
break;
case 1:
if(this.node.position.x > BoxSet.RIGHT_END){
this.reset();
}
break;
}
}
update_pos(){
smc.monsters_in.forEach((element,index) => {
if(element.eid == this.ent.eid){
// console.log("index:"+index)
element.pos_x = this.node.position.x;
}
});
// console.log('smc.monsters_in',smc.monsters_in);
}
reset() {
console.log("node destroy:",this.node,this.ent)
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);