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]) {