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