feat(game/enemies): 所有怪物子类支持 speedMultiplier/hpMultiplier 参数

This commit is contained in:
Cloud Bot
2026-03-21 09:45:17 +00:00
parent bcfd001c11
commit 185fa39b4e
5 changed files with 45 additions and 28 deletions

View File

@@ -1,7 +1,8 @@
import type Phaser from 'phaser'
import { GameManager } from '../GameManager'
import { HUD_HEIGHT, PATH_WAYPOINTS } from '../constants'
import { HUD_HEIGHT } from '../constants'
import { getCellSize } from '../mapRenderer'
import { ALL_MAPS } from '../data/mapConfigs'
export interface PathPoint { x: number; y: number }
@@ -12,12 +13,19 @@ function gridToPixel(gx: number, gy: number, cellW: number, cellH: number): Path
}
}
export function buildFullPath(): PathPoint[] {
/**
* 将地图路径折线坐标转换为像素路径点序列
* @param waypoints 折线关键坐标点默认使用地图1
*/
export function buildFullPath(
waypoints?: readonly { x: number; y: number }[]
): PathPoint[] {
const { cellW, cellH } = getCellSize()
const pts = waypoints ?? ALL_MAPS[0].waypoints
const points: PathPoint[] = []
for (let i = 0; i < PATH_WAYPOINTS.length - 1; i++) {
const from = gridToPixel(PATH_WAYPOINTS[i].x, PATH_WAYPOINTS[i].y, cellW, cellH)
const to = gridToPixel(PATH_WAYPOINTS[i + 1].x, PATH_WAYPOINTS[i + 1].y, cellW, cellH)
for (let i = 0; i < pts.length - 1; i++) {
const from = gridToPixel(pts[i].x, pts[i].y, cellW, cellH)
const to = gridToPixel(pts[i + 1].x, pts[i + 1].y, cellW, cellH)
points.push(from)
points.push(to)
}
@@ -31,7 +39,6 @@ export interface DotEffect { damage: number; duration: number; timer: number }
export abstract class EnemyBase {
protected scene: Phaser.Scene
protected imageSprite!: Phaser.GameObjects.Image
// expose for tower targeting & health bar
public x: number = 0
public y: number = 0
protected healthBar!: Phaser.GameObjects.Graphics
@@ -67,13 +74,15 @@ export abstract class EnemyBase {
speed: number,
kpiDamage: number,
hcReward: number,
spriteKey: string
spriteKey: string,
speedMultiplier: number = 1.0,
hpMultiplier: number = 1.0
) {
this.scene = scene
this.pathPoints = pathPoints
this.maxHp = maxHp
this.hp = maxHp
this.speed = speed
this.maxHp = Math.ceil(maxHp * hpMultiplier)
this.hp = this.maxHp
this.speed = speed * speedMultiplier
this.kpiDamage = kpiDamage
this.hcReward = hcReward
this.spriteKey = spriteKey
@@ -87,7 +96,6 @@ export abstract class EnemyBase {
this.y = pathPoints[0].y
}
// 用 AI 图片精灵,精确设为格子尺寸的 75%(怪物比塔小一点)
const enemySize = cellW * 0.75
this.imageSprite = scene.add.image(this.x, this.y, spriteKey)
this.imageSprite.setDisplaySize(enemySize, enemySize)
@@ -108,7 +116,6 @@ export abstract class EnemyBase {
.setAlpha(0)
this.drawHealthBar()
// 出生后 0.5s 显示语录
scene.time.delayedCall(500, () => { if (!this.isDead) this.showQuote() })
}
@@ -154,7 +161,6 @@ export abstract class EnemyBase {
this.x += (dx / dist) * distance
this.y += (dy / dist) * distance
}
// 减速时图片变色
if (this.slowEffect > 0) {
this.imageSprite.setTint(0x93c5fd)
} else {