diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index 4cd8341..3b1741a 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -62,28 +62,51 @@ "enemyManager": { "enemies": [ { - "id": "Basic", + "id": "BasicEnemy", "moveType": "Follow", "health": 1, "damage": 1, "speed": 50 }, { - "id": "Wave", + "id": "WaveEnemy", "moveType": "Launch", "health": 1, "damage": 1, "speed": 100 } ], + "individualEnemySpawners": [ + { + "common": { + "enemyId": "BasicEnemy", + "startDelay": 0, + "stopDelay": -1, + "cooldown": 2 + } + } + ], + "circularEnemySpawners": [ + { + "common": { + "enemyId": "BasicEnemy", + "startDelay": 5, + "stopDelay": -1, + "cooldown": 10 + }, + "enemiesToSpawn": 50 + } + ], "waveEnemySpawners": [ { - "startDelay": 0, - "stopDelay": 10000, - "cooldown": 5, - "enemiesPerWave": 30, - "waveLifetime": 20, - "enemyId": "Wave" + "common": { + "enemyId": "WaveEnemy", + "startDelay": 5, + "stopDelay": -1, + "cooldown": 5 + }, + "enemiesToSpawn": 10, + "waveLifetime": 50 } ] } diff --git a/assets/Scripts/Game/Data/GameSettings.ts b/assets/Scripts/Game/Data/GameSettings.ts index 0c05d99..fd50287 100644 --- a/assets/Scripts/Game/Data/GameSettings.ts +++ b/assets/Scripts/Game/Data/GameSettings.ts @@ -50,16 +50,31 @@ export class UpgradeSettings { export class EnemyManagerSettings { public enemies: EnemySettings[] = [new EnemySettings()]; + public individualEnemySpawners: IndividualEnemySpawnerSettings[] = [new IndividualEnemySpawnerSettings()]; + public circularEnemySpawners: CircularEnemySpawnerSettings[] = [new CircularEnemySpawnerSettings()]; public waveEnemySpawners: WaveEnemySpawnerSettings[] = [new WaveEnemySpawnerSettings()]; } -export class WaveEnemySpawnerSettings { +export class GeneralEnemySpawnerSettings { + public enemyId = ""; public startDelay = 0; public stopDelay = 0; public cooldown = 0; - public enemiesPerWave = 0; +} + +export class WaveEnemySpawnerSettings { + public common = new GeneralEnemySpawnerSettings(); + public enemiesToSpawn = 0; public waveLifetime = 0; - public enemyId = ""; +} + +export class CircularEnemySpawnerSettings { + public common = new GeneralEnemySpawnerSettings(); + public enemiesToSpawn = 0; +} + +export class IndividualEnemySpawnerSettings { + public common = new GeneralEnemySpawnerSettings(); } export class EnemySettings { diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts index ebefc1f..bd18948 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts @@ -24,22 +24,26 @@ export class EnemyManager extends Component { private spawners: DelayedEnemySpawner[] = []; - private individualEnemySpawner: IndividualEnemySpawner; - private circularEnemySpawner: CircularEnemySpawner; - public init(targetNode: Node, settings: EnemyManagerSettings): void { this.enemySpawner.init(targetNode, settings.enemies); this.enemySpawner.EnemyAddedEvent.on(this.onEnemyAdded, this); this.enemySpawner.enemyRemovedEvent.on(this.onRemoveEnemy, this); + for (const individualSpawnerSettings of settings.individualEnemySpawners) { + const individualSpawner = new IndividualEnemySpawner(this.enemySpawner, individualSpawnerSettings); + this.spawners.push(individualSpawner); + } + + for (const circularSpawnerSettings of settings.circularEnemySpawners) { + const circularSpawner = new CircularEnemySpawner(this.enemySpawner, circularSpawnerSettings); + this.spawners.push(circularSpawner); + } + for (const waveSpawnerSettings of settings.waveEnemySpawners) { const waveSpawner = new WaveEnemySpawner(this.enemySpawner, waveSpawnerSettings); this.spawners.push(waveSpawner); } - this.individualEnemySpawner = new IndividualEnemySpawner(this.enemySpawner, "Basic", 0); - this.circularEnemySpawner = new CircularEnemySpawner(this.enemySpawner, 30, "Basic", 5); - this.movementTypeToMover.set(EnemyMovementType.Follow, new FollowTargetEnemyMover(targetNode)); this.movementTypeToMover.set(EnemyMovementType.Launch, new WaveEnemyMover(targetNode)); this.movementTypeToMover.set(EnemyMovementType.PeriodicFollow, new PeriodicFollowTargetEnemyMover(targetNode, 5, 5)); @@ -48,9 +52,6 @@ export class EnemyManager extends Component { } public gameTick(deltaTime: number): void { - this.individualEnemySpawner.gameTick(deltaTime); - this.circularEnemySpawner.gameTick(deltaTime); - for (const spawner of this.spawners) { spawner.gameTick(deltaTime); } diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts index 2ddce89..96b21a4 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts @@ -1,14 +1,21 @@ import { GameTimer } from "../../../../Services/GameTimer"; import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils"; +import { CircularEnemySpawnerSettings } from "../../../Data/GameSettings"; import { DelayedEnemySpawner } from "./DelayedEnemySpawner"; import { EnemySpawner } from "./EnemySpawner"; export class CircularEnemySpawner extends DelayedEnemySpawner { - private spawnTimer: GameTimer = new GameTimer(10); + private spawnTimer: GameTimer; + private enemyId: string; + private enemiesToSpawn: number; - public constructor(private enemySpawner: EnemySpawner, private enemiesToSpawn: number, private enemyId: string, startDelay = 0, stopDelay = 100) { - super(startDelay, stopDelay); + public constructor(private enemySpawner: EnemySpawner, settings: CircularEnemySpawnerSettings) { + super(settings.common.startDelay, settings.common.stopDelay); + + this.spawnTimer = new GameTimer(settings.common.cooldown); + this.enemyId = settings.common.enemyId; + this.enemiesToSpawn = settings.enemiesToSpawn; } public delayedGameTick(deltaTime: number): void { diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/DelayedEnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/DelayedEnemySpawner.ts index fb59d7b..29cd529 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/DelayedEnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/DelayedEnemySpawner.ts @@ -1,6 +1,10 @@ export abstract class DelayedEnemySpawner { private currentTime = 0; - public constructor(private startDelay: number, private stopDelay: number) {} + public constructor(private startDelay: number, private stopDelay: number) { + if (stopDelay === -1) { + this.stopDelay = Number.MAX_SAFE_INTEGER; + } + } public gameTick(deltaTime: number): void { this.currentTime += deltaTime; diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts index 9bd0c2b..3a10718 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts @@ -1,14 +1,19 @@ import { randomRange } from "cc"; import { GameTimer } from "../../../../Services/GameTimer"; import { randomPositiveOrNegative } from "../../../../Services/Utils/MathUtils"; +import { IndividualEnemySpawnerSettings } from "../../../Data/GameSettings"; import { DelayedEnemySpawner } from "./DelayedEnemySpawner"; import { EnemySpawner } from "./EnemySpawner"; export class IndividualEnemySpawner extends DelayedEnemySpawner { - private spawnTimer: GameTimer = new GameTimer(1); + private spawnTimer: GameTimer; + private enemyId: string; - public constructor(private enemySpawner: EnemySpawner, private enemyId: string, startDelay = 0, stopDelay = 100) { - super(startDelay, stopDelay); + public constructor(private enemySpawner: EnemySpawner, settings: IndividualEnemySpawnerSettings) { + super(settings.common.startDelay, settings.common.stopDelay); + + this.spawnTimer = new GameTimer(settings.common.cooldown); + this.enemyId = settings.common.enemyId; } public delayedGameTick(deltaTime: number): void { diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts index b32d99f..af942c9 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts @@ -15,12 +15,12 @@ export class WaveEnemySpawner extends DelayedEnemySpawner { private waves: EnemyWave[] = []; public constructor(private enemySpawner: EnemySpawner, settings: WaveEnemySpawnerSettings) { - super(settings.startDelay, settings.stopDelay); + super(settings.common.startDelay, settings.common.stopDelay); - this.spawnTimer = new GameTimer(settings.cooldown); - this.enemiesPerWave = settings.enemiesPerWave; + this.spawnTimer = new GameTimer(settings.common.cooldown); + this.enemiesPerWave = settings.enemiesToSpawn; this.waveLifetime = settings.waveLifetime; - this.enemyId = settings.enemyId; + this.enemyId = settings.common.enemyId; } public delayedGameTick(deltaTime: number): void {