diff --git a/game/enemies/BossVP.ts b/game/enemies/BossVP.ts index 4a16965..ea531a1 100644 --- a/game/enemies/BossVP.ts +++ b/game/enemies/BossVP.ts @@ -14,9 +14,9 @@ export class BossVP extends EnemyBase { ) { 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) + // BOSS 放大到 1.3 个格子(跨格的威压感) + const bossSize = this.cellW * 1.3 + this.imageSprite.setDisplaySize(bossSize, bossSize) this.imageSprite.setDepth(12) // BOSS 出现特效 scene.cameras.main.flash(800, 255, 0, 0, false) diff --git a/game/enemies/EnemyBase.ts b/game/enemies/EnemyBase.ts index 78747bb..17a2315 100644 --- a/game/enemies/EnemyBase.ts +++ b/game/enemies/EnemyBase.ts @@ -87,10 +87,10 @@ export abstract class EnemyBase { this.y = pathPoints[0].y } - // 用 AI 图片精灵,尺寸按格子缩放 + // 用 AI 图片精灵,精确设为格子尺寸的 75%(怪物比塔小一点) + const enemySize = cellW * 0.75 this.imageSprite = scene.add.image(this.x, this.y, spriteKey) - const scale = Math.min(cellW, cellH) / 128 * 0.75 - this.imageSprite.setScale(scale) + this.imageSprite.setDisplaySize(enemySize, enemySize) this.imageSprite.setDepth(10) this.healthBar = scene.add.graphics() diff --git a/game/enemies/OldEmployee.ts b/game/enemies/OldEmployee.ts index fccb464..fd2bc2e 100644 --- a/game/enemies/OldEmployee.ts +++ b/game/enemies/OldEmployee.ts @@ -6,9 +6,8 @@ export class OldEmployee extends EnemyBase { constructor(scene: Phaser.Scene, pathPoints: PathPoint[]) { super(scene, pathPoints, 150, 50, 8, 30, 'enemy-old') this.shieldCount = 3 - // 老员工图片稍大 - const scale = Math.min(this.cellW, this.cellH) / 128 * 0.9 - this.imageSprite.setScale(scale) + // 老员工比普通怪略大(0.85 个格子) + this.imageSprite.setDisplaySize(this.cellW * 0.85, this.cellW * 0.85) } getQuote(): string { return getRandomQuote('OldEmployee') } diff --git a/game/mapRenderer.ts b/game/mapRenderer.ts index 6b7fb71..bbee42e 100644 --- a/game/mapRenderer.ts +++ b/game/mapRenderer.ts @@ -3,6 +3,7 @@ import { MAP_COLS, MAP_ROWS, GAME_WIDTH, + GAME_HEIGHT, HUD_HEIGHT, PATH_WAYPOINTS, COLOR_PATH, @@ -36,11 +37,12 @@ export function buildPathTiles( export const PATH_TILES = buildPathTiles(PATH_WAYPOINTS) -/** 计算格子尺寸 */ +/** 计算格子尺寸(正方形格子,取宽高中较小值保证正方形) */ export function getCellSize() { - const cellW = Math.floor(GAME_WIDTH / MAP_COLS) - const cellH = Math.floor((720 - HUD_HEIGHT) / MAP_ROWS) - return { cellW, cellH } + const rawW = Math.floor(GAME_WIDTH / MAP_COLS) // 80 + const rawH = Math.floor((GAME_HEIGHT - HUD_HEIGHT) / MAP_ROWS) // 55 + const cell = Math.min(rawW, rawH) // 55 → 正方形 + return { cellW: cell, cellH: cell } } /** diff --git a/game/towers/TowerBase.ts b/game/towers/TowerBase.ts index 4e7af0a..345a4ac 100644 --- a/game/towers/TowerBase.ts +++ b/game/towers/TowerBase.ts @@ -56,10 +56,10 @@ export abstract class TowerBase { this.px = gridX * cellW + cellW / 2 this.py = HUD_HEIGHT + gridY * cellH + cellH / 2 - // 用 AI 图片作为精灵 + // 用 AI 图片作为精灵,精确设为格子尺寸的 85%(留边距) + const imgSize = cellW * 0.85 this.imageSprite = scene.add.image(this.px, this.py, spriteKey) - const scale = Math.min(cellW, cellH) / 128 * 0.85 - this.imageSprite.setScale(scale) + this.imageSprite.setDisplaySize(imgSize, imgSize) this.imageSprite.setDepth(10) this.staminaBar = scene.add.graphics()