技能碰撞改回物理碰撞

This commit is contained in:
2025-03-31 08:16:41 +08:00
parent 798a831227
commit 063764dc82
5 changed files with 59 additions and 38 deletions

View File

@@ -33,8 +33,14 @@ export class HeroInfoCompComp extends CCComp {
this.update_info() this.update_info()
} }
update_info(){ update_info(){
let heros=ecs.query(ecs.allOf(HeroModelComp)) let heros=ecs.query(ecs.allOf(HeroModelComp))
for(let hero of heros){ this.has_hero=false
this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string=""
this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string=""
this.node.getChildByName("name").getComponent(Label).string="无英雄"
const sprite = this.node.getChildByName("mask").getChildByName("icon").getComponent(Sprite);
// sprite.spriteFrame = //需要添加默认头像
for(let hero of heros){
let info=hero.get(HeroViewComp) let info=hero.get(HeroViewComp)
if(info.node.position.x==HeroPos[this.c_id].pos.x){ if(info.node.position.x==HeroPos[this.c_id].pos.x){
this.has_hero=true this.has_hero=true
@@ -47,11 +53,11 @@ export class HeroInfoCompComp extends CCComp {
sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[info.hero_uuid].path); sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[info.hero_uuid].path);
}); });
} }
} }
if(this.is_Change){ // if(this.is_Change){
this.node.getChildByName("change").active=this.has_hero // this.node.getChildByName("change").active=this.has_hero
this.node.getChildByName("select").active=!this.has_hero // this.node.getChildByName("select").active=!this.has_hero
} // }
} }
/** 全局消息逻辑处理 */ /** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) { // private onHandler(event: string, args: any) {

View File

@@ -16,6 +16,12 @@ const { ccclass, property } = _decorator;
@ecs.register('MissionMonComp', false) @ecs.register('MissionMonComp', false)
export class MissionMonCompComp extends CCComp { export class MissionMonCompComp extends CCComp {
timer:Timer=new Timer(3) timer:Timer=new Timer(3)
// 添加刷怪队列
private monsterQueue: Array<{uuid: number, position: number, isBoss: boolean}> = [];
private isSpawning: boolean = false;
private spawnInterval: number = 0.5; // 每个怪物生成间隔时间
private spawnTimer: number = 0;
/** 视图层逻辑代码分离演示 */ /** 视图层逻辑代码分离演示 */
start() { start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象 // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
@@ -28,31 +34,45 @@ export class MissionMonCompComp extends CCComp {
this.mon_refresh() this.mon_refresh()
} }
// 处理刷怪队列
if (this.monsterQueue.length > 0 && !this.isSpawning) {
this.spawnTimer += dt;
if (this.spawnTimer >= this.spawnInterval) {
this.spawnNextMonster();
this.spawnTimer = 0;
}
}
} }
test_call(){ test_call(){
this.addMonster(5202,0,true) this.addToSpawnQueue(5202, 0, true);
} }
mon_refresh(){ mon_refresh(){
let num =3 let positions = [0, 1, 2, 3];
let t_num= Missions[0].length positions.forEach(pos => {
let y_num= Missions[1].length let x = RandomManager.instance.getRandomInt(0, Missions[0].length, 1);
let b_num= Missions[2].length this.addToSpawnQueue(Missions[0][x], pos, false);
let tc=1 });
let yc=2 }
let bc=1
let x=RandomManager.instance.getRandomInt(0,y_num,1)
this.addMonster(Missions[0][x],0)
x=RandomManager.instance.getRandomInt(0,y_num,1)
this.addMonster(Missions[0][x],1)
x=RandomManager.instance.getRandomInt(0,y_num,1)
this.addMonster(Missions[0][x],2)
x=RandomManager.instance.getRandomInt(0,y_num,1)
this.addMonster(Missions[0][x],3)
console.log("Missions t:"+x,Missions[0][x]) // 新增:添加到刷怪队列
private addToSpawnQueue(uuid: number, position: number, isBoss: boolean = false) {
this.monsterQueue.push({
uuid: uuid,
position: position,
isBoss: isBoss
});
}
// 新增:从队列中生成下一个怪物
private spawnNextMonster() {
if (this.monsterQueue.length === 0) return;
const monsterData = this.monsterQueue.shift();
if (monsterData) {
this.addMonster(monsterData.uuid, monsterData.position, monsterData.isBoss);
}
} }
private addMonster(uuid:number=1001,i:number=0,is_boss:boolean=false) { private addMonster(uuid:number=1001,i:number=0,is_boss:boolean=false) {

View File

@@ -54,7 +54,6 @@ export class HeroSkillSystem extends ecs.ComblockSystem implements ecs.ISystemUp
view.node.parent, // 父节点 view.node.parent, // 父节点
config.uuid, // 技能ID config.uuid, // 技能ID
new Vec3(targets[0]?.get(HeroViewComp).node.position.x, targets[0]?.get(HeroViewComp).node.position.y, 0), // 目标位置 new Vec3(targets[0]?.get(HeroViewComp).node.position.x, targets[0]?.get(HeroViewComp).node.position.y, 0), // 目标位置
targets[0]?.get(HeroViewComp),
view view
); );
caster.get(HeroViewComp).playSkillEffect(config.uuid); caster.get(HeroViewComp).playSkillEffect(config.uuid);

View File

@@ -27,7 +27,6 @@ export class Skill extends ecs.Entity {
parent: Node, // 父节点 parent: Node, // 父节点
uuid: number, // 技能ID uuid: number, // 技能ID
targetPos: Vec3, // 目标位置 targetPos: Vec3, // 目标位置
target:any=null, // 目标
caster:any=null // 施法者 caster:any=null // 施法者
) { ) {
const config = SkillSet[uuid]; const config = SkillSet[uuid];
@@ -53,7 +52,6 @@ export class Skill extends ecs.Entity {
skillComp.atk_count = 0; skillComp.atk_count = 0;
skillComp.startPos = startPos skillComp.startPos = startPos
skillComp.targetPos =targetPos skillComp.targetPos =targetPos
skillComp.target = target;
skillComp.caster = caster; skillComp.caster = caster;
skillComp.prefabName = config.sp_name; skillComp.prefabName = config.sp_name;
skillComp.group = group; skillComp.group = group;

View File

@@ -37,7 +37,6 @@ export class SkillCom extends CCComp {
animName: string = ""; animName: string = "";
group:number = 0; //阵营 group:number = 0; //阵营
fac:number=0; //阵营 fac:number=0; //阵营
target:any=null;
caster:any=null; caster:any=null;
distance_x:number=0; distance_x:number=0;
distance_y:number=0; distance_y:number=0;
@@ -58,32 +57,31 @@ export class SkillCom extends CCComp {
if (collider) { if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
} }
let dir_x = this.target.node.position.x > this.node.position.x ? 1 : -1 let dir_x = this.targetPos.x > this.node.position.x ? 1 : -1
this.node.scale = v3(dir_x,1,1) this.node.scale = v3(dir_x,1,1)
// 根据目标位置设置节点朝向 // 根据目标位置设置节点朝向
if (this.target && this.target.node) { if ( this.targetPos) {
// 计算朝向 // 计算朝向
let direction = this.target.node.position.x > this.node.position.x ? 1 : -1; let direction = this.targetPos.x > this.node.position.x ? 1 : -1;
// 设置节点缩放来改变朝向 // 设置节点缩放来改变朝向
this.node.scale = v3(direction * Math.abs(this.scale), this.scale, 1); this.node.scale = v3(direction * Math.abs(this.scale), this.scale, 1);
} }
let dir_y = (this.target.node.position.y+BoxSet.ATK_Y) > this.node.position.y ? 1 : -1 let dir_y = ( this.targetPos.y+BoxSet.ATK_Y) > this.node.position.y ? 1 : -1
if(this.target.node.position.y+BoxSet.ATK_Y==this.node.position.y){ if( this.targetPos.y+BoxSet.ATK_Y==this.node.position.y){
dir_y=0 dir_y=0
} }
// 计算这一帧的移动距离 // 计算这一帧的移动距离
this.distance_x = SkillSet[this.s_uuid].speed*dir_x; this.distance_x = SkillSet[this.s_uuid].speed*dir_x;
this.distance_y = this.distance_x*Math.abs(this.target.node.position.y-this.node.position.y)/Math.abs(this.target.node.position.x-this.node.position.x)*dir_y; this.distance_y = this.distance_x*Math.abs(this.targetPos.y-this.node.position.y)/Math.abs(this.targetPos.x-this.node.position.x)*dir_y;
this.startMovement(); this.startMovement();
// 计算目标角度 // 计算目标角度
if (this.target && this.target.node) { if (this.targetPos) {
const targetPos = this.target.node.position;
const currentPos = this.node.position; const currentPos = this.node.position;
// 计算角度(弧度) // 计算角度(弧度)
const dx = targetPos.x - currentPos.x; const dx = this.targetPos.x - currentPos.x;
const dy = (targetPos.y + BoxSet.ATK_Y) - currentPos.y; const dy = (this.targetPos.y + BoxSet.ATK_Y) - currentPos.y;
const angle = Math.atan2(dy, dx); const angle = Math.atan2(dy, dx);
// 将弧度转换为角度并设置节点旋转 // 将弧度转换为角度并设置节点旋转