feat(game): 添加PUA激励台——AI评分打鸡血,触发攻击/攻速/HC/狂暴/翻车等游戏效果;移除静音按钮BGM默认开启

This commit is contained in:
Cloud Bot
2026-03-24 08:14:51 +00:00
parent e922c8fdf6
commit adda7ae57c
4 changed files with 558 additions and 95 deletions

View File

@@ -117,34 +117,158 @@ export function createGameScene(PhaserLib: typeof Phaser): typeof Phaser.Scene {
}
}
// 初始化音效引擎(首次点击后激活 AudioContext
// 初始化音效引擎(首次点击后激活 AudioContext,默认开启
const audio = AudioEngine.getInstance()
this.input.once('pointerdown', () => {
audio.init()
audio.startBGM()
})
// 添加静音切换按钮(右上角)
this.createMuteButton(audio)
// 注册 PUA buff 接口供 React 层调用
if (typeof window !== 'undefined') {
;(window as any).__gamePuaBuff = (
effect: string, score: number, title: string
) => {
this.applyPuaBuff(effect, score, title)
}
}
this.setupInteraction()
this.setupManagerCallbacks()
if (typeof window !== 'undefined') { ;(window as any).__gameReady?.() }
}
private createMuteButton(audio: AudioEngine): void {
const btn = this.add.text(GAME_WIDTH - 10, 8, '🔊', {
fontSize: '16px', backgroundColor: 'rgba(0,0,0,0.35)',
padding: { x: 6, y: 3 },
}).setOrigin(1, 0).setDepth(50).setInteractive({ useHandCursor: true })
btn.on('pointerdown', () => {
const nowMuted = !audio.isMuted()
audio.setMuted(nowMuted)
btn.setText(nowMuted ? '🔇' : '🔊')
if (!nowMuted) audio.startBGM()
else audio.stopBGM()
private createMuteButton(_audio: AudioEngine): void {
// 静音按钮已移除,音乐默认开启
void _audio
}
/**
* 应用 PUA buff 效果到游戏
* effect: attack_boost | speed_boost | money_rain | rage_mode | backfire
*/
private applyPuaBuff(effect: string, score: number, title: string): void {
const towers = this.towerManager.getAllTowers()
const audio = AudioEngine.getInstance()
// 全屏效果提示横幅
const colors: Record<string, string> = {
rage_mode: '#FF4E00',
speed_boost: '#FBBF24',
attack_boost: '#22C55E',
money_rain: '#A78BFA',
backfire: '#6B7280',
}
const color = colors[effect] ?? '#E2E8F0'
this.showPuaBanner(title, score, color)
const dur = Math.max(8000, score * 1500) // buff 持续时间ms
switch (effect) {
case 'rage_mode': {
// 9-10分全场狂暴 — 攻速×2全图红色相机震动
audio.playBossAppear()
this.cameras.main.flash(600, 255, 60, 0, false)
this.cameras.main.shake(400, 0.008)
towers.forEach(t => { t['_puaSpeedMult'] = 2.0 })
this.manager.addHC(score * 15)
this.time.delayedCall(dur, () => {
towers.forEach(t => { t['_puaSpeedMult'] = 1.0 })
})
break
}
case 'speed_boost': {
// 7-8分攻速 ×1.5
audio.playWaveStart()
towers.forEach(t => { t['_puaSpeedMult'] = 1.5 })
this.time.delayedCall(dur, () => {
towers.forEach(t => { t['_puaSpeedMult'] = 1.0 })
})
break
}
case 'attack_boost': {
// 4-6分伤害 ×(1 + score*0.08)
audio.playDingTalk()
const mult = 1 + score * 0.08
towers.forEach(t => { t['_puaDmgMult'] = mult })
this.time.delayedCall(dur, () => {
towers.forEach(t => { t['_puaDmgMult'] = 1.0 })
})
break
}
case 'money_rain': {
// 5-7分立即获得 HC屏幕绿色雨
const hcBonus = score * 20
this.manager.addHC(hcBonus)
audio.playOpsAttack()
this.showMoneyRain(hcBonus)
break
}
case 'backfire': {
// 1-2分废话反效果 — 全场塔禁锢 2 秒
audio.playEnemyDeath()
this.cameras.main.shake(300, 0.005)
this.freezeAllTowers(2000)
break
}
}
}
/** 显示 PUA buff 横幅 */
private showPuaBanner(title: string, score: number, color: string): void {
const stars = '★'.repeat(Math.min(score, 10))
const banner = this.add.text(
GAME_WIDTH / 2, HUD_HEIGHT + 80,
`${title} ${stars}`,
{
fontFamily: 'VT323, monospace',
fontSize: '28px',
color,
stroke: '#000000',
strokeThickness: 4,
shadow: { offsetX: 0, offsetY: 0, color, blur: 16, stroke: true, fill: true },
}
).setOrigin(0.5, 0.5).setDepth(60).setAlpha(0)
this.tweens.add({
targets: banner,
alpha: 1,
y: HUD_HEIGHT + 60,
duration: 300,
yoyo: false,
onComplete: () => {
this.time.delayedCall(2000, () => {
this.tweens.add({
targets: banner, alpha: 0, y: HUD_HEIGHT + 40,
duration: 400, onComplete: () => banner.destroy(),
})
})
},
})
}
/** 金币雨效果money_rain */
private showMoneyRain(amount: number): void {
for (let i = 0; i < 12; i++) {
const x = Math.random() * GAME_WIDTH
const coin = this.add.text(x, HUD_HEIGHT + 20, `+${Math.floor(amount / 12)}HC`, {
fontFamily: 'VT323, monospace',
fontSize: '16px',
color: '#A78BFA',
stroke: '#000',
strokeThickness: 2,
}).setOrigin(0.5, 0).setDepth(55).setAlpha(0.9)
this.tweens.add({
targets: coin,
y: coin.y + 120 + Math.random() * 80,
alpha: 0,
delay: i * 80,
duration: 900,
onComplete: () => coin.destroy(),
})
}
}
private setupManagerCallbacks(): void {
this.manager.onHCChange.push((hc: number) => {
this.hcText.setText(`HC: ${hc}`)