feat(game): 添加开会暂停系统——点击开会按钮暂停游戏,可安心发激励,结束开会后恢复
This commit is contained in:
@@ -102,6 +102,22 @@ export class GameManager {
|
||||
this.onKPIChange.forEach(cb => cb(this.kpi))
|
||||
}
|
||||
|
||||
/** 暂停游戏(仅 playing 状态下有效) */
|
||||
pause(): boolean {
|
||||
if (this.gameState !== 'playing') return false
|
||||
this.gameState = 'paused'
|
||||
return true
|
||||
}
|
||||
|
||||
/** 恢复游戏(仅 paused 状态下有效) */
|
||||
resume(): boolean {
|
||||
if (this.gameState !== 'paused') return false
|
||||
this.gameState = 'playing'
|
||||
return true
|
||||
}
|
||||
|
||||
get isPaused(): boolean { return this.gameState === 'paused' }
|
||||
|
||||
/** 触发胜利 */
|
||||
triggerVictory(): void {
|
||||
if (this.gameState === 'playing') {
|
||||
|
||||
@@ -64,6 +64,10 @@ export function createGameScene(PhaserLib: typeof Phaser): typeof Phaser.Scene {
|
||||
private bgObject: Phaser.GameObjects.Image | null = null
|
||||
private mapInTransition: boolean = false
|
||||
|
||||
// 暂停遮罩
|
||||
private pauseOverlay: Phaser.GameObjects.Graphics | null = null
|
||||
private pauseText: Phaser.GameObjects.Text | null = null
|
||||
|
||||
constructor() { super({ key: 'GameScene' }) }
|
||||
|
||||
preload(): void {
|
||||
@@ -124,19 +128,34 @@ export function createGameScene(PhaserLib: typeof Phaser): typeof Phaser.Scene {
|
||||
audio.startBGM()
|
||||
})
|
||||
|
||||
// 注册 PUA buff 接口 + HC 查询/扣除接口供 React 层调用
|
||||
// 注册 PUA buff 接口 + HC 查询/扣除接口 + 暂停/恢复接口
|
||||
if (typeof window !== 'undefined') {
|
||||
;(window as any).__gamePuaBuff = (
|
||||
effect: string, score: number, title: string
|
||||
) => {
|
||||
this.applyPuaBuff(effect, score, title)
|
||||
}
|
||||
// 查询当前 HC
|
||||
) => { this.applyPuaBuff(effect, score, title) }
|
||||
|
||||
;(window as any).__gameGetHC = () => this.manager.hc
|
||||
// 尝试扣除 HC,成功返回 true,不足返回 false
|
||||
;(window as any).__gameSpendHC = (amount: number): boolean => {
|
||||
return this.manager.spendHC(amount)
|
||||
;(window as any).__gameSpendHC = (amount: number): boolean =>
|
||||
this.manager.spendHC(amount)
|
||||
|
||||
;(window as any).__gamePause = (): boolean => {
|
||||
if (!this.manager.pause()) return false
|
||||
this.showPauseOverlay()
|
||||
// 暂停 Phaser 物理与 Tween
|
||||
this.physics.pause()
|
||||
this.tweens.pauseAll()
|
||||
return true
|
||||
}
|
||||
|
||||
;(window as any).__gameResume = (): boolean => {
|
||||
if (!this.manager.resume()) return false
|
||||
this.hidePauseOverlay()
|
||||
this.physics.resume()
|
||||
this.tweens.resumeAll()
|
||||
return true
|
||||
}
|
||||
|
||||
;(window as any).__gameIsPaused = (): boolean => this.manager.isPaused
|
||||
}
|
||||
|
||||
this.setupInteraction()
|
||||
@@ -145,10 +164,34 @@ export function createGameScene(PhaserLib: typeof Phaser): typeof Phaser.Scene {
|
||||
}
|
||||
|
||||
private createMuteButton(_audio: AudioEngine): void {
|
||||
// 静音按钮已移除,音乐默认开启
|
||||
void _audio
|
||||
}
|
||||
|
||||
private showPauseOverlay(): void {
|
||||
const { width, height } = this.scale
|
||||
// 半透明深色遮罩
|
||||
this.pauseOverlay = this.add.graphics().setDepth(90)
|
||||
this.pauseOverlay.fillStyle(0x000000, 0.6)
|
||||
this.pauseOverlay.fillRect(0, 0, width, height)
|
||||
|
||||
// "开会中" 提示卡片
|
||||
this.pauseText = this.add.text(width / 2, height / 2, '📋 开会中...\n游戏已暂停', {
|
||||
fontFamily: 'VT323, monospace',
|
||||
fontSize: '32px',
|
||||
color: '#FCD34D',
|
||||
backgroundColor: '#1e3a5f',
|
||||
padding: { x: 32, y: 18 },
|
||||
align: 'center',
|
||||
}).setOrigin(0.5, 0.5).setDepth(91)
|
||||
}
|
||||
|
||||
private hidePauseOverlay(): void {
|
||||
this.pauseOverlay?.destroy()
|
||||
this.pauseOverlay = null
|
||||
this.pauseText?.destroy()
|
||||
this.pauseText = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用 PUA buff 效果到游戏
|
||||
* effect: attack_boost | speed_boost | money_rain | rage_mode | backfire
|
||||
@@ -324,6 +367,7 @@ export function createGameScene(PhaserLib: typeof Phaser): typeof Phaser.Scene {
|
||||
private readonly AUTO_WAVE_DELAY = 2000 // 自动开始等待:3s→2s,缩短喘息时间
|
||||
|
||||
update(_time: number, delta: number): void {
|
||||
if (this.manager.gameState === 'paused') return // 暂停时完全跳过
|
||||
if (this.manager.gameState !== 'playing' && this.manager.gameState !== 'idle') return
|
||||
if (this.mapInTransition) return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user