fix spawning of enemies

This commit is contained in:
2025-06-02 21:16:04 +02:00
parent 61b86b7a60
commit c61a10d79a

View File

@@ -1,4 +1,6 @@
import { EEnemySize } from '../../data/EEnemySize'; import { EEnemySize } from '../../data/EEnemySize';
import { Hex } from '../../util/Hex';
import { PathFinding } from '../../util/PathFinding';
import { SimCommandStartNextWave } from '../commands/SimCommandStartNextWave'; import { SimCommandStartNextWave } from '../commands/SimCommandStartNextWave';
import { SimEnemy } from '../SimEnemy'; import { SimEnemy } from '../SimEnemy';
import { SimMain } from '../SimMain'; import { SimMain } from '../SimMain';
@@ -33,9 +35,17 @@ export class SimActionSpawnEnemies implements ISimAction {
level.lastEnemySpawnStep = step; level.lastEnemySpawnStep = step;
const route = Math.floor(Math.random() * gdLevel.enemyRoutes.length); const route = Math.floor(Math.random() * gdLevel.enemyRoutes.length);
const enemy = new SimEnemy(gdWave.enemy, route); const simEnemy = new SimEnemy(gdWave.enemy, route);
enemy.onPathUpdated(level); simEnemy.startHex = gdLevel.enemySpawns[gdLevel.enemyRoutes[route][0]];
level.enemies.push(enemy); 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]) { if (level.nextWaveStep == step && !!gdLevel.waves[level.currentWave + 1]) {