import Boy from "./Boy"; const {ccclass, property} = cc._decorator; @ccclass export default class Bot extends cc.Component { boy:Boy; target:Boy; onLoad(){ this.boy = this.node.getComponent(Boy); this.schedule(this.updateOperate,0.8-0.6*window.gm.botStrength); } updateOperate(){ if(window.gm.isGameOver)return; //find a nearest target let distance = 10000; window.gm.boys.forEach((boy:Boy)=>{ if(boy!=this.boy&&boy.isValid){ let newDistance = this.boy.node.position.sub(boy.node.position).mag(); if(newDistancecc.winSize.width/2-30){ targetX -= 55*2; } if(this.node.xtargetX+80){ this.boy.leftUp(); }else{ if(this.node.ytargetY-55){ this.boy.leftUp(); }else if(this.node.y0){ if(targetX-55<-cc.winSize.width/2+30){ targetX += 55*2; } if(this.node.x>targetX-55){ this.boy.leftUp(); }else if(this.node.xtargetY-55){ this.boy.rightUp(); }else if(this.node.ytargetX+80){ this.boy.leftUp(); }else{ if(this.node.ytargetY-55){ this.boy.leftUp(); }else if(this.node.y0){ if(this.node.x>targetX-55){ this.boy.leftUp(); }else if(this.node.xtargetY-55){ this.boy.rightUp(); }else if(this.node.y