diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index ef92bcb..915aa44 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -58,5 +58,13 @@ "maxDiagonalProjectileUpgrades": 0, "maxHaloProjectileUpgrades": 5, "maxRegenerationUpgrades": 5 + }, + "enemyManager": { + "waveEnemySpawner": { + "cooldown": 5, + "enemiesPerWave": 30, + "waveLifetime": 20, + "enemyType": "Basic" + } } } \ No newline at end of file diff --git a/assets/Scenes/scene.scene b/assets/Scenes/scene.scene index 0ab852f..700c6b5 100644 --- a/assets/Scenes/scene.scene +++ b/assets/Scenes/scene.scene @@ -2080,7 +2080,7 @@ "_id": "936Vpv3ydL8JZMvakVgAP5" }, { - "__type__": "7914boZbMpO4oIxuuvZ61Wb", + "__type__": "2260cGJEAdNlpJwzk5tNSzU", "_name": "", "_objFlags": 0, "node": { @@ -2094,7 +2094,7 @@ "__expectedType__": "cc.Prefab" } ], - "_id": "55UHuO7YRLaa/e/fP7FAK2" + "_id": "ebqmDEqu5OGJivYBW47skm" }, { "__type__": "839f4SZvHNBFaiDSpMi6pOJ", diff --git a/assets/Scripts/Game/Data/GameSettings.ts b/assets/Scripts/Game/Data/GameSettings.ts index f9ababd..8c08b5b 100644 --- a/assets/Scripts/Game/Data/GameSettings.ts +++ b/assets/Scripts/Game/Data/GameSettings.ts @@ -1,6 +1,7 @@ export class GameSettings { public player: PlayerSettings = new PlayerSettings(); public upgrades: UpgradeSettings = new UpgradeSettings(); + public enemyManager: EnemyManagerSettings = new EnemyManagerSettings(); } export class PlayerSettings { @@ -46,3 +47,14 @@ export class UpgradeSettings { public maxHaloProjectileUpgrades = 0; public maxRegenerationUpgrades = 0; } + +export class EnemyManagerSettings { + public waveEnemySpawner = new WaveEnemySpawnerSettings(); +} + +export class WaveEnemySpawnerSettings { + public cooldown = 0; + public enemiesPerWave = 0; + public waveLifetime = 0; + public enemyType = ""; +} diff --git a/assets/Scripts/Game/GameBootstrapper.ts b/assets/Scripts/Game/GameBootstrapper.ts index 9c72c9f..ab70ea4 100644 --- a/assets/Scripts/Game/GameBootstrapper.ts +++ b/assets/Scripts/Game/GameBootstrapper.ts @@ -52,7 +52,7 @@ export class GameBootstrapper extends Component { this.playerCollisionSystem = new PlayerCollisionSystem(this.player, settings.player.collisionDelay); new WeaponCollisionSystem(this.player.Weapon); - this.enemyManager.init(this.player.node); + this.enemyManager.init(this.player.node, settings.enemyManager); this.haloProjectileLauncher = new HaloProjectileLauncher( this.haloProjectileLauncherComponent, diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts index a3cc726..af35d23 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts @@ -1,15 +1,17 @@ import { Component, Node, _decorator } from "cc"; +import { EnemyManagerSettings } from "../../Data/GameSettings"; import { XPSpawner } from "../../XP/XPSpawner"; -import { CircularEnemySpawner } from "./CircularEnemySpawner"; import { Enemy } from "./Enemy"; import { EnemyMovementType } from "./EnemyMovementType"; -import { EnemyMover } from "./EnemyMover"; -import { EnemySpawner } from "./EnemySpawner"; +import { EnemyMover } from "./EnemyMover/EnemyMover"; +import { FollowTargetEnemyMover } from "./EnemyMover/FollowTargetEnemyMover"; +import { WaveEnemyMover } from "./EnemyMover/WaveEnemyMover"; +import { CircularEnemySpawner } from "./EnemySpawner/CircularEnemySpawner"; +import { EnemySpawner } from "./EnemySpawner/EnemySpawner"; +import { IndividualEnemySpawner } from "./EnemySpawner/IndividualEnemySpawner"; +import { WaveEnemySpawner } from "./EnemySpawner/WaveEnemySpawner"; import { EnemyType } from "./EnemyType"; -import { FollowTargetEnemyMover } from "./FollowTargetEnemyMover"; -import { InvididualEnemySpawner as IndividualEnemySpawner } from "./InvididualEnemySpawner"; -import { LaunchToTargetEnemyMover } from "./LaunchToTargetEnemyMover"; -import { WaveEnemySpawner } from "./WaveEnemySpawner"; + const { ccclass, property } = _decorator; @ccclass("EnemyManager") @@ -23,24 +25,24 @@ export class EnemyManager extends Component { private circularEnemySpawner: CircularEnemySpawner; private waveEnemySpawner: WaveEnemySpawner; - public init(targetNode: Node): void { + public init(targetNode: Node, settings: EnemyManagerSettings): void { this.enemySpawner.init(targetNode); this.enemySpawner.EnemyAddedEvent.on(this.onEnemyAdded, this); this.enemySpawner.enemyRemovedEvent.on(this.onRemoveEnemy, this); this.individualEnemySpawner = new IndividualEnemySpawner(this.enemySpawner, EnemyType.Basic); this.circularEnemySpawner = new CircularEnemySpawner(this.enemySpawner, 30, EnemyType.Basic); - this.waveEnemySpawner = new WaveEnemySpawner(this.enemySpawner, 30, 10, EnemyType.Basic); + this.waveEnemySpawner = new WaveEnemySpawner(this.enemySpawner, settings.waveEnemySpawner); this.movementTypeToMover.set(EnemyMovementType.Follow, new FollowTargetEnemyMover(targetNode)); - this.movementTypeToMover.set(EnemyMovementType.Launch, new LaunchToTargetEnemyMover(targetNode)); + this.movementTypeToMover.set(EnemyMovementType.Launch, new WaveEnemyMover(targetNode)); this.xpSpawner.init(); } public gameTick(deltaTime: number): void { - //this.individualEnemySpawner.gameTick(deltaTime); - //this.circularEnemySpawner.gameTick(deltaTime); + this.individualEnemySpawner.gameTick(deltaTime); + this.circularEnemySpawner.gameTick(deltaTime); this.waveEnemySpawner.gameTick(deltaTime); for (const kvp of this.movementTypeToMover) { diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyMover.meta b/assets/Scripts/Game/Unit/Enemy/EnemyMover.meta new file mode 100644 index 0000000..b02ed38 --- /dev/null +++ b/assets/Scripts/Game/Unit/Enemy/EnemyMover.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "19a29ec1-9090-43e5-ab3f-8b7430e496ed", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyMover.ts b/assets/Scripts/Game/Unit/Enemy/EnemyMover/EnemyMover.ts similarity index 94% rename from assets/Scripts/Game/Unit/Enemy/EnemyMover.ts rename to assets/Scripts/Game/Unit/Enemy/EnemyMover/EnemyMover.ts index 6cb5eb0..2bf477c 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemyMover.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemyMover/EnemyMover.ts @@ -1,5 +1,5 @@ import { Node } from "cc"; -import { Enemy } from "./Enemy"; +import { Enemy } from "../Enemy"; export abstract class EnemyMover { protected targetNode: Node; diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyMover.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemyMover/EnemyMover.ts.meta similarity index 100% rename from assets/Scripts/Game/Unit/Enemy/EnemyMover.ts.meta rename to assets/Scripts/Game/Unit/Enemy/EnemyMover/EnemyMover.ts.meta diff --git a/assets/Scripts/Game/Unit/Enemy/FollowTargetEnemyMover.ts b/assets/Scripts/Game/Unit/Enemy/EnemyMover/FollowTargetEnemyMover.ts similarity index 100% rename from assets/Scripts/Game/Unit/Enemy/FollowTargetEnemyMover.ts rename to assets/Scripts/Game/Unit/Enemy/EnemyMover/FollowTargetEnemyMover.ts diff --git a/assets/Scripts/Game/Unit/Enemy/FollowTargetEnemyMover.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemyMover/FollowTargetEnemyMover.ts.meta similarity index 100% rename from assets/Scripts/Game/Unit/Enemy/FollowTargetEnemyMover.ts.meta rename to assets/Scripts/Game/Unit/Enemy/EnemyMover/FollowTargetEnemyMover.ts.meta diff --git a/assets/Scripts/Game/Unit/Enemy/LaunchToTargetEnemyMover.ts b/assets/Scripts/Game/Unit/Enemy/EnemyMover/WaveEnemyMover.ts similarity index 93% rename from assets/Scripts/Game/Unit/Enemy/LaunchToTargetEnemyMover.ts rename to assets/Scripts/Game/Unit/Enemy/EnemyMover/WaveEnemyMover.ts index 58d7b84..7828ba5 100644 --- a/assets/Scripts/Game/Unit/Enemy/LaunchToTargetEnemyMover.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemyMover/WaveEnemyMover.ts @@ -1,8 +1,8 @@ import { Vec3 } from "cc"; -import { Enemy } from "./Enemy"; +import { Enemy } from "../Enemy"; import { EnemyMover } from "./EnemyMover"; -export class LaunchToTargetEnemyMover extends EnemyMover { +export class WaveEnemyMover extends EnemyMover { private enemyToDirection: Map = new Map(); private lastTargetPosition: Vec3 = new Vec3(); private lastDirection: Vec3 = new Vec3(); diff --git a/assets/Scripts/Game/Unit/Enemy/LaunchToTargetEnemyMover.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemyMover/WaveEnemyMover.ts.meta similarity index 100% rename from assets/Scripts/Game/Unit/Enemy/LaunchToTargetEnemyMover.ts.meta rename to assets/Scripts/Game/Unit/Enemy/EnemyMover/WaveEnemyMover.ts.meta diff --git a/assets/Scripts/Game/Unit/Enemy/CircularEnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts similarity index 73% rename from assets/Scripts/Game/Unit/Enemy/CircularEnemySpawner.ts rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts index 8308786..a413bb9 100644 --- a/assets/Scripts/Game/Unit/Enemy/CircularEnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts @@ -1,8 +1,8 @@ -import { GameTimer } from "../../../Services/GameTimer"; -import { roundToOneDecimal } from "../../../Services/Utils/MathUtils"; -import { EnemyMovementType } from "./EnemyMovementType"; -import { EnemySpawner } from "./EnemySpawner"; -import { EnemyType } from "./EnemyType"; +import { GameTimer } from "../../../../Services/GameTimer"; +import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils"; +import { EnemyMovementType } from "../EnemyMovementType"; +import { EnemySpawner } from "../EnemySpawner"; +import { EnemyType } from "../EnemyType"; export class CircularEnemySpawner { private spawnTimer: GameTimer = new GameTimer(10); diff --git a/assets/Scripts/Game/Unit/Enemy/CircularEnemySpawner.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts.meta similarity index 100% rename from assets/Scripts/Game/Unit/Enemy/CircularEnemySpawner.ts.meta rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/CircularEnemySpawner.ts.meta diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.meta b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.meta new file mode 100644 index 0000000..4ba5a67 --- /dev/null +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "c3d97e6e-d624-48f8-a337-7bc21688eb22", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts similarity index 80% rename from assets/Scripts/Game/Unit/Enemy/EnemySpawner.ts rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts index 7445087..8403eb1 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts @@ -1,10 +1,10 @@ -import { Component, Node, Prefab, Vec3, _decorator } from "cc"; -import { ISignal } from "../../../Services/EventSystem/ISignal"; -import { Signal } from "../../../Services/EventSystem/Signal"; -import { ObjectPool } from "../../../Services/ObjectPool"; +import { _decorator, Component, Prefab, Vec3, Node } from "cc"; +import { ISignal } from "../../../../Services/EventSystem/ISignal"; +import { Signal } from "../../../../Services/EventSystem/Signal"; +import { ObjectPool } from "../../../../Services/ObjectPool"; +import { Enemy } from "../Enemy"; +import { EnemyMovementType } from "../EnemyMovementType"; -import { Enemy } from "./Enemy"; -import { EnemyMovementType } from "./EnemyMovementType"; const { ccclass, property } = _decorator; @ccclass("EnemySpawner") diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts.meta similarity index 70% rename from assets/Scripts/Game/Unit/Enemy/EnemySpawner.ts.meta rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts.meta index c0a6ee9..a9f746d 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemySpawner.ts.meta +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.23", "importer": "typescript", "imported": true, - "uuid": "7914ba19-6cca-4ee2-8231-baebd9eb559b", + "uuid": "2260c189-1007-4d96-9270-ce4e6d352cd4", "files": [], "subMetas": {}, "userData": {} diff --git a/assets/Scripts/Game/Unit/Enemy/InvididualEnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts similarity index 64% rename from assets/Scripts/Game/Unit/Enemy/InvididualEnemySpawner.ts rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts index b7932b5..7ae9020 100644 --- a/assets/Scripts/Game/Unit/Enemy/InvididualEnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts @@ -1,11 +1,11 @@ import { randomRange } from "cc"; -import { GameTimer } from "../../../Services/GameTimer"; -import { randomPositiveOrNegative } from "../../../Services/Utils/MathUtils"; -import { EnemyMovementType } from "./EnemyMovementType"; -import { EnemySpawner } from "./EnemySpawner"; -import { EnemyType } from "./EnemyType"; +import { GameTimer } from "../../../../Services/GameTimer"; +import { randomPositiveOrNegative } from "../../../../Services/Utils/MathUtils"; +import { EnemyMovementType } from "../EnemyMovementType"; +import { EnemySpawner } from "../EnemySpawner"; +import { EnemyType } from "../EnemyType"; -export class InvididualEnemySpawner { +export class IndividualEnemySpawner { private spawnTimer: GameTimer = new GameTimer(1); public constructor(private enemySpawner: EnemySpawner, private enemyType: EnemyType) {} diff --git a/assets/Scripts/Game/Unit/Enemy/InvididualEnemySpawner.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts.meta similarity index 70% rename from assets/Scripts/Game/Unit/Enemy/InvididualEnemySpawner.ts.meta rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts.meta index 75f17e8..683bcb0 100644 --- a/assets/Scripts/Game/Unit/Enemy/InvididualEnemySpawner.ts.meta +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/IndividualEnemySpawner.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.23", "importer": "typescript", "imported": true, - "uuid": "46674857-f5ad-4112-8b5d-c19879117904", + "uuid": "2deef32d-8a42-4617-8466-55c49b0a6439", "files": [], "subMetas": {}, "userData": {} diff --git a/assets/Scripts/Game/Unit/Enemy/WaveEnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts similarity index 58% rename from assets/Scripts/Game/Unit/Enemy/WaveEnemySpawner.ts rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts index 927cf16..4fb667e 100644 --- a/assets/Scripts/Game/Unit/Enemy/WaveEnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts @@ -1,20 +1,26 @@ import { randomRange } from "cc"; -import { GameTimer } from "../../../Services/GameTimer"; -import { randomPositiveOrNegative } from "../../../Services/Utils/MathUtils"; -import { Enemy } from "./Enemy"; -import { EnemyMovementType } from "./EnemyMovementType"; -import { EnemySpawner } from "./EnemySpawner"; -import { EnemyType } from "./EnemyType"; +import { GameTimer } from "../../../../Services/GameTimer"; +import { randomPositiveOrNegative } from "../../../../Services/Utils/MathUtils"; +import { WaveEnemySpawnerSettings } from "../../../Data/GameSettings"; +import { Enemy } from "../Enemy"; +import { EnemyMovementType } from "../EnemyMovementType"; +import { EnemySpawner } from "../EnemySpawner"; +import { EnemyType } from "../EnemyType"; export class WaveEnemySpawner { - private spawnTimer: GameTimer = new GameTimer(5); + private enemiesPerWave: number; + private waveLifetime: number; + private enemyType: EnemyType; + + private spawnTimer: GameTimer; private waves: EnemyWave[] = []; - public constructor( - private enemySpawner: EnemySpawner, - private enemiesToSpawn: number, - private enemyLifeTime: number, - private enemyType: EnemyType - ) {} + + public constructor(private enemySpawner: EnemySpawner, settings: WaveEnemySpawnerSettings) { + this.spawnTimer = new GameTimer(settings.cooldown); + this.enemiesPerWave = settings.enemiesPerWave; + this.waveLifetime = settings.waveLifetime; + this.enemyType = settings.enemyType; + } public gameTick(deltaTime: number): void { this.spawnTimer.gameTick(deltaTime); @@ -27,9 +33,12 @@ export class WaveEnemySpawner { for (let i = this.waves.length - 1; 0 <= i; i--) { const wave: EnemyWave = this.waves[i]; wave.lifeTimeLeft -= deltaTime; + if (wave.lifeTimeLeft <= 0) { for (const enemy of wave.enemies) { - this.enemySpawner.returnEnemy(enemy); + if (enemy.Health.IsAlive) { + this.enemySpawner.returnEnemy(enemy); + } } this.waves.splice(i, 1); @@ -43,8 +52,8 @@ export class WaveEnemySpawner { const defaultPosY: number = 200 * randomPositiveOrNegative(); const enemies: Enemy[] = []; - const side: number = Math.ceil(Math.sqrt(this.enemiesToSpawn)); - for (let i = 0; i < this.enemiesToSpawn; i++) { + const side: number = Math.ceil(Math.sqrt(this.enemiesPerWave)); + for (let i = 0; i < this.enemiesPerWave; i++) { const randomOffsetX: number = randomRange(-20, 20); const randomOffsetY: number = randomRange(-20, 20); const posX: number = defaultPosX + randomOffsetX + 50 * (i % side); @@ -53,7 +62,7 @@ export class WaveEnemySpawner { enemies.push(enemy); } - this.waves.push({ enemies, lifeTimeLeft: this.enemyLifeTime }); + this.waves.push({ enemies, lifeTimeLeft: this.waveLifetime }); } } } diff --git a/assets/Scripts/Game/Unit/Enemy/WaveEnemySpawner.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts.meta similarity index 100% rename from assets/Scripts/Game/Unit/Enemy/WaveEnemySpawner.ts.meta rename to assets/Scripts/Game/Unit/Enemy/EnemySpawner/WaveEnemySpawner.ts.meta