Merge branch 'card' of git.eoxnet.com:pan/pixelheros into card

This commit is contained in:
walkpan
2026-05-12 19:56:24 +08:00

View File

@@ -263,7 +263,10 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
private moveToSlot(view: HeroViewComp, move: MoveComp, model: HeroAttrsComp, targetX: number) {
const currentX = view.node.position.x;
if (Math.abs(currentX - targetX) <= 2) {
const currentY = view.node.position.y;
// 当 X 和 Y 都到达目标时,才算真正到达
if (Math.abs(currentX - targetX) <= 2 && Math.abs(currentY - move.baseY) <= 2) {
view.node.setPosition(targetX, move.baseY, 0);
view.status_change("idle");
return;
@@ -283,14 +286,25 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
const moveMinX = Math.min(cfg.moveBackX, cfg.moveFrontX);
const moveMaxX = Math.max(cfg.moveBackX, cfg.moveFrontX);
const currentX = view.node.position.x;
const currentY = view.node.position.y;
const delta = speed * this.dt * direction;
let newX = view.node.position.x + delta;
if (currentX < moveMinX && direction < 0) {
// X 轴到底了,如果 Y 轴还在换路,继续维持 move 状态
if (Math.abs(currentY - move.baseY) > 2) {
view.status_change("move");
} else {
view.status_change("idle");
}
return;
}
if (currentX > moveMaxX && direction > 0) {
if (Math.abs(currentY - move.baseY) > 2) {
view.status_change("move");
} else {
view.status_change("idle");
}
return;
}
newX = Math.max(moveMinX, Math.min(moveMaxX, newX));
@@ -299,10 +313,15 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
newX = direction > 0 ? Math.min(newX, stopAtX) : Math.max(newX, stopAtX);
}
if (Math.abs(newX - currentX) < 0.01) {
// X轴虽然没变化但如果Y轴还在移动依然是move状态
if (Math.abs(currentY - move.baseY) > 2) {
view.status_change("move");
} else {
view.status_change("idle");
}
return;
}
view.node.setPosition(newX, move.baseY, 0);
view.node.setPosition(newX, view.node.position.y, 0); // 注意:这里只更新 XY 在外部平滑逻辑更新
view.status_change("move");
}