From 7344042728dac01f5de75ae7e6175760e6a33708 Mon Sep 17 00:00:00 2001 From: "pan@work" Date: Thu, 1 Aug 2024 17:10:59 +0800 Subject: [PATCH] ddd --- assets/script/game/monster/MonsterViewComp.ts | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/assets/script/game/monster/MonsterViewComp.ts b/assets/script/game/monster/MonsterViewComp.ts index 8b63b6fd..2ee9553a 100644 --- a/assets/script/game/monster/MonsterViewComp.ts +++ b/assets/script/game/monster/MonsterViewComp.ts @@ -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.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);