feat(game/towers): TowerBase 添加 isFrozen 禁锢状态支持,禁锢时显示灰色覆盖层并跳过攻击
This commit is contained in:
@@ -9,6 +9,7 @@ export abstract class TowerBase {
|
|||||||
public gridY: number
|
public gridY: number
|
||||||
protected sprite!: Phaser.GameObjects.Graphics
|
protected sprite!: Phaser.GameObjects.Graphics
|
||||||
protected staminaBar!: Phaser.GameObjects.Graphics
|
protected staminaBar!: Phaser.GameObjects.Graphics
|
||||||
|
private frozenOverlay!: Phaser.GameObjects.Graphics
|
||||||
|
|
||||||
public readonly cost: number
|
public readonly cost: number
|
||||||
public readonly attackRange: number
|
public readonly attackRange: number
|
||||||
@@ -16,6 +17,7 @@ export abstract class TowerBase {
|
|||||||
public readonly attackSpeed: number
|
public readonly attackSpeed: number
|
||||||
public readonly maxStamina: number = STAMINA_MAX
|
public readonly maxStamina: number = STAMINA_MAX
|
||||||
public stamina: number = STAMINA_MAX
|
public stamina: number = STAMINA_MAX
|
||||||
|
public isFrozen: boolean = false
|
||||||
|
|
||||||
protected attackCooldown: number = 0
|
protected attackCooldown: number = 0
|
||||||
protected staminaRegen: number = STAMINA_REGEN
|
protected staminaRegen: number = STAMINA_REGEN
|
||||||
@@ -47,12 +49,20 @@ export abstract class TowerBase {
|
|||||||
|
|
||||||
this.sprite = scene.add.graphics()
|
this.sprite = scene.add.graphics()
|
||||||
this.staminaBar = scene.add.graphics()
|
this.staminaBar = scene.add.graphics()
|
||||||
|
this.frozenOverlay = scene.add.graphics()
|
||||||
|
|
||||||
this.drawSprite()
|
this.drawSprite()
|
||||||
this.updateStaminaBar()
|
this.updateStaminaBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
update(delta: number, enemies: EnemyBase[]): void {
|
update(delta: number, enemies: EnemyBase[]): void {
|
||||||
|
// 禁锢状态:跳过攻击,显示灰色覆盖
|
||||||
|
if (this.isFrozen) {
|
||||||
|
this.drawFrozenOverlay()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 解除禁锢时清除覆盖层
|
||||||
|
this.clearFrozenOverlay()
|
||||||
this.attackCooldown -= delta
|
this.attackCooldown -= delta
|
||||||
|
|
||||||
if (this.stamina <= 0) {
|
if (this.stamina <= 0) {
|
||||||
@@ -135,11 +145,31 @@ export abstract class TowerBase {
|
|||||||
return { x: this.px, y: this.py }
|
return { x: this.px, y: this.py }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 绘制禁锢状态灰色覆盖层 */
|
||||||
|
protected drawFrozenOverlay(): void {
|
||||||
|
this.frozenOverlay.clear()
|
||||||
|
const half = TILE_SIZE / 2
|
||||||
|
this.frozenOverlay.fillStyle(0x6b7280, 0.6)
|
||||||
|
this.frozenOverlay.fillRect(
|
||||||
|
this.px - half,
|
||||||
|
this.py - half,
|
||||||
|
TILE_SIZE,
|
||||||
|
TILE_SIZE
|
||||||
|
)
|
||||||
|
this.frozenOverlay.setDepth(13)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 清除禁锢覆盖层 */
|
||||||
|
protected clearFrozenOverlay(): void {
|
||||||
|
this.frozenOverlay.clear()
|
||||||
|
}
|
||||||
|
|
||||||
abstract attack(target: EnemyBase): void
|
abstract attack(target: EnemyBase): void
|
||||||
abstract drawSprite(): void
|
abstract drawSprite(): void
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
this.sprite?.destroy()
|
this.sprite?.destroy()
|
||||||
this.staminaBar?.destroy()
|
this.staminaBar?.destroy()
|
||||||
|
this.frozenOverlay?.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user