|
|
@@ -110,6 +110,15 @@ export class BallController extends Component {
|
|
|
|
|
|
// 监听重置球控制器事件
|
|
|
eventBus.on(GameEvents.RESET_BALL_CONTROLLER, this.onResetBallControllerEvent, this);
|
|
|
+
|
|
|
+ // 监听球创建事件
|
|
|
+ eventBus.on(GameEvents.BALL_CREATE, this.onBallCreateEvent, this);
|
|
|
+
|
|
|
+ // 监听球启动事件
|
|
|
+ eventBus.on(GameEvents.BALL_START, this.onBallStartEvent, this);
|
|
|
+
|
|
|
+ // 监听创建额外球事件
|
|
|
+ eventBus.on(GameEvents.BALL_CREATE_ADDITIONAL, this.onBallCreateAdditionalEvent, this);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -139,6 +148,30 @@ export class BallController extends Component {
|
|
|
console.log('[BallController] 接收到重置球控制器事件');
|
|
|
this.resetBallController();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理球创建事件
|
|
|
+ */
|
|
|
+ private onBallCreateEvent() {
|
|
|
+ console.log('[BallController] 接收到球创建事件');
|
|
|
+ this.createBall();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理球启动事件
|
|
|
+ */
|
|
|
+ private onBallStartEvent() {
|
|
|
+ console.log('[BallController] 接收到球启动事件');
|
|
|
+ this.startBall();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理创建额外球事件
|
|
|
+ */
|
|
|
+ private onBallCreateAdditionalEvent() {
|
|
|
+ console.log('[BallController] 接收到创建额外球事件');
|
|
|
+ this.createAdditionalBall();
|
|
|
+ }
|
|
|
|
|
|
// 计算游戏边界(使用GameArea节点)
|
|
|
calculateGameBounds() {
|
|
|
@@ -171,19 +204,24 @@ export class BallController extends Component {
|
|
|
// 创建小球
|
|
|
createBall() {
|
|
|
if (!this.ballPrefab) {
|
|
|
+ console.error('[BallController] ballPrefab 未设置,无法创建小球');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 实例化小球
|
|
|
this.activeBall = instantiate(this.ballPrefab);
|
|
|
|
|
|
+ if (!this.activeBall) {
|
|
|
+ console.error('[BallController] 小球实例化失败');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 将小球添加到GameArea中
|
|
|
const gameArea = find('Canvas/GameLevelUI/GameArea');
|
|
|
if (gameArea) {
|
|
|
gameArea.addChild(this.activeBall);
|
|
|
} else {
|
|
|
+ console.warn('[BallController] 未找到GameArea,将小球添加到当前节点');
|
|
|
this.node.addChild(this.activeBall);
|
|
|
}
|
|
|
|
|
|
@@ -957,6 +995,11 @@ export class BallController extends Component {
|
|
|
|
|
|
// 启动小球 - 公开方法,在确定按钮点击后调用
|
|
|
public startBall() {
|
|
|
+ // 检查ballPrefab是否设置
|
|
|
+ if (!this.ballPrefab) {
|
|
|
+ console.error('[BallController] ballPrefab 未设置,无法创建小球');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
// 如果还没有初始化,先初始化
|
|
|
if (!this.initialized) {
|
|
|
@@ -968,6 +1011,12 @@ export class BallController extends Component {
|
|
|
this.createBall();
|
|
|
}
|
|
|
|
|
|
+ // 检查小球是否成功创建
|
|
|
+ if (!this.activeBall) {
|
|
|
+ console.error('[BallController] 小球创建失败');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 重新定位小球,避免与方块重叠
|
|
|
this.positionBallRandomly();
|
|
|
|
|
|
@@ -979,6 +1028,8 @@ export class BallController extends Component {
|
|
|
|
|
|
// 设置运动状态
|
|
|
this.ballStarted = true;
|
|
|
+
|
|
|
+ console.log('[BallController] 小球启动完成');
|
|
|
}
|
|
|
|
|
|
/**
|