Jelajahi Sumber

停止敌人生成

181404010226 5 bulan lalu
induk
melakukan
0e98e0ebf3

+ 0 - 3
assets/scripts/CombatSystem/BlockSelection/BlockTag.ts

@@ -19,7 +19,6 @@ export class BlockTag {
         
         // 将方块UUID添加到标签集合中
         this.taggedBlocks.add(block.uuid);
-        console.log(`[BlockTag] 为方块 ${block.name} (UUID: ${block.uuid}) 添加标签`);
     }
 
     /**
@@ -43,7 +42,6 @@ export class BlockTag {
         
         if (this.taggedBlocks.has(block.uuid)) {
             this.taggedBlocks.delete(block.uuid);
-            console.log(`[BlockTag] 移除方块 ${block.name} (UUID: ${block.uuid}) 的标签`);
         }
     }
 
@@ -53,7 +51,6 @@ export class BlockTag {
     public static clearAllTags(): void {
         const count = this.taggedBlocks.size;
         this.taggedBlocks.clear();
-        console.log(`[BlockTag] 清除了所有方块标签 (共 ${count} 个)`);
     }
 
     /**

+ 32 - 0
assets/scripts/CombatSystem/EnemyController.ts

@@ -250,6 +250,12 @@ export class EnemyController extends BaseSingleton {
 
     // 游戏开始
     startGame() {
+        // 检查游戏是否已经结束,如果结束则不开始生成敌人
+        if (this.gameManager && typeof this.gameManager.isGameOver === 'function' && this.gameManager.isGameOver()) {
+            console.log('[EnemyController] 游戏已经结束,不启动敌人生成');
+            return;
+        }
+        
         this.gameStarted = true;
         
         // 确保enemyContainer节点存在
@@ -282,6 +288,13 @@ export class EnemyController extends BaseSingleton {
     spawnEnemy() {
         if (!this.gameStarted || !this.enemyPrefab) return;
         
+        // 检查游戏是否已经结束,如果结束则不生成敌人
+        if (this.gameManager && typeof this.gameManager.isGameOver === 'function' && this.gameManager.isGameOver()) {
+            console.log('[EnemyController] 游戏已经结束,不再生成敌人');
+            this.unschedule(this.spawnEnemy); // 取消定时生成
+            return;
+        }
+        
         // 随机决定从上方还是下方生成
         const fromTop = Math.random() > 0.5;
         
@@ -444,6 +457,12 @@ export class EnemyController extends BaseSingleton {
 
     // 恢复生成敌人
     public resumeSpawning(): void {
+        // 检查游戏是否已经结束,如果结束则不恢复生成敌人
+        if (this.gameManager && typeof this.gameManager.isGameOver === 'function' && this.gameManager.isGameOver()) {
+            console.log('[EnemyController] 游戏已经结束,不恢复敌人生成');
+            return;
+        }
+        
         if (this.gameStarted) {
             this.schedule(this.spawnEnemy, this.spawnInterval);
         }
@@ -673,6 +692,12 @@ export class EnemyController extends BaseSingleton {
 
     /** 显示每波开始提示,随后开启敌人生成 */
     public showStartWavePromptUI(duration: number = 2) {
+        // 检查游戏是否已经结束,如果结束则不显示波次提示
+        if (this.gameManager && typeof this.gameManager.isGameOver === 'function' && this.gameManager.isGameOver()) {
+            console.log('[EnemyController] 游戏已经结束,不显示波次提示');
+            return;
+        }
+        
         if (!this.startWaveUI) return;
         this.startWaveUI.active = true;
         // 暂停生成(确保未重复)
@@ -680,6 +705,13 @@ export class EnemyController extends BaseSingleton {
         if (duration > 0) {
             this.scheduleOnce(() => {
                 if (this.startWaveUI) this.startWaveUI.active = false;
+                
+                // 再次检查游戏是否已经结束,如果结束则不开始生成敌人
+                if (this.gameManager && typeof this.gameManager.isGameOver === 'function' && this.gameManager.isGameOver()) {
+                    console.log('[EnemyController] 游戏已经结束,不启动敌人生成(延时检查)');
+                    return;
+                }
+                
                 // 真正开始/恢复生成敌人
                 this.startGame();
             }, duration);

+ 23 - 3
assets/scripts/CombatSystem/GamePause.ts

@@ -92,8 +92,14 @@ export class GamePause extends Component {
         // 恢复敌人
         this.resumeAllEnemies();
 
-        // 恢复敌人生成
-        this.resumeEnemySpawning();
+        // 检查游戏是否已经结束,如果结束则不恢复敌人生成
+        const gameManager = find('Canvas/GameManager')?.getComponent('GameManager');
+        if (gameManager && typeof (gameManager as any).isGameOver === 'function' && (gameManager as any).isGameOver()) {
+            console.log('[GamePause] 游戏已经结束,不恢复敌人生成');
+        } else {
+            // 恢复敌人生成
+            this.resumeEnemySpawning();
+        }
 
         // 恢复小球(如果之前被暂停的话)
         this.resumeAllBalls();
@@ -257,7 +263,21 @@ export class GamePause extends Component {
      * 游戏结束时的处理
      */
     private onGameEnd(): void {
-        this.pauseGame();
+        console.log('GamePause: 游戏结束,确保停止敌人生成');
+        
+        // 停止敌人生成
+        const enemyController = EnemyController.getInstance();
+        if (enemyController) {
+            // 确保停止生成敌人
+            enemyController.unschedule(enemyController.spawnEnemy);
+            console.log('GamePause: 游戏结束,已取消敌人生成定时器');
+        }
+        
+        // 设置为暂停状态
+        this.currentState = PauseState.PAUSED;
+        
+        // 禁用子弹发射
+        this.bulletFireEnabled = false;
     }
 
     /**

+ 6 - 0
assets/scripts/LevelSystem/GameManager.ts

@@ -473,6 +473,12 @@ export class GameManager extends Component {
 
         this.currentState = GameState.SUCCESS;
 
+        // 确保停止敌人生成
+        if (this.enemyController) {
+            this.enemyController.stopGame(false); // 停止游戏但不清除敌人
+            console.log('[GameManager] 游戏成功,已停止敌人生成');
+        }
+
         this.pauseGame();
 
         if (this.gameSuccessUI) {