Files
test1/game/enemies/BossVP.ts

79 lines
2.6 KiB
TypeScript

import type Phaser from 'phaser'
import { EnemyBase, type PathPoint } from './EnemyBase'
import { getRandomQuote } from '../data/quotes'
export class BossVP extends EnemyBase {
private skillTimer: number = 20000
private onDestroyTower?: () => void
private bossLabel!: Phaser.GameObjects.Text
constructor(
scene: Phaser.Scene,
pathPoints: PathPoint[],
onDestroyTower?: () => void
) {
super(scene, pathPoints, 800, 40, 30, 150, 'enemy-boss')
this.onDestroyTower = onDestroyTower
// 放大 BOSS
const bossScale = Math.min(this.cellW, this.cellH) / 128 * 1.3
this.imageSprite.setScale(bossScale)
this.imageSprite.setDepth(12)
// BOSS 出现特效
scene.cameras.main.flash(800, 255, 0, 0, false)
this.showBossAlert()
// BOSS 名字标签
this.bossLabel = scene.add.text(this.x, this.y + this.cellH * 0.5, '空降VP', {
fontFamily: 'VT323, monospace', fontSize: '14px',
color: '#FBBF24', backgroundColor: '#7c2d12', padding: { x: 4, y: 1 },
}).setOrigin(0.5, 0).setDepth(15)
}
private showBossAlert(): void {
const alert = this.scene.add
.text(this.scene.scale.width / 2, this.scene.scale.height / 2, '⚠ 空降VP来袭 ⚠', {
fontFamily: 'VT323, monospace', fontSize: '36px',
color: '#FBBF24', backgroundColor: '#7F1D1D', padding: { x: 16, y: 8 },
}).setOrigin(0.5, 0.5).setDepth(50)
this.scene.tweens.add({
targets: alert, alpha: 0, duration: 2500, delay: 500,
onComplete: () => alert.destroy(),
})
}
override update(delta: number): void {
if (this.isDead) return
super.update(delta)
this.skillTimer -= delta
if (this.skillTimer <= 0) {
this.skillTimer = 20000
this.triggerOrgRestructure()
}
// 更新名字标签位置
if (this.bossLabel) {
this.bossLabel.setPosition(this.x, this.y + this.cellH * 0.5)
}
// BOSS 金色发光边框
this.imageSprite.setTint(this.skillTimer < 3000 ? 0xff6600 : 0xfbbf24)
}
private triggerOrgRestructure(): void {
this.onDestroyTower?.()
const txt = this.scene.add
.text(this.x, this.y - 40, '组织架构调整!', {
fontFamily: 'VT323, monospace', fontSize: '18px',
color: '#FBBF24', backgroundColor: '#7C2D12', padding: { x: 6, y: 3 },
}).setOrigin(0.5, 1).setDepth(25)
this.scene.tweens.add({
targets: txt, y: this.y - 70, alpha: 0,
duration: 2000, onComplete: () => txt.destroy(),
})
}
override destroy(): void {
this.bossLabel?.destroy()
super.destroy()
}
getQuote(): string { return getRandomQuote('BossVP') }
}