From c61a10d79aed0b5d5a1e3d322564238d29736a05 Mon Sep 17 00:00:00 2001 From: Frank Tovar Date: Mon, 2 Jun 2025 21:16:04 +0200 Subject: [PATCH] fix spawning of enemies --- .../game/sim/actions/SimActionSpawnEnemies.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts b/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts index 5284afe..561f8e6 100644 --- a/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts +++ b/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts @@ -1,4 +1,6 @@ import { EEnemySize } from '../../data/EEnemySize'; +import { Hex } from '../../util/Hex'; +import { PathFinding } from '../../util/PathFinding'; import { SimCommandStartNextWave } from '../commands/SimCommandStartNextWave'; import { SimEnemy } from '../SimEnemy'; import { SimMain } from '../SimMain'; @@ -33,9 +35,17 @@ export class SimActionSpawnEnemies implements ISimAction { level.lastEnemySpawnStep = step; const route = Math.floor(Math.random() * gdLevel.enemyRoutes.length); - const enemy = new SimEnemy(gdWave.enemy, route); - enemy.onPathUpdated(level); - level.enemies.push(enemy); + const simEnemy = new SimEnemy(gdWave.enemy, route); + simEnemy.startHex = gdLevel.enemySpawns[gdLevel.enemyRoutes[route][0]]; + simEnemy.endHex = gdLevel.enemyTargets[gdLevel.enemyRoutes[route][1]]; + simEnemy.position = Hex.toWorld(simEnemy.startHex); + const startIndex = level.getCellIndex(simEnemy.startHex); + const endIndex = level.getCellIndex(simEnemy.endHex); + const path = PathFinding.bfs(level, startIndex, endIndex); + simEnemy.path = path!; + simEnemy.currentPathIndex = 0; + simEnemy.onPathUpdated(level); + level.enemies.push(simEnemy); } if (level.nextWaveStep == step && !!gdLevel.waves[level.currentWave + 1]) {