refactor(hero): 优化怪物生成位置计算并添加调试日志
- 使用 MonStart 配置计算怪物出生位置,替代硬编码的 MonSet - 添加 console.log 调试英雄和怪物的 siblingIndex - 根据 y 坐标动态判断线路,提高代码可读性和可维护性
This commit is contained in:
@@ -55,7 +55,8 @@ export class Hero extends ecs.Entity {
|
||||
// 🔥 设置初始 SiblingIndex - 英雄基础层级 + 位置偏移
|
||||
const initialSiblingIndex = IndexSet.HERO;
|
||||
node.setSiblingIndex(initialSiblingIndex);
|
||||
|
||||
console.log("hero",node.getSiblingIndex());
|
||||
|
||||
// console.log("hero load",pos)
|
||||
var hv = node.getComponent(HeroViewComp)!;
|
||||
const model = this.get(HeroAttrsComp);
|
||||
|
||||
@@ -55,7 +55,7 @@ export class Monster extends ecs.Entity {
|
||||
const safeSpawnOrder = spawnOrder % 999; // 限制在999以内,避免溢出到其他层级
|
||||
const initialSiblingIndex = baseLane + safeSpawnOrder;
|
||||
node.setSiblingIndex(initialSiblingIndex);
|
||||
|
||||
console.log("mon",node.getSiblingIndex());
|
||||
var view = node.getComponent(HeroViewComp)!;
|
||||
const model = this.get(HeroAttrsComp);
|
||||
const skillsComp = this.get(HeroSkillsComp);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { _decorator, v3, Vec3 } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { Monster } from "../hero/Mon";
|
||||
import { MonSet } from "../common/config/heroSet";
|
||||
import { MonStart } from "../common/config/heroSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
// 导入肉鸽配置
|
||||
@@ -189,10 +189,15 @@ export class MissionMonCompComp extends CCComp {
|
||||
) {
|
||||
let mon = ecs.getEntity<Monster>(Monster);
|
||||
let scale = -1;
|
||||
let pos: Vec3 = v3(MonSet[i].pos);
|
||||
// 使用 MonStart 计算怪物出生位置:
|
||||
// x 从 START_X 开始,按 START_I 的间隔递增;
|
||||
// y 在线路之间交替:偶数索引为 SLINE_1,奇数索引为 SLINE_2。
|
||||
const x = MonStart.START_X + Math.floor(i / 2) * MonStart.START_I;
|
||||
const y = (i % 2 === 0) ? MonStart.SLINE_1 : MonStart.SLINE_2;
|
||||
let pos: Vec3 = v3(x, y, 0);
|
||||
|
||||
// 根据位置判断线路:y=110为一线(lane=0),y=80为二线(lane=1)
|
||||
const lane = pos.y === 130 ? 0 : 1;
|
||||
// 根据位置判断线路:y=SLINE_1 为一线(lane=0),y=SLINE_2 为二线(lane=1)
|
||||
const lane = y === MonStart.SLINE_1 ? 0 : 1;
|
||||
|
||||
// 递增全局生成顺序 - 🔥 添加溢出保护
|
||||
this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999; // 防止无限增长,在999处循环重置
|
||||
|
||||
Reference in New Issue
Block a user