This commit is contained in:
2024-09-25 17:23:56 +08:00
parent 3870bdec50
commit 5831697fb8
21 changed files with 155 additions and 93 deletions

View File

@@ -91,6 +91,7 @@ export class RoleViewComp extends CCComp {
is_dead:boolean = false; //是否摧毁
is_stop:boolean = false;
is_atking:boolean = false;
is_moving:boolean = false;
type:number = 0;
onLoad() {
// this.BoxRang = this.node.getChildByName("range_box");
@@ -131,14 +132,17 @@ export class RoleViewComp extends CCComp {
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group == otherCollider.group&&selfCollider.tag==otherCollider.tag){
if(selfCollider.node.position.y < otherCollider.node.position.y){
if(selfCollider.node.getSiblingIndex() < otherCollider.node.getSiblingIndex()){
selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()+1)
// console.log(selfCollider.node.position.y+":role:hero:"+otherCollider.node.position.y);
if(selfCollider.node.position.y <= otherCollider.node.position.y){
if(selfCollider.node.getSiblingIndex() <= otherCollider.node.getSiblingIndex()){
selfCollider.node.setSiblingIndex(200)
// selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()+1)
// console.log("onPreSolve b:"+selfCollider.node.uuid+":"+selfCollider.node.getSiblingIndex()+"/"+otherCollider.node.uuid+":"+otherCollider.node.getSiblingIndex());
}else{
selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()-1)
selfCollider.node.setSiblingIndex(-1)
// console.log("onPreSolve f:"+selfCollider.node.uuid+":"+selfCollider.node.getSiblingIndex()+"/"+otherCollider.node.uuid+":"+otherCollider.node.getSiblingIndex());
}
}
@@ -180,17 +184,41 @@ export class RoleViewComp extends CCComp {
this.atk_time += dt;
this.in_atk();
this.skill_cds(dt);
// this.move();
this.move(dt);
this.check_enemys()
}
skill_cds(dt:number){
this.skill1.cd -= dt;
if(this.skill1.alive) this.skill1.cd -= dt;
if(this.skill2.alive) this.skill2.cd -= dt;
if(this.skill3.alive) this.skill3.cd -= dt;
if(this.skill4.alive) this.skill4.cd -= dt;
if(this.skill5.alive) this.skill5.cd -= dt;
if(this.skill1.cd <= 0){
this.shoot(this.skill1.uuid);
this.skill1.cd=this.skill1.cd_max
console.log("shoot uuid :"+this.skill1.uuid);
}
}
if(this.skill2.cd <= 0){
this.shoot(this.skill2.uuid);
this.skill2.cd=this.skill2.cd_max
console.log("shoot uuid :"+this.skill2.uuid);
}
if(this.skill3.cd <= 0){
this.shoot(this.skill3.uuid);
this.skill3.cd=this.skill3.cd_max
console.log("shoot uuid :"+this.skill3.uuid);
}
if(this.skill4.cd <= 0){
this.shoot(this.skill4.uuid);
this.skill4.cd=this.skill4.cd_max
console.log("shoot uuid :"+this.skill4.uuid);
}
if(this.skill5.cd <= 0){
this.shoot(this.skill5.uuid);
this.skill5.cd=this.skill5.cd_max
console.log("shoot uuid :"+this.skill5.uuid);
}
// this.skills.forEach((e:any) => {
// if(e.cd > 0&&e.alive){
// e.cd -= dt;
@@ -222,41 +250,29 @@ export class RoleViewComp extends CCComp {
this.enemy = v3(720,this.node.position.y);
}
}
move(){
move(dt:number){
if(this.stop_cd > 0){
this.as.idle()
this.is_moving=false
return
}
if(this.enemy){
this.move_to(this.enemy.position)
this.move_to()
let move_x=1
let move_y=1
if(Math.abs(this.enemy.x - this.node.position.x) < this.atk_dis) move_x = 0
if(Math.abs(this.enemy.y - this.node.position.y) < this.atk_dis) move_y = 0
if(this.enemy.x < this.node.position.x){
this.scale = -1
}else{
this.move_to(v3(0,0));
this.scale = 1
}
this.node.setScale(this.scale,1);
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale*move_x, this.node.position.y+dt*this.speed*move_y, this.node.position.z);
}
move_to(enemy:Vec3){
// console.log("move to ",enemy);
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
move.target = v3(enemy.x-100,enemy.y);
move.node = this.node;
move.speed = this.ospeed;
if(enemy.x < this.node.position.x){
this.node.setScale(-1,1);
}else{
this.node.setScale(1,1);
}
}
shoot(skill_uuid:number,y:number=0,x:number=0){
// console.log("mon shoot");
let skill = ecs.getEntity<Skill>(Skill);
let atk = smc.skills[skill_uuid].atk+this.atk+this.buff_atk+this.mission_atk;
let {pos,t_pos}=this.get_enemy_pos()
pos.y=pos.y + y
pos.x=pos.x + x
if(smc.skills[skill_uuid].type==11){
pos.y=300
t_pos.y=t_pos.y-300
}
skill.load(pos,this.box_group,this.node,skill_uuid,atk,t_pos);
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
move_to(){
if(this.is_moving) return
this.is_moving=true
this.as.move()
}
//使用max_skill
@@ -298,6 +314,20 @@ export class RoleViewComp extends CCComp {
}
}
shoot(skill_uuid:number,y:number=0,x:number=0){
// console.log("mon shoot");
let skill = ecs.getEntity<Skill>(Skill);
let atk = smc.skills[skill_uuid].atk+this.atk+this.buff_atk+this.mission_atk;
let {pos,t_pos}=this.get_enemy_pos()
pos.y=pos.y + y
pos.x=pos.x + x
if(smc.skills[skill_uuid].type==11){
pos.y=300
t_pos.y=t_pos.y-300
}
skill.load(pos,this.box_group,this.node,skill_uuid,atk,t_pos,this.atk_dis);
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
}
hp_change(hp: number){
if(this.is_dead){
return;