攻击距离设定

This commit is contained in:
2024-09-11 10:19:35 +08:00
parent 0f7f2ad49b
commit f5a8cb20de
31 changed files with 114 additions and 191 deletions

View File

@@ -63,9 +63,9 @@ export class BoxRangComp extends CCComp {
this.HeroViewComp.enemy = otherCollider.node;
}
}
if(Math.abs(other_pos.x-self_pos.x) < this.atk_range){
if(Math.abs(other_pos.x-self_pos.x) < this.HeroViewComp.atk_dis){
this.HeroViewComp.is_atking = true;
// this.HeroViewComp.stop_cd = 0.1
this.HeroViewComp.stop_cd = 0.1
}
}

View File

@@ -41,7 +41,6 @@ export class Hero extends ecs.Entity {
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!) {
console.log("加载角色",uuid,smc.heros[uuid]);
var path = "game/hero/"+smc.heros[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
@@ -85,6 +84,7 @@ export class Hero extends ecs.Entity {
mv.level = smc.heros[uuid].level;
mv.atk = smc.heros[uuid].atk;
mv.atk_cd = smc.heros[uuid].atk_cd;
mv.atk_dis = smc.heros[uuid].atk_dis;
mv.power = smc.heros[uuid].power;
mv.type = smc.heros[uuid].type;
mv.skill_uuid = 9001;

View File

@@ -64,6 +64,7 @@ export class HeroViewComp extends CCComp {
atk: number = 10; /**攻击力 */
// atk_speed: number = 1;
atk_cd: number = 1.3; /**攻击速度 攻击间隔 */
atk_dis: number = 80;
atk_time: number = 0; /** 冷却时间 */
speed: number = 100; /** 角色移动速度 */
@@ -138,29 +139,29 @@ export class HeroViewComp extends CCComp {
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
this.is_atking = true;
this.stop_cd = 0.1;
}
// if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
// this.is_atking = true;
// this.stop_cd = 0.1;
// }
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
let self_pos=selfCollider.node.getPosition();
let other_pos=otherCollider.node.getPosition();
// console.log('mon view group 相同');
switch (selfCollider.group) {
case BoxSet.HERO:
if(self_pos.x < other_pos.x){
// this.stop_cd=0.1
}
break;
case BoxSet.MONSTER:
if(self_pos.x > other_pos.x){
// this.stop_cd=0.1
}
break
}
}
// if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
// let self_pos=selfCollider.node.getPosition();
// let other_pos=otherCollider.node.getPosition();
// // console.log('mon view group 相同');
// switch (selfCollider.group) {
// case BoxSet.HERO:
// if(self_pos.x < other_pos.x){
// // this.stop_cd=0.1
// }
// break;
// case BoxSet.MONSTER:
// if(self_pos.x > other_pos.x){
// // this.stop_cd=0.1
// }
// break
// }
// }
}
@@ -182,11 +183,11 @@ export class HeroViewComp extends CCComp {
if(this.stop_cd > 0){
return
}
if (this.scale === 1 && this.node.position.x >= 120) {
if (this.scale === 1 && this.node.position.x >= BoxSet.MONSTER_START) {
return;
}
if(this.scale===-1&&this.node.position.x <= BoxSet.HERO_START){
if(this.scale===-1&&this.node.position.x <= BoxSet.HERO_START-this.atk_cd){
return;
}
if(this.enemy){