碰撞体 基本完成,开始精灵技能释放优化

This commit is contained in:
2024-08-22 13:38:03 +08:00
parent a707bcca29
commit bdb96e61a1
35 changed files with 806 additions and 1809 deletions

View File

@@ -67,6 +67,8 @@ export class Monster extends ecs.Entity {
mv.atk_cd = smc.heros[uuid].atk_cd;
mv.power = smc.heros[uuid].power;
mv.type = smc.heros[uuid].type;
mv.skill_name = "base2";
mv.max_skill_name = "fire";
mv.scale = -1;
mv.Tpos = v3(0,0,0);
mv.change_name(smc.heros[uuid].name,-1)

View File

@@ -47,7 +47,7 @@ export class MonsterViewComp extends CCComp {
power_max: number = 100; /** 能量最大值 */
power_speed: number = 1; //能量回复速度每0.1秒回复量
skill_name: string = "atk"; //技能名称
skill_name: string = "base"; //技能名称
max_skill_name: string = "base"; //大技能名称
atk: number = 10; /**攻击力 */
@@ -67,6 +67,7 @@ export class MonsterViewComp extends CCComp {
private timer:Timer = new Timer(0.1); //计时器
is_dead:boolean = false; //是否摧毁
is_stop:boolean = false;
is_atking:boolean = false;
onLoad() {
this.as = this.getComponent(MonsterSpine);
@@ -93,29 +94,35 @@ export class MonsterViewComp extends CCComp {
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体结束接触时被调用一次
// console.log('onEndContact');
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group){
if(otherCollider.tag != 8){
this.stop_cd = 0.5;
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
if(selfCollider.group != otherCollider.group){
let skill = otherCollider.node.getComponent(SkillCom)!;
// console.log('onPostSolve',skill);
this.in_atked();
this.hp_change(skill.atk);
}
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){
let skill = otherCollider.node.getComponent(SkillCom)!;
// console.log('onPostSolve',skill);
this.in_atked();
this.hp_change(skill.atk);
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
if(otherCollider.tag != BoxSet.SKILL_TAG&&selfCollider.tag != BoxSet.ATK_RANGE){
this.stop_cd = 0.1;
}
}
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
this.is_atking = true;
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group == otherCollider.group){
console.log('group 相同');
if(otherCollider.tag != 8){
// console.log('monster view group 相同');
if(otherCollider.tag != BoxSet.SKILL_TAG){
let self_pos=selfCollider.node.getPosition();
let other_pos=otherCollider.node.getPosition();
if(selfCollider.group == BoxSet.HERO){
@@ -191,23 +198,26 @@ export class MonsterViewComp extends CCComp {
power_change(power: number){
this.power += power;
if(this.power >= this.power_max){
this.load_skill(this.max_skill_name);
this.shoot(this.max_skill_name);
this.power = 0
}
let power_progress= this.power/this.power_max;
this.node.getChildByName("power").getComponent(ProgressBar)!.progress = power_progress;
}
in_act(dt: number) {
if(this.atk_time >= this.atk_cd){
this.atk_time = 0;
// console.log("atk_cd:"+this.atk_cd);
this.as.atk();
this.scheduleOnce(()=>{
this.load_skill(this.skill_name);
},0.2)
if(this.is_atking){
this.atk_time = 0;
// console.log("atk_cd:"+this.atk_cd);
this.as.atk();
this.scheduleOnce(()=>{
this.shoot(this.skill_name);
},0.2)
}
}else{
this.atk_time += dt;
}
this.atk_time += dt;
}
hp_change(hp: number){
if(this.is_dead){
@@ -220,9 +230,10 @@ export class MonsterViewComp extends CCComp {
let hp_progress= this.hp/this.hp_max;
this.node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
if(this.hp <= 0){
this.dead();
this.is_dead = true;
setTimeout(() => {
this.toDestroy();
this.ent.destroy();
}, 15);
}
@@ -232,8 +243,8 @@ export class MonsterViewComp extends CCComp {
if(this.stop_cd > 0){
this.stop_cd -= dt;
if(this.stop_cd <= 0){
// this.speed = this.ospeed;
this.stop_cd = 0;
this.is_atking = false;
}
}
}
@@ -258,19 +269,19 @@ export class MonsterViewComp extends CCComp {
}
});
}
load_skill(skill_name:string){
console.log("load_skill");
shoot(skill_name:string){
console.log("monster shoot");
let skill = ecs.getEntity<Skill>(Skill);
let x=30
if(this.scale==1){
x=40
x=0
}else{
x=-20
x=-0
}
let pos = v3(x,50)
let pos = v3(x,40)
let speed =350
let scale = this.scale
let dis = 30;
let dis = 50;
console.log(speed);
skill.load(pos,speed,dis,scale,this.node,skill_name,this.atk);
}
@@ -294,9 +305,7 @@ export class MonsterViewComp extends CCComp {
node.parent = this.node.parent;
}
toDestroy(){
this.dead();
this.ent.destroy();
}
reset() {
this.is_dead = false;