|
|
@@ -100,6 +100,9 @@ export class BallController extends Component {
|
|
|
})
|
|
|
public bulletContainerPrefab: Prefab = null;
|
|
|
|
|
|
+ // 正在被拖拽的方块集合
|
|
|
+ private draggingBlocks: Set<Node> = new Set();
|
|
|
+
|
|
|
start() {
|
|
|
// 如果没有指定placedBlocksContainer,尝试找到它
|
|
|
if (!this.placedBlocksContainer) {
|
|
|
@@ -253,6 +256,12 @@ export class BallController extends Component {
|
|
|
|
|
|
// 监听子弹发射检查事件
|
|
|
eventBus.on(GameEvents.BALL_FIRE_BULLET, this.onBallFireBulletEvent, this);
|
|
|
+
|
|
|
+ // 监听方块拖拽开始事件
|
|
|
+ eventBus.on(GameEvents.BLOCK_DRAG_START, this.onBlockDragStartEvent, this);
|
|
|
+
|
|
|
+ // 监听方块拖拽结束事件
|
|
|
+ eventBus.on(GameEvents.BLOCK_DRAG_END, this.onBlockDragEndEvent, this);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -316,6 +325,38 @@ export class BallController extends Component {
|
|
|
// 如果游戏未暂停,则继续执行子弹发射逻辑
|
|
|
this.fireBulletAt(blockNode, fireWorldPos);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理方块拖拽开始事件
|
|
|
+ */
|
|
|
+ private onBlockDragStartEvent(data: { block: Node }) {
|
|
|
+ if (data && data.block) {
|
|
|
+ console.log('[BallController] 方块开始拖拽:', data.block.name, '路径:', this.getNodePath(data.block));
|
|
|
+ this.draggingBlocks.add(data.block);
|
|
|
+ console.log('[BallController] 当前拖拽方块数量:', this.draggingBlocks.size);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理方块拖拽结束事件
|
|
|
+ */
|
|
|
+ private onBlockDragEndEvent(data: { block: Node }) {
|
|
|
+ if (data && data.block) {
|
|
|
+ console.log('[BallController] 方块结束拖拽:', data.block.name, '路径:', this.getNodePath(data.block));
|
|
|
+ const wasDeleted = this.draggingBlocks.delete(data.block);
|
|
|
+ console.log('[BallController] 删除成功:', wasDeleted, '当前拖拽方块数量:', this.draggingBlocks.size);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调试方法:显示当前拖拽的方块
|
|
|
+ */
|
|
|
+ private debugDraggingBlocks() {
|
|
|
+ console.log('[BallController] 当前拖拽方块列表:');
|
|
|
+ this.draggingBlocks.forEach((block, index) => {
|
|
|
+ // console.log(` ${index + 1}. ${block.name} - 路径: ${this.getNodePath(block)} - 有效: ${block.isValid}`);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
// 计算游戏边界(使用GameArea节点)
|
|
|
calculateGameBounds() {
|
|
|
@@ -778,6 +819,29 @@ export class BallController extends Component {
|
|
|
|
|
|
// 如果是方块碰撞,检查防围困机制
|
|
|
if (isBlock) {
|
|
|
+ // 检查方块是否正在被拖拽,如果是则忽略碰撞
|
|
|
+ // 需要检查碰撞节点本身或其父节点是否在拖拽列表中
|
|
|
+ let isDragging = false;
|
|
|
+ let currentNode = otherNode;
|
|
|
+
|
|
|
+ // 向上遍历节点树,检查是否有父节点在拖拽列表中
|
|
|
+ while (currentNode && !isDragging) {
|
|
|
+ if (this.draggingBlocks.has(currentNode)) {
|
|
|
+ isDragging = true;
|
|
|
+ console.log('[BallController] 发现拖拽方块,忽略碰撞:', currentNode.name, '碰撞节点:', otherNode.name, '路径:', nodePath);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ currentNode = currentNode.parent;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isDragging) {
|
|
|
+ console.log('[BallController] 当前拖拽方块数量:', this.draggingBlocks.size);
|
|
|
+ if (contact) {
|
|
|
+ contact.disabled = true;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const ballId = ballNode.uuid;
|
|
|
const currentTime = performance.now() / 1000; // 转换为秒
|
|
|
|
|
|
@@ -1276,6 +1340,8 @@ export class BallController extends Component {
|
|
|
return path;
|
|
|
}
|
|
|
|
|
|
+ private debugDragCounter = 0;
|
|
|
+
|
|
|
update(dt: number) {
|
|
|
// 只有当小球已启动时才执行运动逻辑
|
|
|
if (!this.ballStarted || !this.initialized) {
|
|
|
@@ -1292,6 +1358,14 @@ export class BallController extends Component {
|
|
|
if (this.activeBall && this.activeBall.isValid) {
|
|
|
this.debugCheckNearBlocks();
|
|
|
}
|
|
|
+
|
|
|
+ // 定期调试拖拽状态(每5秒一次)
|
|
|
+ this.debugDragCounter += dt;
|
|
|
+ if (this.debugDragCounter >= 5.0 && this.draggingBlocks.size > 0) {
|
|
|
+ console.log('[BallController] 定期调试 - 当前拖拽状态:');
|
|
|
+ this.debugDraggingBlocks();
|
|
|
+ this.debugDragCounter = 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1590,6 +1664,9 @@ export class BallController extends Component {
|
|
|
this.ballPhaseThrough.clear();
|
|
|
this.ballDeflectionAttempts.clear();
|
|
|
|
|
|
+ // 清理拖拽方块集合
|
|
|
+ this.draggingBlocks.clear();
|
|
|
+
|
|
|
// 重置球速
|
|
|
this.updateBallSpeed();
|
|
|
|
|
|
@@ -1638,6 +1715,12 @@ export class BallController extends Component {
|
|
|
eventBus.off(GameEvents.GAME_PAUSE, this.onGamePauseEvent, this);
|
|
|
eventBus.off(GameEvents.GAME_RESUME, this.onGameResumeEvent, this);
|
|
|
eventBus.off(GameEvents.RESET_BALL_CONTROLLER, this.onResetBallControllerEvent, this);
|
|
|
+ eventBus.off(GameEvents.BALL_CREATE, this.onBallCreateEvent, this);
|
|
|
+ eventBus.off(GameEvents.BALL_START, this.onBallStartEvent, this);
|
|
|
+ eventBus.off(GameEvents.BALL_CREATE_ADDITIONAL, this.onBallCreateAdditionalEvent, this);
|
|
|
+ eventBus.off(GameEvents.BALL_FIRE_BULLET, this.onBallFireBulletEvent, this);
|
|
|
+ eventBus.off(GameEvents.BLOCK_DRAG_START, this.onBlockDragStartEvent, this);
|
|
|
+ eventBus.off(GameEvents.BLOCK_DRAG_END, this.onBlockDragEndEvent, this);
|
|
|
|
|
|
// 清理物理事件监听器
|
|
|
const physics = PhysicsManager.getInstance()?.getSystem();
|