|
|
@@ -84,15 +84,10 @@ export class InGameManager extends Component {
|
|
|
public bottomFenceNode: Node = null;
|
|
|
|
|
|
// === 游戏配置属性 ===
|
|
|
- @property({
|
|
|
- tooltip: '状态检查间隔(秒)'
|
|
|
- })
|
|
|
- public checkInterval: number = 1.0;
|
|
|
|
|
|
// === 私有属性 ===
|
|
|
private gameStarted: boolean = false;
|
|
|
private currentState: GameState = GameState.PLAYING;
|
|
|
- private checkTimer: number = 0;
|
|
|
// EnemyController现在通过事件系统通信,不再直接引用
|
|
|
private enemySpawningStarted: boolean = false;
|
|
|
private totalEnemiesSpawned: number = 0;
|
|
|
@@ -199,25 +194,13 @@ export class InGameManager extends Component {
|
|
|
Audio.stopMusic();
|
|
|
}
|
|
|
|
|
|
- update(deltaTime: number) {
|
|
|
- if (this.currentState !== GameState.PLAYING) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.checkTimer += deltaTime;
|
|
|
-
|
|
|
- if (this.checkTimer >= this.checkInterval) {
|
|
|
- this.checkTimer = 0;
|
|
|
- this.checkGameState();
|
|
|
- }
|
|
|
- }
|
|
|
+ update(deltaTime: number) { }
|
|
|
|
|
|
/**
|
|
|
* 初始化游戏状态
|
|
|
*/
|
|
|
private initializeGameState() {
|
|
|
this.currentState = GameState.PLAYING;
|
|
|
- this.checkTimer = 0;
|
|
|
this.enemySpawningStarted = false;
|
|
|
this.totalEnemiesSpawned = 0;
|
|
|
this.currentWave = 1;
|
|
|
@@ -489,18 +472,19 @@ export class InGameManager extends Component {
|
|
|
|
|
|
if (isWaveEnd) {
|
|
|
console.log(`[InGameManager] 波次结束检测: remaining=${remaining}`);
|
|
|
-
|
|
|
- // 如果能量已满,设置等待方块选择状态
|
|
|
- if (energyWillBeFull) {
|
|
|
+
|
|
|
+ const isLastWave = this.currentWave >= (this.levelWaves?.length || 1);
|
|
|
+ if (isLastWave) {
|
|
|
+ // 最后一波结束,立即触发胜利(不受能量满影响)
|
|
|
+ this.triggerGameSuccess();
|
|
|
+ } else if (energyWillBeFull) {
|
|
|
+ // 非最后一波且能量已满,进入方块选择并准备下一波
|
|
|
this.pendingBlockSelection = true;
|
|
|
this.preparingNextWave = true;
|
|
|
this.currentState = GameState.BLOCK_SELECTION;
|
|
|
} else {
|
|
|
- if (this.currentWave < (this.levelWaves?.length || 1)) {
|
|
|
- this.showNextWavePrompt();
|
|
|
- } else {
|
|
|
- this.triggerGameSuccess();
|
|
|
- }
|
|
|
+ // 非最后一波且能量未满,显示下一波提示
|
|
|
+ this.showNextWavePrompt();
|
|
|
}
|
|
|
} else if (energyWillBeFull) {
|
|
|
// 如果波次未结束但能量已满,设置状态为方块选择
|
|
|
@@ -550,41 +534,9 @@ export class InGameManager extends Component {
|
|
|
// 这种情况下,pendingBlockSelection已经在onEnemyKilledEvent中设置为true
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 游戏状态检查
|
|
|
- * 现在只检查敌人击败状态,墙体摧毁直接触发GAME_DEFEAT事件
|
|
|
- */
|
|
|
- private checkGameState() {
|
|
|
- // 如果游戏已经结束,不再进行状态检查
|
|
|
- if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 墙体摧毁检查已移除,因为墙体现在直接触发GAME_DEFEAT事件
|
|
|
- // 这样与菜单退出的失败处理流程保持一致
|
|
|
-
|
|
|
- if (this.checkAllEnemiesDefeated()) {
|
|
|
- this.triggerGameSuccess();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查所有敌人是否被击败
|
|
|
- */
|
|
|
- private checkAllEnemiesDefeated(): boolean {
|
|
|
- // 如果敌人生成还未开始,不进行胜利检查
|
|
|
- if (!this.enemySpawningStarted) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- // 基于当前波次的敌人击杀数量判断是否胜利
|
|
|
- // 如果当前波次的剩余敌人数量为0,且是最后一波,则胜利
|
|
|
- const currentWaveRemaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
|
|
|
- const isLastWave = this.currentWave >= (this.levelWaves?.length || 1);
|
|
|
-
|
|
|
- return currentWaveRemaining <= 0 && isLastWave;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 触发游戏成功
|
|
|
@@ -1106,7 +1058,6 @@ export class InGameManager extends Component {
|
|
|
this.shouldShowNextWavePrompt = false;
|
|
|
this.gameStartTime = 0;
|
|
|
this.gameEndTime = 0;
|
|
|
- this.checkTimer = 0;
|
|
|
console.log('[InGameManager] 游戏状态重置完成');
|
|
|
}
|
|
|
|