IN_game.ts 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. import { _decorator, Component, Node, Label, ProgressBar, find } from 'cc';
  2. import EventBus, { GameEvents } from '../Core/EventBus';
  3. import { GameBlockSelection } from '../CombatSystem/BlockSelection/GameBlockSelection';
  4. import { Wall } from '../CombatSystem/Wall';
  5. import { GameStartMove } from '../Animations/GameStartMove';
  6. import { LevelSessionManager } from '../Core/LevelSessionManager';
  7. import { SaveDataManager } from './SaveDataManager';
  8. import { SkillManager } from '../CombatSystem/SkillSelection/SkillManager';
  9. import { StartGame } from './StartGame';
  10. import { BackgroundManager } from './BackgroundManager';
  11. import { GroundBurnAreaManager } from '../CombatSystem/BulletEffects/GroundBurnAreaManager';
  12. import { ScreenShakeManager } from '../CombatSystem/EnemyWeapon/ScreenShakeManager';
  13. const { ccclass, property } = _decorator;
  14. /**
  15. * 游戏内状态枚举
  16. * 仅在 AppState.IN_GAME 时使用
  17. */
  18. export enum GameState {
  19. PLAYING = 'playing',
  20. SUCCESS = 'success',
  21. DEFEAT = 'defeat',
  22. PAUSED = 'paused',
  23. BLOCK_SELECTION = 'block_selection'
  24. }
  25. /**
  26. * 游戏内状态管理器
  27. * 负责管理游戏进行中的所有状态和逻辑
  28. */
  29. @ccclass('InGameManager')
  30. export class InGameManager extends Component {
  31. // === 游戏内UI节点引用 ===
  32. @property({
  33. type: Node,
  34. tooltip: '拖拽BallController节点到这里'
  35. })
  36. public ballController: Node = null;
  37. @property({
  38. type: Node,
  39. tooltip: '拖拽GameBlockSelection节点到这里'
  40. })
  41. public gameBlockSelection: Node = null;
  42. @property({
  43. type: Node,
  44. tooltip: '拖拽GameArea节点到这里'
  45. })
  46. public gameArea: Node = null;
  47. @property({
  48. type: Node,
  49. tooltip: '拖拽EnemyController节点到这里'
  50. })
  51. public enemyManager: Node = null;
  52. @property({
  53. type: Node,
  54. tooltip: '摄像机节点,用于获取GameStartMove组件'
  55. })
  56. public cameraNode: Node = null;
  57. @property({
  58. type: Node,
  59. tooltip: '墙体节点,用于获取Wall组件'
  60. })
  61. public wallNode: Node = null;
  62. @property({
  63. type: Node,
  64. tooltip: '上围栏墙体节点 (TopFence)'
  65. })
  66. public topFenceNode: Node = null;
  67. @property({
  68. type: Node,
  69. tooltip: '下围栏墙体节点 (BottomFence)'
  70. })
  71. public bottomFenceNode: Node = null;
  72. // === 游戏配置属性 ===
  73. @property({
  74. tooltip: '状态检查间隔(秒)'
  75. })
  76. public checkInterval: number = 1.0;
  77. // === 私有属性 ===
  78. private gameStarted: boolean = false;
  79. private currentState: GameState = GameState.PLAYING;
  80. private checkTimer: number = 0;
  81. // EnemyController现在通过事件系统通信,不再直接引用
  82. private enemySpawningStarted: boolean = false;
  83. private totalEnemiesSpawned: number = 0;
  84. private currentWave: number = 1;
  85. private currentWaveEnemyCount: number = 0;
  86. private currentWaveTotalEnemies: number = 0;
  87. public levelWaves: any[] = [];
  88. private levelTotalEnemies: number = 0;
  89. private enemiesKilled: number = 0;
  90. // === 背景管理器组件 ===
  91. private backgroundManager: BackgroundManager = null;
  92. // === 地面燃烧区域管理器 ===
  93. private groundBurnAreaManager: GroundBurnAreaManager = null;
  94. // 游戏计时器
  95. private gameStartTime: number = 0;
  96. private gameEndTime: number = 0;
  97. // 游戏区域的边界
  98. private gameBounds = {
  99. left: 0,
  100. right: 0,
  101. top: 0,
  102. bottom: 0
  103. };
  104. private preparingNextWave = false;
  105. // 能量系统
  106. private energyPoints: number = 0;
  107. private energyMax: number = 0; // 必须从关卡配置中读取
  108. private energyBar: ProgressBar = null;
  109. private selectSkillUI: Node = null;
  110. // 新增:能量条升级系统
  111. private energyUpgradeCount: number = 0; // 当前能量条升级次数
  112. private energyMaxUpgrades: number[] = []; // 每次升级后的最大值配置
  113. // 能量条UI节点
  114. @property({
  115. type: Node,
  116. tooltip: '拖拽能量条节点到这里 (Canvas/GameLevelUI/EnergyBar)'
  117. })
  118. public energyBarNode: Node = null;
  119. // 技能选择UI节点
  120. @property({
  121. type: Node,
  122. tooltip: '拖拽技能选择UI节点到这里 (Canvas/GameLevelUI/SelectSkillUI)'
  123. })
  124. public selectSkillUINode: Node = null;
  125. // === 背景管理器 ===
  126. @property({
  127. type: Node,
  128. tooltip: '拖拽BackgroundManager节点到这里'
  129. })
  130. public backgroundManagerNode: Node = null;
  131. @property({
  132. type: Node,
  133. tooltip: '拖拽GroundBurnAreaManager节点到这里'
  134. })
  135. public groundBurnAreaManagerNode: Node = null;
  136. // GameBlockSelection组件
  137. private blockSelectionComponent: GameBlockSelection = null;
  138. private pendingSkillSelection: boolean = false;
  139. private pendingBlockSelection: boolean = false;
  140. private shouldShowNextWavePrompt: boolean = false;
  141. // 墙体组件引用
  142. private wallComponent: Wall = null;
  143. private topFenceComponent: Wall = null;
  144. private bottomFenceComponent: Wall = null;
  145. // GameStartMove组件引用
  146. private gameStartMoveComponent: GameStartMove = null;
  147. start() {
  148. this.initializeGameState();
  149. this.setupEventListeners();
  150. this.initGameBlockSelection();
  151. this.initGameStartMove();
  152. this.initWallComponent();
  153. this.initUINodes();
  154. this.initScreenShakeManager();
  155. }
  156. update(deltaTime: number) {
  157. if (this.currentState !== GameState.PLAYING) {
  158. return;
  159. }
  160. this.checkTimer += deltaTime;
  161. if (this.checkTimer >= this.checkInterval) {
  162. this.checkTimer = 0;
  163. this.checkGameState();
  164. }
  165. }
  166. /**
  167. * 初始化游戏状态
  168. */
  169. private initializeGameState() {
  170. this.currentState = GameState.PLAYING;
  171. this.checkTimer = 0;
  172. this.enemySpawningStarted = false;
  173. this.totalEnemiesSpawned = 0;
  174. this.currentWave = 1;
  175. this.currentWaveEnemyCount = 0;
  176. this.currentWaveTotalEnemies = 0;
  177. this.energyPoints = 0;
  178. this.pendingSkillSelection = false;
  179. }
  180. /**
  181. * 设置事件监听器
  182. */
  183. private setupEventListeners() {
  184. const eventBus = EventBus.getInstance();
  185. eventBus.on(GameEvents.GAME_SUCCESS, this.onGameSuccessEvent, this);
  186. eventBus.on(GameEvents.GAME_DEFEAT, this.onGameDefeatEvent, this);
  187. eventBus.on(GameEvents.GAME_RESUME, this.onGameResumeEvent, this);
  188. eventBus.on(GameEvents.GAME_RESUME_SKILL_SELECTION, this.onGameResumeEvent, this);
  189. eventBus.on(GameEvents.GAME_RESUME_BLOCK_SELECTION, this.onGameResumeEvent, this);
  190. eventBus.on('ENEMY_KILLED', this.onEnemyKilledEvent, this);
  191. eventBus.on(GameEvents.RESET_ENERGY_SYSTEM, this.resetEnergySystem, this);
  192. eventBus.on(GameEvents.WALL_DESTROYED, this.onWallDestroyedEvent, this);
  193. }
  194. /**
  195. * 初始化GameBlockSelection组件
  196. */
  197. private initGameBlockSelection() {
  198. if (this.gameBlockSelection) {
  199. this.blockSelectionComponent = this.gameBlockSelection.getComponent(GameBlockSelection);
  200. }
  201. }
  202. /**
  203. * 初始化GameStartMove组件
  204. */
  205. private initGameStartMove() {
  206. if (this.cameraNode) {
  207. this.gameStartMoveComponent = this.cameraNode.getComponent(GameStartMove);
  208. }
  209. }
  210. /**
  211. * EnemyController现在通过事件系统通信,不再需要直接初始化
  212. */
  213. /**
  214. * 初始化墙体组件
  215. */
  216. private initWallComponent() {
  217. // 初始化主墙体
  218. if (this.wallNode) {
  219. this.wallComponent = this.wallNode.getComponent(Wall);
  220. if (this.wallComponent) {
  221. console.log('[InGameManager] 主墙体组件初始化成功');
  222. } else {
  223. console.warn('[InGameManager] 未找到主墙体Wall组件');
  224. }
  225. } else {
  226. console.warn('[InGameManager] 主墙体节点未通过装饰器挂载');
  227. }
  228. // 初始化上围栏
  229. if (this.topFenceNode) {
  230. this.topFenceComponent = this.topFenceNode.getComponent(Wall);
  231. if (this.topFenceComponent) {
  232. console.log('[InGameManager] 上围栏墙体组件初始化成功');
  233. } else {
  234. console.warn('[InGameManager] 未找到上围栏Wall组件');
  235. }
  236. } else {
  237. console.warn('[InGameManager] 上围栏节点未通过装饰器挂载');
  238. }
  239. // 初始化下围栏
  240. if (this.bottomFenceNode) {
  241. this.bottomFenceComponent = this.bottomFenceNode.getComponent(Wall);
  242. if (this.bottomFenceComponent) {
  243. console.log('[InGameManager] 下围栏墙体组件初始化成功');
  244. } else {
  245. console.warn('[InGameManager] 未找到下围栏Wall组件');
  246. }
  247. } else {
  248. console.warn('[InGameManager] 下围栏节点未通过装饰器挂载');
  249. }
  250. }
  251. /**
  252. * 初始化ScreenShakeManager
  253. */
  254. private initScreenShakeManager() {
  255. if (this.cameraNode) {
  256. ScreenShakeManager.getInstance().initialize(this.cameraNode);
  257. console.log('[InGameManager] ScreenShakeManager初始化成功');
  258. } else {
  259. console.warn('[InGameManager] 相机节点未设置,ScreenShakeManager初始化失败');
  260. }
  261. }
  262. /**
  263. * 获取指定波次的敌人配置
  264. */
  265. private getWaveEnemyConfigs(wave: number): any[] {
  266. if (!this.levelWaves || wave < 1 || wave > this.levelWaves.length) {
  267. return [];
  268. }
  269. const waveConfig = this.levelWaves[wave - 1];
  270. return waveConfig?.enemies || [];
  271. }
  272. /**
  273. * 检查是否应该播放diban动画
  274. */
  275. public shouldPlayDibanAnimation(): boolean {
  276. return this.preparingNextWave && this.currentState === GameState.BLOCK_SELECTION;
  277. }
  278. /**
  279. * 技能选择完成后的处理
  280. */
  281. public onSkillSelectionComplete() {
  282. console.log('[InGameManager] 技能选择完成');
  283. // 关闭技能选择UI
  284. if (this.selectSkillUI) {
  285. this.selectSkillUI.active = false;
  286. console.log('[InGameManager] 技能选择UI已关闭');
  287. }
  288. // 恢复游戏
  289. this.resumeGame();
  290. // 发射技能选择结束恢复事件
  291. EventBus.getInstance().emit(GameEvents.GAME_RESUME_SKILL_SELECTION);
  292. // 如果有等待的diban动画,现在播放diban动画
  293. if (this.pendingBlockSelection) {
  294. console.log('[InGameManager] 技能选择完成,现在播放diban动画');
  295. this.playDibanAnimationAfterSkill();
  296. }
  297. }
  298. /**
  299. * 在技能选择后播放diban动画
  300. */
  301. public playDibanAnimationAfterSkill() {
  302. if (this.pendingBlockSelection) {
  303. console.log('[InGameManager] 技能选择完成,现在播放diban动画');
  304. this.pendingBlockSelection = false;
  305. if (this.currentWave < (this.levelWaves?.length || 1)) {
  306. this.playDibanAnimationForNextWave();
  307. } else {
  308. console.log('[InGameManager] 最后一波结束,触发游戏胜利');
  309. this.triggerGameSuccess();
  310. }
  311. } else if (this.shouldPlayDibanAnimation()) {
  312. this.playDibanAnimationForNextWave();
  313. }
  314. }
  315. /**
  316. * 播放下一波diban动画
  317. */
  318. private playDibanAnimationForNextWave() {
  319. // 如果游戏已经结束,不播放diban动画
  320. if (this.isGameOver()) {
  321. console.warn('[InGameManager] 游戏已经结束(胜利或失败),不播放下一波diban动画!');
  322. return;
  323. }
  324. console.log('[InGameManager] 播放diban动画');
  325. // 生成方块选择(不显示UI)
  326. if (this.blockSelectionComponent) {
  327. this.blockSelectionComponent.generateBlockSelection();
  328. }
  329. // 使用GameStartMove组件播放diban上滑动画和镜头下移动画
  330. if (this.gameStartMoveComponent) {
  331. console.log('[InGameManager] 调用GameStartMove组件播放diban上滑动画');
  332. this.gameStartMoveComponent.slideUpFromBottom(0.3);
  333. } else {
  334. console.warn('[InGameManager] GameStartMove组件未找到,无法播放diban动画');
  335. }
  336. // 使用底板选择专用暂停事件,小球继续运动
  337. EventBus.getInstance().emit(GameEvents.GAME_PAUSE_BLOCK_SELECTION);
  338. }
  339. /**
  340. * 处理游戏成功事件
  341. */
  342. private onGameSuccessEvent() {
  343. console.log('[InGameManager] 接收到游戏成功事件');
  344. this.currentState = GameState.SUCCESS;
  345. // 游戏结束时进入暂停状态,停止所有游戏对象的行为
  346. console.log('[InGameManager] 游戏成功,触发游戏暂停');
  347. const eventBus = EventBus.getInstance();
  348. eventBus.emit(GameEvents.GAME_PAUSE);
  349. }
  350. /**
  351. * 处理游戏失败事件
  352. */
  353. private onGameDefeatEvent() {
  354. console.log('[InGameManager] 接收到游戏失败事件');
  355. this.currentState = GameState.DEFEAT;
  356. // 游戏结束时进入暂停状态,停止所有游戏对象的行为
  357. console.log('[InGameManager] 游戏失败,触发游戏暂停');
  358. const eventBus = EventBus.getInstance();
  359. eventBus.emit(GameEvents.GAME_PAUSE);
  360. }
  361. /**
  362. * 处理游戏恢复事件
  363. */
  364. private onGameResumeEvent() {
  365. console.log('[InGameManager] 接收到游戏恢复事件');
  366. }
  367. /**
  368. * 墙体被摧毁事件处理
  369. * 墙体现在直接触发GAME_DEFEAT事件,与菜单退出处理流程一致
  370. */
  371. private onWallDestroyedEvent() {
  372. console.log('[InGameManager] 收到墙体被摧毁事件,墙体已直接触发GAME_DEFEAT事件');
  373. // 不再需要调用checkGameState,因为墙体已直接触发GAME_DEFEAT事件
  374. }
  375. /**
  376. * 处理敌人被击杀事件
  377. */
  378. private onEnemyKilledEvent() {
  379. // 游戏状态检查现在通过事件系统处理
  380. if (this.isGameOver()) {
  381. console.warn('[InGameManager] 游戏已结束状态下onEnemyKilledEvent被调用!');
  382. return;
  383. }
  384. // 如果游戏状态已经是成功或失败,不处理敌人击杀事件
  385. if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
  386. console.warn(`[InGameManager] 游戏已结束(${this.currentState}),跳过敌人击杀事件处理`);
  387. return;
  388. }
  389. this.enemiesKilled++;
  390. this.currentWaveEnemyCount++;
  391. const remaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
  392. console.log(`[InGameManager] 敌人被消灭,当前波剩余敌人: ${remaining}/${this.currentWaveTotalEnemies}`);
  393. // 每死一个敌人就立即增加能量
  394. const energyBeforeIncrement = this.energyPoints;
  395. this.incrementEnergy();
  396. // 通过事件系统更新敌人计数标签
  397. EventBus.getInstance().emit(GameEvents.ENEMY_UPDATE_COUNT, this.currentWaveEnemyCount);
  398. // 检查能量是否已满,如果满了需要触发技能选择
  399. const energyWillBeFull = energyBeforeIncrement + 1 >= this.energyMax;
  400. // 基于UI显示的敌人数量判断波次是否结束(Canvas-001/TopArea/EnemyNode/EnemyNumber为0)
  401. const isWaveEnd = remaining <= 0;
  402. if (isWaveEnd) {
  403. console.log(`[InGameManager] 波次结束检测: remaining=${remaining}`);
  404. // 如果能量已满,设置等待方块选择状态
  405. if (energyWillBeFull) {
  406. this.pendingBlockSelection = true;
  407. this.preparingNextWave = true;
  408. this.currentState = GameState.BLOCK_SELECTION;
  409. } else {
  410. if (this.currentWave < (this.levelWaves?.length || 1)) {
  411. this.showNextWavePrompt();
  412. } else {
  413. this.triggerGameSuccess();
  414. }
  415. }
  416. } else if (energyWillBeFull) {
  417. // 如果波次未结束但能量已满,设置状态为方块选择
  418. // 注意:onEnergyFull()已在incrementEnergy()中调用,这里不需要重复调用
  419. console.log('[InGameManager] 能量已满但波次未结束,设置方块选择状态');
  420. this.currentState = GameState.BLOCK_SELECTION;
  421. }
  422. }
  423. /**
  424. * 增加能量值
  425. */
  426. private incrementEnergy() {
  427. // 获取技能等级
  428. const energyHunterLevel = SkillManager.getInstance() ? SkillManager.getInstance().getSkillLevel('energy_hunter') : 0;
  429. const baseEnergy = 1;
  430. const bonusEnergy = SkillManager.calculateEnergyBonus ? SkillManager.calculateEnergyBonus(baseEnergy, energyHunterLevel) : baseEnergy;
  431. this.energyPoints += bonusEnergy;
  432. console.log(`[InGameManager] 能量值增加: +${bonusEnergy}, 当前: ${this.energyPoints}/${this.energyMax}`);
  433. // 检查是否达到当前能量最大值
  434. if (this.energyPoints >= this.energyMax) {
  435. this.onEnergyFull();
  436. // 能量满后重置为0,开始下一轮积累
  437. this.energyPoints = 0;
  438. }
  439. this.updateEnergyBar();
  440. }
  441. /**
  442. * 显示下一波提示
  443. */
  444. private showNextWavePrompt() {
  445. // 设置准备下一波的状态
  446. this.preparingNextWave = true;
  447. this.pendingBlockSelection = true;
  448. this.currentState = GameState.BLOCK_SELECTION;
  449. console.log('[InGameManager] 设置准备下一波状态,准备播放diban动画');
  450. // 如果当前没有技能选择UI显示,立即播放diban动画
  451. if (!this.selectSkillUI || !this.selectSkillUI.active) {
  452. this.playDibanAnimationForNextWave();
  453. }
  454. // 如果技能选择UI正在显示,则等待技能选择完成后再播放diban动画
  455. // 这种情况下,pendingBlockSelection已经在onEnemyKilledEvent中设置为true
  456. }
  457. /**
  458. * 游戏状态检查
  459. * 现在只检查敌人击败状态,墙体摧毁直接触发GAME_DEFEAT事件
  460. */
  461. private checkGameState() {
  462. // 如果游戏已经结束,不再进行状态检查
  463. if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
  464. return;
  465. }
  466. // 墙体摧毁检查已移除,因为墙体现在直接触发GAME_DEFEAT事件
  467. // 这样与菜单退出的失败处理流程保持一致
  468. if (this.checkAllEnemiesDefeated()) {
  469. this.triggerGameSuccess();
  470. return;
  471. }
  472. }
  473. /**
  474. * 检查所有敌人是否被击败
  475. */
  476. private checkAllEnemiesDefeated(): boolean {
  477. // 如果敌人生成还未开始,不进行胜利检查
  478. if (!this.enemySpawningStarted) {
  479. return false;
  480. }
  481. // 基于当前波次的敌人击杀数量判断是否胜利
  482. // 如果当前波次的剩余敌人数量为0,且是最后一波,则胜利
  483. const currentWaveRemaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
  484. const isLastWave = this.currentWave >= (this.levelWaves?.length || 1);
  485. return currentWaveRemaining <= 0 && isLastWave;
  486. }
  487. /**
  488. * 触发游戏失败
  489. * 只负责记录游戏结束时间和发送事件,状态切换由GameEnd.ts统一处理
  490. */
  491. private triggerGameDefeat() {
  492. // 防止重复触发游戏失败
  493. if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
  494. console.log('[InGameManager] 游戏已结束,跳过重复的失败触发');
  495. return;
  496. }
  497. // 记录游戏结束时间
  498. this.gameEndTime = Date.now();
  499. // 触发游戏结束状态事件
  500. EventBus.getInstance().emit(GameEvents.ENTER_GAME_END_STATE, { result: 'defeat' });
  501. console.log('[InGameManager] 游戏失败,发送GAME_DEFEAT事件,状态切换由GameEnd.ts处理');
  502. EventBus.getInstance().emit(GameEvents.GAME_DEFEAT);
  503. }
  504. /**
  505. * 触发游戏成功
  506. * 只负责记录游戏结束时间和发送事件,状态切换由GameEnd.ts统一处理
  507. */
  508. private triggerGameSuccess() {
  509. // 防止重复触发游戏成功
  510. if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
  511. console.log('[InGameManager] 游戏已结束,跳过重复的成功触发');
  512. return;
  513. }
  514. // 记录游戏结束时间
  515. this.gameEndTime = Date.now();
  516. // 触发游戏结束状态事件
  517. EventBus.getInstance().emit(GameEvents.ENTER_GAME_END_STATE, { result: 'success' });
  518. console.log('[InGameManager] 游戏成功,发送GAME_SUCCESS事件,状态切换由GameEnd.ts处理');
  519. EventBus.getInstance().emit(GameEvents.GAME_SUCCESS);
  520. }
  521. /**
  522. * 获取游戏持续时间
  523. */
  524. public getGameDuration(): number {
  525. const endTime = this.gameEndTime || Date.now();
  526. return Math.max(0, endTime - this.gameStartTime);
  527. }
  528. /**
  529. * 获取当前游戏状态
  530. */
  531. public getCurrentState(): GameState {
  532. return this.currentState;
  533. }
  534. /**
  535. * 设置游戏状态
  536. */
  537. public setCurrentState(state: GameState) {
  538. this.currentState = state;
  539. // 当游戏状态变为PLAYING时,更新能量条显示
  540. if (state === GameState.PLAYING) {
  541. this.updateEnergyBar();
  542. }
  543. }
  544. /**
  545. * 初始化UI节点
  546. */
  547. private initUINodes() {
  548. // 初始化能量条
  549. if (this.energyBarNode) {
  550. this.energyBar = this.energyBarNode.getComponent(ProgressBar);
  551. if (this.energyBar) {
  552. console.log('[InGameManager] 能量条组件初始化成功');
  553. // 不在初始化阶段更新能量条,等待游戏状态变为PLAYING后再更新
  554. } else {
  555. console.error('[InGameManager] 能量条节点存在但ProgressBar组件未找到');
  556. }
  557. } else {
  558. console.error('[InGameManager] 能量条节点未通过装饰器挂载,请在Inspector中拖拽EnergyBar节点');
  559. }
  560. // 初始化技能选择UI
  561. if (this.selectSkillUINode) {
  562. this.selectSkillUI = this.selectSkillUINode;
  563. console.log('[InGameManager] 技能选择UI节点初始化成功');
  564. } else {
  565. console.error('[InGameManager] 技能选择UI节点未通过装饰器挂载,请在Inspector中拖拽SelectSkillUI节点');
  566. }
  567. // 初始化背景管理器
  568. if (this.backgroundManagerNode) {
  569. this.backgroundManager = this.backgroundManagerNode.getComponent(BackgroundManager);
  570. if (this.backgroundManager) {
  571. console.log('[InGameManager] 背景管理器组件初始化成功');
  572. } else {
  573. console.error('[InGameManager] 背景管理器节点存在但BackgroundManager组件未找到');
  574. }
  575. } else {
  576. console.error('[InGameManager] 背景管理器节点未通过装饰器挂载,请在Inspector中拖拽BackgroundManager节点');
  577. }
  578. // 初始化地面燃烧区域管理器
  579. if (this.groundBurnAreaManagerNode) {
  580. this.groundBurnAreaManager = this.groundBurnAreaManagerNode.getComponent(GroundBurnAreaManager);
  581. if (this.groundBurnAreaManager) {
  582. console.log('[InGameManager] 地面燃烧区域管理器组件初始化成功');
  583. } else {
  584. console.error('[InGameManager] 地面燃烧区域管理器节点存在但GroundBurnAreaManager组件未找到');
  585. }
  586. } else {
  587. console.error('[InGameManager] 地面燃烧区域管理器节点未通过装饰器挂载,请在Inspector中拖拽GroundBurnAreaManager节点');
  588. }
  589. }
  590. /**
  591. * 更新能量条显示
  592. */
  593. private updateEnergyBar() {
  594. // 只有在游戏状态为PLAYING时才更新能量条,避免初始化阶段的报错
  595. if (this.currentState !== GameState.PLAYING) {
  596. return;
  597. }
  598. if (this.energyBar && this.energyMax > 0) {
  599. const progress = this.energyPoints / this.energyMax;
  600. this.energyBar.progress = Math.min(progress, 1.0);
  601. console.log(`[InGameManager] 能量条更新: ${this.energyPoints}/${this.energyMax} (${Math.round(progress * 100)}%)`);
  602. } else {
  603. console.warn('[InGameManager] 能量条组件未初始化或energyMax未设置,无法更新显示');
  604. }
  605. }
  606. /**
  607. * 能量满时的处理
  608. */
  609. private onEnergyFull() {
  610. console.log('[InGameManager] 能量已满,开始升级处理');
  611. // 升级能量条
  612. this.upgradeEnergySystem();
  613. // 显示技能选择UI
  614. this.showSkillSelection();
  615. }
  616. /**
  617. * 升级能量系统
  618. */
  619. private upgradeEnergySystem() {
  620. // 增加升级次数
  621. this.energyUpgradeCount++;
  622. // 更新能量最大值
  623. // energyMaxUpgrades数组索引0是初始值,索引1是第1次升级后的值,以此类推
  624. if (this.energyUpgradeCount < this.energyMaxUpgrades.length) {
  625. const newMaxEnergy = this.energyMaxUpgrades[this.energyUpgradeCount];
  626. this.energyMax = newMaxEnergy;
  627. console.log(`[InGameManager] 能量条升级 ${this.energyUpgradeCount} 次,新的最大值: ${this.energyMax}`);
  628. } else {
  629. // 超出配置次数,按照上一次的值+1递增
  630. this.energyMax = this.energyMax + 1;
  631. console.log(`[InGameManager] 能量条升级超出配置次数,使用递增模式,新的最大值: ${this.energyMax}`);
  632. }
  633. // 立即更新能量条显示,确保新的最大值生效
  634. this.updateEnergyBar();
  635. }
  636. /**
  637. * 显示技能选择UI
  638. */
  639. private showSkillSelection() {
  640. if (this.selectSkillUI) {
  641. this.selectSkillUI.active = true;
  642. // 使用技能选择专用暂停事件,所有小球停止运动
  643. EventBus.getInstance().emit(GameEvents.GAME_PAUSE_SKILL_SELECTION);
  644. // 注意:不调用StartGame.resetEnergy(),因为那会重置整个能量系统包括最大值
  645. // 能量点数已在onEnergyFull()中重置为0
  646. }
  647. }
  648. /**
  649. * 恢复游戏
  650. */
  651. private resumeGame() {
  652. console.log('[InGameManager] 恢复游戏');
  653. EventBus.getInstance().emit(GameEvents.GAME_RESUME);
  654. }
  655. /**
  656. * 检查游戏是否结束
  657. */
  658. private isGameOver(): boolean {
  659. let gameOver = false;
  660. EventBus.getInstance().emit(GameEvents.GAME_CHECK_OVER, (isOver: boolean) => {
  661. gameOver = isOver;
  662. });
  663. return gameOver;
  664. }
  665. /**
  666. * 设置当前波次
  667. */
  668. public setCurrentWave(wave: number, enemyCount: number = 0) {
  669. this.currentWave = wave;
  670. this.currentWaveEnemyCount = 0; // 重置当前击杀数
  671. this.currentWaveTotalEnemies = enemyCount; // 设置该波次总敌人数
  672. const totalWaves = this.levelWaves?.length || 1;
  673. // 获取波次敌人配置
  674. const waveEnemyConfigs = this.getWaveEnemyConfigs(wave);
  675. // 获取当前波次的血量系数
  676. let healthMultiplier = 1.0;
  677. if (this.levelWaves && this.levelWaves.length > 0) {
  678. const waveIndex = wave - 1; // 波次从1开始,数组从0开始
  679. if (waveIndex >= 0 && waveIndex < this.levelWaves.length) {
  680. const waveData = this.levelWaves[waveIndex];
  681. if (waveData && typeof waveData.healthMultiplier === 'number') {
  682. healthMultiplier = waveData.healthMultiplier;
  683. }
  684. }
  685. }
  686. // 通过事件系统启动波次
  687. EventBus.getInstance().emit(GameEvents.ENEMY_START_WAVE, {
  688. wave: wave,
  689. totalWaves: totalWaves,
  690. enemyCount: enemyCount,
  691. waveEnemyConfigs: waveEnemyConfigs,
  692. healthMultiplier: healthMultiplier
  693. });
  694. }
  695. /**
  696. * 更新当前波次敌人数量
  697. */
  698. public updateCurrentWaveEnemyCount(count: number) {
  699. this.currentWaveEnemyCount = count;
  700. }
  701. /**
  702. * 获取当前波次
  703. */
  704. public getCurrentWave(): number {
  705. return this.currentWave;
  706. }
  707. /**
  708. * 获取当前波次敌人数量
  709. */
  710. public getCurrentWaveEnemyCount(): number {
  711. return this.currentWaveEnemyCount;
  712. }
  713. /**
  714. * 获取当前波次总敌人数量
  715. */
  716. public getCurrentWaveTotalEnemies(): number {
  717. return this.currentWaveTotalEnemies;
  718. }
  719. /**
  720. * 进入下一波
  721. */
  722. public nextWave() {
  723. this.currentWave++;
  724. // 根据关卡配置获取下一波敌人数
  725. let enemyTotal = 0;
  726. if (this.levelWaves && this.levelWaves.length >= this.currentWave) {
  727. const waveCfg = this.levelWaves[this.currentWave - 1];
  728. if (waveCfg && waveCfg.enemies) {
  729. enemyTotal = waveCfg.enemies.reduce((t: number, g: any) => t + (g.count || 0), 0);
  730. }
  731. }
  732. this.setCurrentWave(this.currentWave, enemyTotal);
  733. }
  734. /**
  735. * 获取当前能量值
  736. */
  737. public getCurrentEnergy(): number {
  738. return this.energyPoints;
  739. }
  740. /**
  741. * 获取最大能量值
  742. */
  743. public getMaxEnergy(): number {
  744. return this.energyMax;
  745. }
  746. /**
  747. * 获取墙体健康度(返回主墙体健康度)
  748. */
  749. public getWallHealth(): number {
  750. if (this.wallComponent) {
  751. return this.wallComponent.getCurrentHealth();
  752. }
  753. return 0;
  754. }
  755. /**
  756. * 获取所有墙体的健康度
  757. */
  758. public getAllWallsHealth(): { main: number; topFence: number; bottomFence: number } {
  759. return {
  760. main: this.wallComponent ? this.wallComponent.getCurrentHealth() : 0,
  761. topFence: this.topFenceComponent ? this.topFenceComponent.getCurrentHealth() : 0,
  762. bottomFence: this.bottomFenceComponent ? this.bottomFenceComponent.getCurrentHealth() : 0
  763. };
  764. }
  765. /**
  766. * 根据等级获取墙体健康度
  767. */
  768. public getWallHealthByLevel(level: number): number {
  769. if (this.wallComponent) {
  770. return this.wallComponent.getWallHealthByLevel(level);
  771. }
  772. return 100;
  773. }
  774. /**
  775. * 获取当前墙体等级(返回主墙体等级)
  776. */
  777. public getCurrentWallLevel(): number {
  778. if (this.wallComponent) {
  779. return this.wallComponent.getCurrentWallLevel();
  780. }
  781. return 1;
  782. }
  783. /**
  784. * 获取当前墙体健康度(返回主墙体健康度)
  785. */
  786. public getCurrentWallHealth(): number {
  787. if (this.wallComponent) {
  788. return this.wallComponent.getCurrentHealth();
  789. }
  790. return 100;
  791. }
  792. /**
  793. * 获取所有墙体的等级
  794. */
  795. public getAllWallsLevel(): { main: number; topFence: number; bottomFence: number } {
  796. return {
  797. main: this.wallComponent ? this.wallComponent.getCurrentWallLevel() : 1,
  798. topFence: this.topFenceComponent ? this.topFenceComponent.getCurrentWallLevel() : 1,
  799. bottomFence: this.bottomFenceComponent ? this.bottomFenceComponent.getCurrentWallLevel() : 1
  800. };
  801. }
  802. /**
  803. * 处理确认操作(方块选择确认)
  804. */
  805. public handleConfirmAction() {
  806. console.log('[InGameManager] 处理方块选择确认操作');
  807. // 如果是在准备下一波的状态,需要先切换到下一波
  808. if (this.preparingNextWave) {
  809. console.log('[InGameManager] 检测到准备下一波状态,切换到下一波');
  810. this.nextWave();
  811. // 重置状态
  812. this.preparingNextWave = false;
  813. this.pendingBlockSelection = false;
  814. this.currentState = GameState.PLAYING;
  815. }
  816. // 触发进入游玩状态事件
  817. EventBus.getInstance().emit(GameEvents.ENTER_PLAYING_STATE);
  818. // 注意:不再发送GAME_START事件,避免重复触发游戏启动流程
  819. // 游戏启动流程已在用户点击战斗按钮时完成,这里只需要启动游戏逻辑
  820. // 通过事件系统启动球的移动
  821. EventBus.getInstance().emit(GameEvents.BALL_START);
  822. console.log('[InGameManager] 发送BALL_START事件,球已启动');
  823. // 通过事件系统开始当前波次的敌人生成
  824. EventBus.getInstance().emit(GameEvents.ENEMY_START_GAME);
  825. EventBus.getInstance().emit(GameEvents.ENEMY_SHOW_START_WAVE_PROMPT);
  826. console.log(`[InGameManager] 波次 ${this.currentWave} 敌人生成已启动`);
  827. }
  828. /**
  829. * 重置能量值(供StartGame调用)
  830. */
  831. public resetEnergyValue() {
  832. this.energyPoints = 0;
  833. this.updateEnergyBar();
  834. console.log('[InGameManager] 能量值重置完成');
  835. }
  836. /**
  837. * 重置波次信息(供StartGame调用)
  838. */
  839. public resetWaveInfo() {
  840. this.currentWave = 1;
  841. this.currentWaveEnemyCount = 0;
  842. this.currentWaveTotalEnemies = 0;
  843. this.enemiesKilled = 0;
  844. this.totalEnemiesSpawned = 0;
  845. this.levelTotalEnemies = 0;
  846. console.log('[InGameManager] 波次信息重置完成');
  847. }
  848. /**
  849. * 重置能量系统(供StartGame调用)
  850. * 注意:只在游戏真正重新开始时重置升级状态,技能选择后不应重置升级状态
  851. */
  852. public resetEnergySystem() {
  853. this.energyPoints = 0;
  854. // 只有在游戏状态不是BLOCK_SELECTION时才重置升级状态
  855. // 这样可以避免技能选择后重置已获得的能量升级
  856. if (this.currentState !== GameState.BLOCK_SELECTION) {
  857. this.energyUpgradeCount = 0;
  858. // 重置energyMax到初始值(energyMaxUpgrades数组的第一个值)
  859. if (this.energyMaxUpgrades && this.energyMaxUpgrades.length > 0) {
  860. this.energyMax = this.energyMaxUpgrades[0];
  861. }
  862. console.log('[InGameManager] 能量系统完全重置(包括升级状态)');
  863. } else {
  864. console.log('[InGameManager] 技能选择状态下,仅重置能量点数,保持升级状态');
  865. }
  866. this.updateEnergyBar();
  867. console.log('[InGameManager] 能量系统重置完成');
  868. }
  869. /**
  870. * 清理游戏数据,为返回主页面做准备
  871. * 当游戏胜利或失败返回主页面时调用
  872. */
  873. private cleanupGameDataForMainMenu() {
  874. console.log('[InGameManager] 开始清理游戏数据,准备返回主页面');
  875. const eventBus = EventBus.getInstance();
  876. // 1. 清空场上的所有游戏对象
  877. console.log('[InGameManager] 清空场上敌人、方块、球');
  878. eventBus.emit(GameEvents.CLEAR_ALL_ENEMIES); // 清空所有敌人
  879. eventBus.emit(GameEvents.CLEAR_ALL_BULLETS); // 清空所有子弹
  880. eventBus.emit(GameEvents.CLEAR_ALL_GAME_OBJECTS); // 清空其他游戏对象
  881. // 2. 重置能量系统
  882. console.log('[InGameManager] 重置能量系统');
  883. this.energyPoints = 0;
  884. this.updateEnergyBar();
  885. // 3. 清空技能选择数据(重置临时技能状态)
  886. console.log('[InGameManager] 清空技能选择数据');
  887. const skillManager = SkillManager.getInstance();
  888. if (skillManager) {
  889. skillManager.resetAllSkillLevels();
  890. }
  891. // 4. 重置关卡数据和游戏状态
  892. console.log('[InGameManager] 重置关卡数据和游戏状态');
  893. this.currentWave = 1;
  894. this.currentWaveEnemyCount = 0;
  895. this.currentWaveTotalEnemies = 0;
  896. this.enemiesKilled = 0;
  897. this.totalEnemiesSpawned = 0;
  898. this.levelTotalEnemies = 0;
  899. this.levelWaves = [];
  900. this.gameStarted = false;
  901. this.enemySpawningStarted = false;
  902. this.preparingNextWave = false;
  903. this.pendingSkillSelection = false;
  904. this.pendingBlockSelection = false;
  905. this.shouldShowNextWavePrompt = false;
  906. // 5. 重置UI状态
  907. console.log('[InGameManager] 重置UI状态');
  908. if (this.selectSkillUI) {
  909. this.selectSkillUI.active = false;
  910. }
  911. // 6. 清理会话数据(局内金币等临时数据)
  912. console.log('[InGameManager] 清理会话数据');
  913. if (LevelSessionManager.inst) {
  914. LevelSessionManager.inst.clear(); // 清空局内金币等临时数据
  915. }
  916. // 7. 通过事件系统通知其他组件进行清理
  917. eventBus.emit(GameEvents.RESET_BALL_CONTROLLER); // 重置球控制器
  918. eventBus.emit(GameEvents.RESET_BLOCK_MANAGER); // 重置方块管理器
  919. eventBus.emit(GameEvents.RESET_BLOCK_SELECTION); // 重置方块选择
  920. eventBus.emit(GameEvents.RESET_ENEMY_CONTROLLER); // 重置敌人控制器
  921. eventBus.emit(GameEvents.RESET_WALL_HEALTH); // 重置墙体血量
  922. eventBus.emit(GameEvents.RESET_UI_STATES); // 重置UI状态
  923. // 8. 重置镜头位置
  924. console.log('[InGameManager] 重置镜头位置');
  925. if (this.gameStartMoveComponent) {
  926. this.gameStartMoveComponent.resetCameraToOriginalPositionImmediate();
  927. } else {
  928. console.warn('[InGameManager] GameStartMove组件未找到,无法重置镜头位置');
  929. }
  930. // 9. 发送游戏结束事件,确保游戏状态正确转换
  931. console.log('[InGameManager] 发送游戏结束事件');
  932. eventBus.emit('GAME_END');
  933. // 10. 重置游戏状态为初始状态
  934. this.currentState = GameState.PLAYING;
  935. // 11. 重置游戏结束时间,确保下次游戏状态检查正常
  936. this.gameEndTime = 0;
  937. console.log('[InGameManager] 游戏数据清理完成,可以安全返回主页面');
  938. }
  939. /**
  940. * 重置游戏状态(供StartGame调用)
  941. */
  942. public resetGameStates() {
  943. this.currentState = GameState.PLAYING;
  944. this.gameStarted = false;
  945. this.enemySpawningStarted = false;
  946. this.preparingNextWave = false;
  947. this.pendingSkillSelection = false;
  948. this.pendingBlockSelection = false;
  949. this.shouldShowNextWavePrompt = false;
  950. this.gameStartTime = 0;
  951. this.gameEndTime = 0;
  952. this.checkTimer = 0;
  953. console.log('[InGameManager] 游戏状态重置完成');
  954. }
  955. // resetGameRecord方法已被移除,避免与cleanupGameDataForMainMenu重复
  956. // 所有清理逻辑已统一在cleanupGameDataForMainMenu中处理
  957. /**
  958. * 手动触发游戏数据清理(供外部调用)
  959. * 可以在返回主菜单按钮点击时调用
  960. */
  961. public triggerGameDataCleanup() {
  962. this.cleanupGameDataForMainMenu();
  963. }
  964. /**
  965. * 应用关卡配置
  966. */
  967. public async applyLevelConfig(levelConfig: any) {
  968. console.log('[InGameManager] 应用关卡配置');
  969. // 应用能量配置 - 现在从energyMaxUpgrades数组获取初始值
  970. let initialEnergyMax = 5; // 默认值
  971. // 先读取energyMaxUpgrades配置以获取初始能量最大值
  972. if (levelConfig.levelSettings && levelConfig.levelSettings.energyMaxUpgrades && Array.isArray(levelConfig.levelSettings.energyMaxUpgrades) && levelConfig.levelSettings.energyMaxUpgrades.length > 0) {
  973. initialEnergyMax = levelConfig.levelSettings.energyMaxUpgrades[0];
  974. console.log(`[InGameManager] 从energyMaxUpgrades获取初始能量配置: ${initialEnergyMax}`);
  975. } else {
  976. console.warn('[InGameManager] 警告:关卡配置中缺少 energyMaxUpgrades 设置,使用默认值!');
  977. }
  978. this.energyMax = initialEnergyMax;
  979. this.updateEnergyBar();
  980. // 应用新的能量条升级配置
  981. if (levelConfig.levelSettings) {
  982. // 读取能量条升级后最大值配置
  983. if (levelConfig.levelSettings.energyMaxUpgrades && Array.isArray(levelConfig.levelSettings.energyMaxUpgrades)) {
  984. this.energyMaxUpgrades = [...levelConfig.levelSettings.energyMaxUpgrades];
  985. console.log(`[InGameManager] 应用能量条升级配置: ${this.energyMaxUpgrades.length}个配置`);
  986. } else {
  987. // 默认升级配置(基于初始最大值递增)
  988. this.energyMaxUpgrades = [];
  989. for (let i = 0; i < 20; i++) {
  990. this.energyMaxUpgrades.push(this.energyMax + i + 1);
  991. }
  992. console.log('[InGameManager] 使用默认能量条升级配置');
  993. }
  994. this.energyUpgradeCount = 0;
  995. console.log('[InGameManager] 初始化能量条升级系统');
  996. }
  997. // 如果有武器配置,应用武器
  998. if (levelConfig.weapons && Array.isArray(levelConfig.weapons)) {
  999. console.log('[InGameManager] 应用武器配置');
  1000. // TODO: 应用武器配置逻辑
  1001. }
  1002. // 如果有波次配置,设置敌人波次
  1003. if (levelConfig.waves && Array.isArray(levelConfig.waves)) {
  1004. this.levelWaves = levelConfig.waves;
  1005. this.currentWave = 1;
  1006. // 计算本关卡总敌人数
  1007. this.levelTotalEnemies = 0;
  1008. for (const wave of this.levelWaves) {
  1009. for (const enemy of wave.enemies || []) {
  1010. this.levelTotalEnemies += enemy.count || 0;
  1011. }
  1012. }
  1013. console.log(`[InGameManager] 应用波次配置: ${this.levelWaves.length}波,总敌人数: ${this.levelTotalEnemies}`);
  1014. // 通过事件系统通知 EnemyController 初始化第一波数据及 UI
  1015. const firstWaveEnemies = this.levelWaves.length > 0 && this.levelWaves[0].enemies ?
  1016. this.levelWaves[0].enemies.reduce((t: number, g: any) => t + (g.count || 0), 0) : 0;
  1017. // 通过事件系统调用setCurrentWave
  1018. this.setCurrentWave(1, firstWaveEnemies);
  1019. }
  1020. // 应用背景图片配置
  1021. if (this.backgroundManager && levelConfig.backgroundImage) {
  1022. // 转换路径格式:从 "images/LevelBackground/BG1" 转换为 "LevelBackground/BG1"
  1023. const bundlePath = levelConfig.backgroundImage.replace('images/', '');
  1024. await this.backgroundManager.setBackground(bundlePath);
  1025. console.log(`[InGameManager] 应用背景配置: ${levelConfig.backgroundImage}`);
  1026. } else if (this.backgroundManager) {
  1027. // 如果没有指定背景图片,使用默认背景
  1028. await this.backgroundManager.setBackground('LevelBackground/BG1');
  1029. console.log('[InGameManager] 使用默认背景: LevelBackground/BG1');
  1030. }
  1031. }
  1032. onDestroy() {
  1033. const eventBus = EventBus.getInstance();
  1034. eventBus.off(GameEvents.GAME_SUCCESS, this.onGameSuccessEvent, this);
  1035. eventBus.off(GameEvents.GAME_DEFEAT, this.onGameDefeatEvent, this);
  1036. eventBus.off(GameEvents.GAME_RESUME, this.onGameResumeEvent, this);
  1037. eventBus.off(GameEvents.GAME_RESUME_SKILL_SELECTION, this.onGameResumeEvent, this);
  1038. eventBus.off(GameEvents.GAME_RESUME_BLOCK_SELECTION, this.onGameResumeEvent, this);
  1039. eventBus.off('ENEMY_KILLED', this.onEnemyKilledEvent, this);
  1040. eventBus.off(GameEvents.RESET_ENERGY_SYSTEM, this.resetEnergySystem, this);
  1041. eventBus.off(GameEvents.WALL_DESTROYED, this.onWallDestroyedEvent, this);
  1042. }
  1043. }