feat(towers): 实现防御塔基类与4种塔及塔管理器

This commit is contained in:
Cloud Bot
2026-03-21 08:04:15 +00:00
parent 6a21ece3ee
commit 45cf1e4642
6 changed files with 708 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import type Phaser from 'phaser'
import { TowerBase } from './TowerBase'
import type { EnemyBase } from '../enemies/EnemyBase'
export class PPTMasterTower extends TowerBase {
constructor(scene: Phaser.Scene, gridX: number, gridY: number) {
super(scene, gridX, gridY, 100, 3, 5, 1.5)
this.drawSprite()
}
drawSprite(): void {
if (!this.sprite) return
this.sprite.clear()
// 橙色圆形
this.sprite.fillStyle(0xf59e0b, 1)
this.sprite.fillCircle(0, 0, 16)
// 圆心白点
this.sprite.fillStyle(0xffffff, 0.9)
this.sprite.fillCircle(0, 0, 5)
this.sprite.setPosition(this.px, this.py)
this.sprite.setDepth(10)
}
attack(target: EnemyBase): void {
// AOE 攻击:对射程内所有怪物造成伤害 + 减速
this.showAoeEffect()
}
/** 该方法由 TowerManager 调用,传入全体敌人 */
attackAoe(enemies: EnemyBase[]): void {
const rangePx = this.attackRange * 80 // TILE_SIZE
this.showAoeEffect()
for (const e of enemies) {
if (e.isDead) continue
const dx = e.sprite.x - this.px
const dy = e.sprite.y - this.py
const dist = Math.sqrt(dx * dx + dy * dy)
if (dist <= rangePx) {
e.takeDamage(this.attackDamage)
// 黑话领域减速40%持续2秒
e.addSlow(0.4, 2000)
}
}
}
private showAoeEffect(): void {
const g = this.scene.add.graphics()
g.lineStyle(2, 0xf59e0b, 0.8)
g.strokeCircle(this.px, this.py, this.attackRange * 80)
g.setDepth(12)
this.scene.tweens.add({
targets: g,
alpha: 0,
scaleX: 1.2,
scaleY: 1.2,
duration: 400,
onComplete: () => g.destroy(),
})
}
}