|
|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, Component, Node, Prefab, instantiate, Vec3, find, director, Canvas, UITransform, Button, Label, EPhysics2DDrawFlags, sys } from 'cc';
|
|
|
+import { _decorator, Component, Node, Prefab, instantiate, Vec3, find, director, Canvas, UITransform, Button, Label, ProgressBar, EPhysics2DDrawFlags, sys } from 'cc';
|
|
|
import { LevelManager } from './LevelManager';
|
|
|
import { LevelConfigManager } from './LevelConfigManager';
|
|
|
import { SaveDataManager } from './SaveDataManager';
|
|
|
@@ -74,6 +74,19 @@ export class GameManager extends Component {
|
|
|
})
|
|
|
public gameDefeatUI: Node = null;
|
|
|
|
|
|
+ // === 能量与技能选择 UI ===
|
|
|
+ @property({
|
|
|
+ type: Node,
|
|
|
+ tooltip: '拖拽 EnergyBar (ProgressBar) 节点到这里'
|
|
|
+ })
|
|
|
+ public energyBarNode: Node = null;
|
|
|
+
|
|
|
+ @property({
|
|
|
+ type: Node,
|
|
|
+ tooltip: '拖拽 SelectSkillUI 节点到这里'
|
|
|
+ })
|
|
|
+ public selectSkillUI: Node = null;
|
|
|
+
|
|
|
// === 游戏配置属性 ===
|
|
|
// 墙体基础血量由存档决定,不再通过属性面板设置
|
|
|
private wallHealth: number = 100;
|
|
|
@@ -121,6 +134,13 @@ export class GameManager extends Component {
|
|
|
bottom: 0
|
|
|
};
|
|
|
|
|
|
+ private preparingNextWave = false;
|
|
|
+
|
|
|
+ // 能量系统
|
|
|
+ private energyPoints: number = 0;
|
|
|
+ private readonly ENERGY_MAX: number = 5;
|
|
|
+ private energyBar: ProgressBar = null;
|
|
|
+
|
|
|
start() {
|
|
|
// 初始化物理系统
|
|
|
this.initPhysicsSystem();
|
|
|
@@ -275,6 +295,27 @@ export class GameManager extends Component {
|
|
|
if (this.gameDefeatUI) {
|
|
|
this.gameDefeatUI.active = false;
|
|
|
}
|
|
|
+
|
|
|
+ // 查找能量条
|
|
|
+ if (!this.energyBarNode) {
|
|
|
+ this.energyBarNode = find('Canvas/GameLevelUI/EnergyBar');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.energyBarNode) {
|
|
|
+ this.energyBar = this.energyBarNode.getComponent(ProgressBar);
|
|
|
+ if (this.energyBar) {
|
|
|
+ this.energyBar.progress = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找技能选择 UI
|
|
|
+ if (!this.selectSkillUI) {
|
|
|
+ this.selectSkillUI = find('Canvas/SelectSkillUI');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.selectSkillUI) {
|
|
|
+ this.selectSkillUI.active = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// === 查找敌人控制器 ===
|
|
|
@@ -442,7 +483,7 @@ export class GameManager extends Component {
|
|
|
}
|
|
|
|
|
|
// === 恢复游戏 ===
|
|
|
- private resumeGame() {
|
|
|
+ public resumeGame() {
|
|
|
this.currentState = GameState.PLAYING;
|
|
|
this.gameStarted = true;
|
|
|
|
|
|
@@ -705,17 +746,24 @@ export class GameManager extends Component {
|
|
|
|
|
|
// === 原GameManager方法 ===
|
|
|
public onConfirmButtonClicked() {
|
|
|
- if (this.blockSelectionUI) {
|
|
|
- this.blockSelectionUI.active = false;
|
|
|
-
|
|
|
- const gridContainer = find('Canvas/GameLevelUI/GameArea/GridContainer');
|
|
|
- if (gridContainer) {
|
|
|
- gridContainer.active = true;
|
|
|
- }
|
|
|
-
|
|
|
- this.preservePlacedBlocks();
|
|
|
+ if (this.blockSelectionUI) this.blockSelectionUI.active = false;
|
|
|
+
|
|
|
+ if (this.preparingNextWave) {
|
|
|
+ // 进入下一波
|
|
|
+ this.preparingNextWave = false;
|
|
|
+ this.enemyController.showStartWavePromptUI(); // 弹 startWaveUI 后自动 startGame()
|
|
|
+ this.nextWave(); // 更新 wave 计数 & total
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ // ---------- 首波逻辑(原有代码) ----------
|
|
|
+ const gridContainer = find('Canvas/GameLevelUI/GameArea/GridContainer');
|
|
|
+ if (gridContainer) {
|
|
|
+ gridContainer.active = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.preservePlacedBlocks();
|
|
|
+
|
|
|
this.startGame();
|
|
|
}
|
|
|
|
|
|
@@ -799,7 +847,16 @@ export class GameManager extends Component {
|
|
|
this.enemiesKilled = 0;
|
|
|
this.currentWave = 1;
|
|
|
this.currentWaveEnemyCount = 0;
|
|
|
-
|
|
|
+
|
|
|
+ // 重置能量条
|
|
|
+ this.energyPoints = 0;
|
|
|
+ if (this.energyBar) {
|
|
|
+ this.energyBar.progress = 0;
|
|
|
+ }
|
|
|
+ if (this.selectSkillUI) {
|
|
|
+ this.selectSkillUI.active = false;
|
|
|
+ }
|
|
|
+
|
|
|
// 关闭胜利/失败界面,确保重新进入时是正常状态
|
|
|
if (this.gameSuccessUI) {
|
|
|
this.gameSuccessUI.active = false;
|
|
|
@@ -969,6 +1026,9 @@ export class GameManager extends Component {
|
|
|
const firstWaveEnemies = this.levelWaves.length > 0 && this.levelWaves[0].enemies ?
|
|
|
this.levelWaves[0].enemies.reduce((t: number, g: any) => t + (g.count || 0), 0) : 0;
|
|
|
this.enemyController.startWave(1, totalWaves, firstWaveEnemies);
|
|
|
+
|
|
|
+ // 同步 GameManager 当前波敌人数,避免剩余敌人数计算出错
|
|
|
+ this.setCurrentWave(1, firstWaveEnemies);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1063,13 +1123,7 @@ export class GameManager extends Component {
|
|
|
|
|
|
/** 显示下一波提示并在短暂延迟后开始下一波 */
|
|
|
private showNextWavePrompt() {
|
|
|
- if (this.enemyController && this.enemyController.showStartWavePromptUI) {
|
|
|
- this.enemyController.showStartWavePromptUI();
|
|
|
- }
|
|
|
- // 2 秒后开始下一波
|
|
|
- this.scheduleOnce(() => {
|
|
|
- this.nextWave();
|
|
|
- }, 2);
|
|
|
+ this.openBlockSelectionUIForNextWave(); // 只打开布阵,不弹 StartWaveUI
|
|
|
}
|
|
|
|
|
|
/** 敌人被消灭时由 EnemyController 调用 */
|
|
|
@@ -1077,6 +1131,9 @@ export class GameManager extends Component {
|
|
|
this.enemiesKilled++;
|
|
|
// 当前波击杀 +1
|
|
|
this.currentWaveEnemyCount++;
|
|
|
+
|
|
|
+ // 增加能量点
|
|
|
+ this.incrementEnergy();
|
|
|
|
|
|
const remaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
|
|
|
if (remaining <= 0) {
|
|
|
@@ -1091,6 +1148,38 @@ export class GameManager extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 每击杀敌人调用,能量 +1,并更新进度条。满值时弹出技能选择界面 */
|
|
|
+ private incrementEnergy() {
|
|
|
+ this.energyPoints = Math.min(this.energyPoints + 1, this.ENERGY_MAX);
|
|
|
+ this.updateEnergyBar();
|
|
|
+
|
|
|
+ if (this.energyPoints >= this.ENERGY_MAX) {
|
|
|
+ this.onEnergyFull();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 更新能量条显示 */
|
|
|
+ private updateEnergyBar() {
|
|
|
+ if (this.energyBar) {
|
|
|
+ this.energyBar.progress = this.energyPoints / this.ENERGY_MAX;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 能量满时触发 */
|
|
|
+ private onEnergyFull() {
|
|
|
+ if (this.selectSkillUI && !this.selectSkillUI.active) {
|
|
|
+ // 暂停游戏后再弹出 UI
|
|
|
+ this.pauseGame();
|
|
|
+ this.selectSkillUI.active = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 供外部调用:重置能量值并刷新显示 */
|
|
|
+ public resetEnergy() {
|
|
|
+ this.energyPoints = 0;
|
|
|
+ this.updateEnergyBar();
|
|
|
+ }
|
|
|
+
|
|
|
/* ========= 墙体血量 / 等级相关 ========= */
|
|
|
|
|
|
private wallHpMap: Record<number, number> = {
|
|
|
@@ -1146,4 +1235,12 @@ export class GameManager extends Component {
|
|
|
nextHp: this.getWallHealthByLevel(newLvl + 1)
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ private openBlockSelectionUIForNextWave() {
|
|
|
+ if (this.blockSelectionUI) this.blockSelectionUI.active = true;
|
|
|
+ const grid = find('Canvas/GameLevelUI/GameArea/GridContainer');
|
|
|
+ if (grid) grid.active = true;
|
|
|
+ this.preparingNextWave = true;
|
|
|
+ this.enemyController.pauseSpawning(); // 保险
|
|
|
+ }
|
|
|
}
|