diff --git a/src/app/components/game/sim/actions/SimActionMoveEnemies.ts b/src/app/components/game/sim/actions/SimActionMoveEnemies.ts index cfe8ab4..25e57d7 100644 --- a/src/app/components/game/sim/actions/SimActionMoveEnemies.ts +++ b/src/app/components/game/sim/actions/SimActionMoveEnemies.ts @@ -1,43 +1,42 @@ -import { Hex } from "../../util/Hex"; -import { Vector2 } from "../../util/Vector2"; -import { SimEnemy } from "../SimEnemy"; -import { SimMain } from "../SimMain"; -import { ISimAction } from "./ISimAction"; +import { Hex } from '../../util/Hex'; +import { Vector2 } from '../../util/Vector2'; +import { SimEnemy } from '../SimEnemy'; +import { SimMain } from '../SimMain'; +import { ISimAction } from './ISimAction'; export class SimActionMoveEnemies implements ISimAction { - public execute(simMain: SimMain) { - const level = simMain.currentLevel; - if (!level) return; + public execute(simMain: SimMain) { + const level = simMain.currentLevel; + if (!level) return; - const deadEnemies: number[] = []; - level.enemies.forEach((enemy: SimEnemy, idx: number) => { - if (enemy.dead) - deadEnemies.push(idx); - }); + const deadEnemies: number[] = []; + level.enemies.forEach((enemy: SimEnemy, idx: number) => { + if (enemy.dead) deadEnemies.push(idx); + }); - for (const idx of deadEnemies) { - level.enemies.splice(idx, 1); - } + for (const idx of deadEnemies) { + level.enemies.splice(idx, 1); + } - for (const simEnemy of level.enemies) { - const duration = simEnemy.speed / simMain.gdRoot.simulation.stepsPerSecond; - const t = (level.currentStep - simEnemy.currentPathStep) * duration; - const path2 = level.cells[simEnemy.path[simEnemy.currentPathIndex + 1]]; - if (!path2) { - simEnemy.dead = true; - return; - } + for (const simEnemy of level.enemies) { + const duration = simEnemy.speed / simMain.gdRoot.simulation.stepsPerSecond; + const t = (level.currentStep - simEnemy.currentPathStep) * duration; + const path2 = level.cells[simEnemy.path[simEnemy.currentPathIndex + 1]]; + if (!path2) { + simEnemy.dead = true; + return; + } - const hex2 = path2.hex; - const pos1 = simEnemy.currentPathPosition; - const pos2 = Hex.toWorld(hex2); - simEnemy.prevPosition = simEnemy.position; - simEnemy.position = Vector2.lerp(pos1, pos2, t); - if (t >= 1) { - simEnemy.currentPathIndex += 1; - simEnemy.currentPathStep = level.currentStep; - simEnemy.onPathUpdated(level); - } - } - } + const hex2 = path2.hex; + const pos1 = simEnemy.currentPathPosition; + const pos2 = Hex.toWorld(hex2); + simEnemy.prevPosition = simEnemy.position; + simEnemy.position = Vector2.lerp(pos1, pos2, t); + if (t >= 1) { + simEnemy.currentPathIndex += 1; + simEnemy.currentPathStep = level.currentStep; + simEnemy.onPathUpdated(level); + } + } + } } diff --git a/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts b/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts index 561f8e6..9d53d5e 100644 --- a/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts +++ b/src/app/components/game/sim/actions/SimActionSpawnEnemies.ts @@ -44,6 +44,7 @@ export class SimActionSpawnEnemies implements ISimAction { const path = PathFinding.bfs(level, startIndex, endIndex); simEnemy.path = path!; simEnemy.currentPathIndex = 0; + simEnemy.speed = simMain.gdRoot.enemies[gdWave.enemy].speed; simEnemy.onPathUpdated(level); level.enemies.push(simEnemy); }