From ab39355a5c702013e24c6b090211ec5a7daf2d82 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 30 Nov 2022 11:44:20 +0100 Subject: [PATCH] Vertical launcher --- assets/Data/GameSettings.json | 13 +- assets/Scenes/scene.scene | 8 +- .../PlayerProjectileCollisionSystem.ts | 8 +- assets/Scripts/Game/Data/GameSettings.ts | 7 ++ assets/Scripts/Game/GameBootstrapper.ts | 27 +++-- .../IProjectileCollisionSignaler.ts | 6 + .../IProjectileCollisionSignaler.ts.meta | 9 ++ .../Unit/Player/ProjectileLauncher/Halo.meta | 12 -- .../Halo/HaloProjectileLauncher.ts | 114 ------------------ .../HaloProjectileLauncher.ts | 44 +++++++ .../{Halo => }/HaloProjectileLauncher.ts.meta | 0 .../ProjectileLauncher/ProjectileLauncher.ts | 70 ++++++++--- .../VerticalProjectileLauncher.ts | 31 +++++ .../VerticalProjectileLauncher.ts.meta | 9 ++ assets/Scripts/Game/Upgrades/UpgradeType.ts | 4 +- assets/Scripts/Game/Upgrades/Upgrader.ts | 22 +++- 16 files changed, 221 insertions(+), 163 deletions(-) create mode 100644 assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts create mode 100644 assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts.meta delete mode 100644 assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo.meta delete mode 100644 assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher.ts create mode 100644 assets/Scripts/Game/Unit/Player/ProjectileLauncher/HaloProjectileLauncher.ts rename assets/Scripts/Game/Unit/Player/ProjectileLauncher/{Halo => }/HaloProjectileLauncher.ts.meta (100%) create mode 100644 assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts create mode 100644 assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts.meta diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index b379972..4b9e79d 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -21,13 +21,24 @@ }, "haloLauncher": { "projectilesToSpawn": 24, + "cooldownDivisorPerUpgrade": 1, "launcher": { - "projectileLifetime": 5, + "projectileLifetime": 2, "projectileSpeed": 150, "wavesToShoot": 1, "wavesDelayMs": 0, "cooldown": 10 } + }, + "xyLaunchers": { + "wavesToShootPerUpgrade": 1, + "launcher": { + "projectileLifetime": 20, + "projectileSpeed": 300, + "wavesToShoot": 0, + "wavesDelayMs": 100, + "cooldown": 4 + } } }, "upgrades": { diff --git a/assets/Scenes/scene.scene b/assets/Scenes/scene.scene index 18b0883..4215b00 100644 --- a/assets/Scenes/scene.scene +++ b/assets/Scenes/scene.scene @@ -141,7 +141,7 @@ "_id": "61KOckV1dET5kaFFrJFLGb" }, { - "__type__": "422b4bsPhVDfZf8f0Sid8O+", + "__type__": "e3d066A8exFBaWWn2gx4c4j", "_name": "", "_objFlags": 0, "node": { @@ -153,7 +153,7 @@ "__uuid__": "ff0be112-7028-424c-87b8-fc54a106015a", "__expectedType__": "cc.Prefab" }, - "_id": "02VMV6hX5L5pm3W9sOTjZt" + "_id": "59iUbnanhI5rTJrAOksLEe" }, { "__type__": "cc.Node", @@ -3656,10 +3656,10 @@ "player": { "__id__": 55 }, - "haloProjectiles": { + "haloProjectileLauncherComponent": { "__id__": 4 }, - "verticalProjectileLauncher": { + "verticalProjectileLauncherComponent": { "__id__": 6 }, "enemyManager": { diff --git a/assets/Scripts/Game/Collision/PlayerProjectileCollisionSystem.ts b/assets/Scripts/Game/Collision/PlayerProjectileCollisionSystem.ts index a34547f..aabe335 100644 --- a/assets/Scripts/Game/Collision/PlayerProjectileCollisionSystem.ts +++ b/assets/Scripts/Game/Collision/PlayerProjectileCollisionSystem.ts @@ -1,10 +1,12 @@ +import { IProjectileCollisionSignaler } from "../Projectile/IProjectileCollisionSignaler"; import { ProjectileCollision } from "../Projectile/ProjectileCollision"; import { Enemy } from "../Unit/Enemy/Enemy"; -import { HaloProjectileLauncher } from "../Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher"; export class PlayerProjectileCollisionSystem { - public constructor(haloLauncher: HaloProjectileLauncher) { - haloLauncher.ProjectileCollisionEvent.on(this.onProjectileCollision, this); + public constructor(collisionSignalers: IProjectileCollisionSignaler[]) { + for (const collisionSignaler of collisionSignalers) { + collisionSignaler.ProjectileCollisionEvent.on(this.onProjectileCollision, this); + } } private onProjectileCollision(projectileCollision: ProjectileCollision): void { diff --git a/assets/Scripts/Game/Data/GameSettings.ts b/assets/Scripts/Game/Data/GameSettings.ts index 146a982..b796919 100644 --- a/assets/Scripts/Game/Data/GameSettings.ts +++ b/assets/Scripts/Game/Data/GameSettings.ts @@ -10,6 +10,7 @@ export class PlayerSettings { public collisionDelay = 0; public weapon: WeaponSettings = new WeaponSettings(); public haloLauncher: HaloLauncherSettings = new HaloLauncherSettings(); + public xyLaunchers: WaveLauncherSettings = new WaveLauncherSettings(); } export class WeaponSettings { @@ -17,8 +18,14 @@ export class WeaponSettings { public damage = 0; } +export class WaveLauncherSettings { + public wavesToShootPerUpgrade = 0; + public launcher = new ProjectileLauncherSettings(); +} + export class HaloLauncherSettings { public projectilesToSpawn = 0; + public cooldownDivisorPerUpgrade = 0; public launcher = new ProjectileLauncherSettings(); } diff --git a/assets/Scripts/Game/GameBootstrapper.ts b/assets/Scripts/Game/GameBootstrapper.ts index da0092c..d462f1c 100644 --- a/assets/Scripts/Game/GameBootstrapper.ts +++ b/assets/Scripts/Game/GameBootstrapper.ts @@ -12,8 +12,9 @@ import { Pauser } from "./Pauser"; import { GameUI } from "./UI/GameUI"; import { EnemyManager } from "./Unit/Enemy/EnemyManager"; import { Player } from "./Unit/Player/Player"; -import { HaloProjectileLauncher } from "./Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher"; +import { HaloProjectileLauncher } from "./Unit/Player/ProjectileLauncher/HaloProjectileLauncher"; import { ProjectileLauncher } from "./Unit/Player/ProjectileLauncher/ProjectileLauncher"; +import { VerticalProjectileLauncher } from "./Unit/Player/ProjectileLauncher/VerticalProjectileLauncher"; import { Upgrader } from "./Upgrades/Upgrader"; const { ccclass, property } = _decorator; @@ -22,8 +23,8 @@ const { ccclass, property } = _decorator; export class GameBootstrapper extends Component { @property(VirtualJoystic) private virtualJoystic: VirtualJoystic; @property(Player) private player: Player; - @property(HaloProjectileLauncher) private haloProjectiles: HaloProjectileLauncher; - @property(ProjectileLauncher) private verticalProjectileLauncher: ProjectileLauncher; + @property(ProjectileLauncher) private haloProjectileLauncherComponent: ProjectileLauncher; + @property(ProjectileLauncher) private verticalProjectileLauncherComponent: ProjectileLauncher; @property(EnemyManager) private enemyManager: EnemyManager; @property(Camera) private camera: Camera; @property(GameUI) private gameUI: GameUI; @@ -31,6 +32,8 @@ export class GameBootstrapper extends Component { @property(JsonAsset) private settingsAsset: JsonAsset; private playerCollisionSystem: PlayerCollisionSystem; + private haloProjectileLauncher: HaloProjectileLauncher; + private verticalProjectileLauncher: VerticalProjectileLauncher; private gamePauser: Pauser = new Pauser(); @@ -52,13 +55,21 @@ export class GameBootstrapper extends Component { this.enemyManager.init(this.player.node); - this.haloProjectiles.init(this.player.node, settings.player.haloLauncher); - this.haloProjectiles.upgrade(); + this.haloProjectileLauncher = new HaloProjectileLauncher( + this.haloProjectileLauncherComponent, + this.player.node, + settings.player.haloLauncher + ); + this.haloProjectileLauncher.upgrade(); - this.verticalProjectileLauncher.init(this.player.node, [new Vec2(-1, 0)]); + this.verticalProjectileLauncher = new VerticalProjectileLauncher( + this.verticalProjectileLauncherComponent, + this.player.node, + settings.player.xyLaunchers + ); this.verticalProjectileLauncher.upgrade(); - new PlayerProjectileCollisionSystem(this.haloProjectiles); + new PlayerProjectileCollisionSystem([this.haloProjectileLauncher, this.verticalProjectileLauncher]); this.gameUI.init(this.player); } @@ -69,7 +80,7 @@ export class GameBootstrapper extends Component { this.player.gameTick(deltaTime); this.playerCollisionSystem.gameTick(deltaTime); this.enemyManager.gameTick(deltaTime); - this.haloProjectiles.gameTick(deltaTime); + this.haloProjectileLauncher.gameTick(deltaTime); this.verticalProjectileLauncher.gameTick(deltaTime); this.camera.node.worldPosition = this.player.node.worldPosition; diff --git a/assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts b/assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts new file mode 100644 index 0000000..4e5f187 --- /dev/null +++ b/assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts @@ -0,0 +1,6 @@ +import { ISignal } from "../../Services/EventSystem/ISignal"; +import { ProjectileCollision } from "./ProjectileCollision"; + +export interface IProjectileCollisionSignaler { + get ProjectileCollisionEvent(): ISignal; +} diff --git a/assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts.meta b/assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts.meta new file mode 100644 index 0000000..f01dc64 --- /dev/null +++ b/assets/Scripts/Game/Projectile/IProjectileCollisionSignaler.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "1932c90e-393a-44d7-9f23-c52221a89286", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo.meta b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo.meta deleted file mode 100644 index 4f2d755..0000000 --- a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo.meta +++ /dev/null @@ -1,12 +0,0 @@ -{ - "ver": "1.1.0", - "importer": "directory", - "imported": true, - "uuid": "b89dc5a7-3450-47e4-bc36-ae5d08f4bc89", - "files": [], - "subMetas": {}, - "userData": { - "compressionType": {}, - "isRemoteBundle": {} - } -} diff --git a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher.ts b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher.ts deleted file mode 100644 index c38b00a..0000000 --- a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { Component, Node, Prefab, Vec2, Vec3, _decorator } from "cc"; -import { ISignal } from "../../../../../Services/EventSystem/ISignal"; -import { Signal } from "../../../../../Services/EventSystem/Signal"; -import { GameTimer } from "../../../../../Services/GameTimer"; -import { ObjectPool } from "../../../../../Services/ObjectPool"; -import { roundToOneDecimal } from "../../../../../Services/Utils/MathUtils"; -import { HaloLauncherSettings } from "../../../../Data/GameSettings"; -import { Projectile } from "../../../../Projectile/Projectile"; -import { ProjectileCollision } from "../../../../Projectile/ProjectileCollision"; - -const { ccclass, property } = _decorator; - -@ccclass("HaloProjectileLauncher") -export class HaloProjectileLauncher extends Component { - @property(Prefab) private projectilePrefab: Prefab; - private fireTimer: GameTimer; - private lifetimeTimer: GameTimer; - private projectilesToSpawn: number; - private defaultCooldown: number; - private speed: number; - private currentLevel = 0; - - private isFiring = false; - - private projectilePool: ObjectPool; - private projectiles: Projectile[] = []; - private directions: Vec2[] = []; - - private playerNode: Node; - - private projectileCollisionEvent: Signal = new Signal(); - - public init(playerNode: Node, settings: HaloLauncherSettings): void { - this.playerNode = playerNode; - this.projectilesToSpawn = settings.projectilesToSpawn; - this.projectilePool = new ObjectPool(this.projectilePrefab, this.node, this.projectilesToSpawn, "Projectile"); - - this.speed = settings.launcher.projectileSpeed; - this.defaultCooldown = settings.launcher.cooldown; - this.lifetimeTimer = new GameTimer(settings.launcher.projectileLifetime); - this.fireTimer = new GameTimer(this.defaultCooldown); - - const angle: number = (2 * Math.PI) / this.projectilesToSpawn; - - for (let i = 0; i < this.projectilesToSpawn; i++) { - const x: number = roundToOneDecimal(Math.sin(angle * i)); - const y: number = roundToOneDecimal(Math.cos(angle * i)); - this.directions.push(new Vec2(x, y).normalize()); - } - } - - public get ProjectileCollisionEvent(): ISignal { - return this.projectileCollisionEvent; - } - - public upgrade(): void { - this.currentLevel++; - this.fireTimer = new GameTimer(this.defaultCooldown - this.currentLevel); - } - - public gameTick(deltaTime: number): void { - if (this.currentLevel == 0) return; - - this.fireTimer.gameTick(deltaTime); - if (this.isFiring) { - this.moveAllProjectiles(deltaTime); - this.tryRemoveAllProjectiles(deltaTime); - } else { - if (this.fireTimer.tryFinishPeriod()) { - this.fireProjectiles(); - } - } - } - - private fireProjectiles(): void { - for (let index = 0; index < this.projectilesToSpawn; index++) { - const projectile: Projectile = this.projectilePool.borrow(); - projectile.tryInit(); - projectile.node.setWorldPosition(this.playerNode.worldPosition); - projectile.node.active = true; - projectile.ContactBeginEvent.on(this.onProjectileCollision, this); - this.projectiles.push(projectile); - } - - this.isFiring = true; - } - - private moveAllProjectiles(deltaTime: number): void { - for (let i = 0; i < this.projectiles.length; i++) { - const newPosition: Vec3 = this.projectiles[i].node.worldPosition; - newPosition.x += this.directions[i].x * deltaTime * this.speed; - newPosition.y += this.directions[i].y * deltaTime * this.speed; - - this.projectiles[i].node.setWorldPosition(newPosition); - } - } - - private tryRemoveAllProjectiles(deltaTime: number): void { - this.lifetimeTimer.gameTick(deltaTime); - if (this.lifetimeTimer.tryFinishPeriod()) { - for (const projectile of this.projectiles) { - projectile.ContactBeginEvent.off(this.onProjectileCollision); - this.projectilePool.return(projectile); - } - - this.projectiles = []; - this.isFiring = false; - } - } - - private onProjectileCollision(projectileCollision: ProjectileCollision): void { - this.projectileCollisionEvent.trigger(projectileCollision); - } -} diff --git a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/HaloProjectileLauncher.ts b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/HaloProjectileLauncher.ts new file mode 100644 index 0000000..0a7eb9d --- /dev/null +++ b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/HaloProjectileLauncher.ts @@ -0,0 +1,44 @@ +import { Vec2, Node } from "cc"; +import { ISignal } from "../../../../Services/EventSystem/ISignal"; +import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils"; +import { HaloLauncherSettings } from "../../../Data/GameSettings"; +import { ProjectileCollision } from "../../../Projectile/ProjectileCollision"; +import { IProjectileCollisionSignaler } from "../../../Projectile/IProjectileCollisionSignaler"; +import { ProjectileLauncher } from "./ProjectileLauncher"; + +export class HaloProjectileLauncher implements IProjectileCollisionSignaler { + private currentUpgrade = 0; + private defaultCooldown = 0; + private cooldownDivisorPerUpgrade = 0; + + public constructor(private launcher: ProjectileLauncher, playerNode: Node, settings: HaloLauncherSettings) { + this.defaultCooldown = settings.launcher.cooldown; + this.cooldownDivisorPerUpgrade = settings.cooldownDivisorPerUpgrade; + + const directions: Vec2[] = []; + const angle: number = (2 * Math.PI) / settings.projectilesToSpawn; + + for (let i = 0; i < settings.projectilesToSpawn; i++) { + const x: number = roundToOneDecimal(Math.sin(angle * i)); + const y: number = roundToOneDecimal(Math.cos(angle * i)); + directions.push(new Vec2(x, y).normalize()); + } + + launcher.init(playerNode, directions, settings.launcher); + } + + public get ProjectileCollisionEvent(): ISignal { + return this.launcher.ProjectileCollisionEvent; + } + + public gameTick(deltaTime: number): void { + if (this.currentUpgrade == 0) return; + + this.launcher.gameTick(deltaTime); + } + + public upgrade(): void { + this.currentUpgrade++; + this.launcher.Cooldown = (this.defaultCooldown / this.cooldownDivisorPerUpgrade) * this.currentUpgrade; + } +} diff --git a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher.ts.meta b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/HaloProjectileLauncher.ts.meta similarity index 100% rename from assets/Scripts/Game/Unit/Player/ProjectileLauncher/Halo/HaloProjectileLauncher.ts.meta rename to assets/Scripts/Game/Unit/Player/ProjectileLauncher/HaloProjectileLauncher.ts.meta diff --git a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/ProjectileLauncher.ts b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/ProjectileLauncher.ts index de2f2a1..a337d52 100644 --- a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/ProjectileLauncher.ts +++ b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/ProjectileLauncher.ts @@ -1,17 +1,27 @@ import { _decorator, Component, Node, Prefab, Vec2, Vec3 } from "cc"; +import { ISignal } from "../../../../Services/EventSystem/ISignal"; +import { Signal } from "../../../../Services/EventSystem/Signal"; import { GameTimer } from "../../../../Services/GameTimer"; import { ObjectPool } from "../../../../Services/ObjectPool"; import { delay } from "../../../../Services/Utils/AsyncUtils"; +import { ProjectileLauncherSettings } from "../../../Data/GameSettings"; +import { IProjectileCollisionSignaler } from "../../../Projectile/IProjectileCollisionSignaler"; import { Projectile } from "../../../Projectile/Projectile"; +import { ProjectileCollision } from "../../../Projectile/ProjectileCollision"; const { ccclass, property } = _decorator; @ccclass("ProjectileLauncher") -export class ProjectileLauncher extends Component { +export class ProjectileLauncher extends Component implements IProjectileCollisionSignaler { @property(Prefab) private projectilePrefab: Prefab; + private projectileCollisionEvent: Signal = new Signal(); + private projectilePool: ObjectPool; private fireTimer: GameTimer; - private projectileLifetime = 5; - private speed = 300; + private projectileLifetime: number; + private speed: number; + private wavesToShoot: number; + private wavesDelayMs: number; + private cooldown: number; private fireDirections: Vec2[]; @@ -20,20 +30,43 @@ export class ProjectileLauncher extends Component { private expireTimes: number[] = []; private currentTime = 0; - private currentUpgrade = 0; - private playerNode: Node; - public init(playerNode: Node, fireDirections: Vec2[]): void { + public get WavesToShoot(): number { + return this.wavesToShoot; + } + + public set WavesToShoot(value: number) { + this.wavesToShoot = value; + } + + public get Cooldown(): number { + return this.cooldown; + } + + public set Cooldown(value: number) { + this.cooldown = value; + this.fireTimer = new GameTimer(this.cooldown); + } + + public get ProjectileCollisionEvent(): ISignal { + return this.projectileCollisionEvent; + } + + public init(playerNode: Node, fireDirections: Vec2[], settings: ProjectileLauncherSettings): void { + this.projectileLifetime = settings.projectileLifetime; + this.speed = settings.projectileSpeed; + this.wavesToShoot = settings.wavesToShoot; + this.wavesDelayMs = settings.wavesDelayMs; + this.cooldown = settings.cooldown; + this.playerNode = playerNode; this.fireDirections = fireDirections; this.projectilePool = new ObjectPool(this.projectilePrefab, this.node, 6, "Projectile"); - this.fireTimer = new GameTimer(2); + this.fireTimer = new GameTimer(this.cooldown); } public gameTick(deltaTime: number): void { - if (this.currentUpgrade == 0) return; - this.currentTime += deltaTime; this.fireTimer.gameTick(deltaTime); if (this.fireTimer.tryFinishPeriod()) { @@ -44,16 +77,13 @@ export class ProjectileLauncher extends Component { this.moveAllProjectiles(deltaTime); } - public upgrade(): void { - this.currentUpgrade++; - } - private async fireProjectiles(): Promise { - for (let i = 0; i < this.currentUpgrade; i++) { - await delay(100); + for (let i = 0; i < this.wavesToShoot; i++) { for (const direction of this.fireDirections) { this.fireProjectile(direction); } + + await delay(this.wavesDelayMs); } } @@ -62,6 +92,7 @@ export class ProjectileLauncher extends Component { projectile.tryInit(); projectile.node.setWorldPosition(this.playerNode.worldPosition); projectile.node.active = true; + projectile.ContactBeginEvent.on(this.onProjectileCollision, this); this.projectiles.push(projectile); this.directions.push(direction); @@ -72,7 +103,10 @@ export class ProjectileLauncher extends Component { for (let i = 0; i < this.projectiles.length; i++) { if (this.currentTime < this.expireTimes[i]) break; // the oldest particles are at the start of the array - this.projectilePool.return(this.projectiles[i]); + const projectile: Projectile = this.projectiles[i]; + projectile.ContactBeginEvent.off(this.onProjectileCollision); + this.projectilePool.return(projectile); + this.projectiles.splice(i, 1); this.directions.splice(i, 1); this.expireTimes.splice(i, 1); @@ -89,4 +123,8 @@ export class ProjectileLauncher extends Component { this.projectiles[i].node.setWorldPosition(newPosition); } } + + private onProjectileCollision(projectlieCollision: ProjectileCollision): void { + this.projectileCollisionEvent.trigger(projectlieCollision); + } } diff --git a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts new file mode 100644 index 0000000..604fe81 --- /dev/null +++ b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts @@ -0,0 +1,31 @@ +import { Node, Vec2 } from "cc"; +import { ISignal } from "../../../../Services/EventSystem/ISignal"; +import { WaveLauncherSettings } from "../../../Data/GameSettings"; +import { IProjectileCollisionSignaler } from "../../../Projectile/IProjectileCollisionSignaler"; +import { ProjectileCollision } from "../../../Projectile/ProjectileCollision"; +import { ProjectileLauncher } from "./ProjectileLauncher"; + +export class VerticalProjectileLauncher implements IProjectileCollisionSignaler { + private currentUpgrade = 0; + private wavesToShootPerUpgrade = 0; + + public constructor(private launcher: ProjectileLauncher, playerNode: Node, settings: WaveLauncherSettings) { + this.wavesToShootPerUpgrade = settings.wavesToShootPerUpgrade; + launcher.init(playerNode, [new Vec2(-1, 0), new Vec2(1, 0)], settings.launcher); + } + + public get ProjectileCollisionEvent(): ISignal { + return this.launcher.ProjectileCollisionEvent; + } + + public gameTick(deltaTime: number): void { + if (this.currentUpgrade == 0) return; + + this.launcher.gameTick(deltaTime); + } + + public upgrade(): void { + this.currentUpgrade++; + this.launcher.WavesToShoot += this.wavesToShootPerUpgrade; + } +} diff --git a/assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts.meta b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts.meta new file mode 100644 index 0000000..bf39347 --- /dev/null +++ b/assets/Scripts/Game/Unit/Player/ProjectileLauncher/VerticalProjectileLauncher.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "1e160c96-efda-4b1a-8e21-8c1b525bc7ef", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Upgrades/UpgradeType.ts b/assets/Scripts/Game/Upgrades/UpgradeType.ts index 3f9305f..5f106e8 100644 --- a/assets/Scripts/Game/Upgrades/UpgradeType.ts +++ b/assets/Scripts/Game/Upgrades/UpgradeType.ts @@ -3,10 +3,12 @@ export enum UpgradeType { WeaponDamage, HorizontalProjectile, VerticalProjectile, + HaloProjectlie, Regeneration } export enum MetaUpgradeType { MaxHp, - OverallDamage + OverallDamage, + ProjectilePiercing } diff --git a/assets/Scripts/Game/Upgrades/Upgrader.ts b/assets/Scripts/Game/Upgrades/Upgrader.ts index fec4cad..cc2b6a2 100644 --- a/assets/Scripts/Game/Upgrades/Upgrader.ts +++ b/assets/Scripts/Game/Upgrades/Upgrader.ts @@ -1,18 +1,24 @@ import { UpgradeSettings } from "../Data/GameSettings"; import { Player } from "../Unit/Player/Player"; +import { HaloProjectileLauncher } from "../Unit/Player/ProjectileLauncher/HaloProjectileLauncher"; +import { VerticalProjectileLauncher } from "../Unit/Player/ProjectileLauncher/VerticalProjectileLauncher"; import { UpgradeType } from "./UpgradeType"; export class Upgrader { - private player: Player; private typeToAction: Map void> = new Map void>(); private typeToLevel: Map = new Map(); private typeToMaxLevel: Map = new Map(); - public constructor(player: Player, settings: UpgradeSettings) { - this.player = player; - + public constructor( + private player: Player, + private verticalProjectileLauncher: VerticalProjectileLauncher, + private haloProjectileLauncher: HaloProjectileLauncher, + settings: UpgradeSettings + ) { this.setTypeMaps(UpgradeType.WeaponLength, this.upgradeWeaponLength.bind(this), settings.maxWeaponLengthUpgrades); this.setTypeMaps(UpgradeType.WeaponDamage, this.upgradeWeaponDamage.bind(this), settings.maxWeaponDamageUpgrades); + this.setTypeMaps(UpgradeType.VerticalProjectile, this.upgradeVerticalProjectileLauncher.bind(this), settings.maxVerticalProjectileUpgrades); + this.setTypeMaps(UpgradeType.HaloProjectlie, this.upgradeHaloProjectileLauncher.bind(this), settings.maxHaloProjectileUpgrades); this.setTypeMaps(UpgradeType.Regeneration, this.upgradeRegeneration.bind(this), settings.maxRegenerationUpgrades); } @@ -50,6 +56,14 @@ export class Upgrader { this.player.Weapon.upgradeWeaponDamage(); } + private upgradeVerticalProjectileLauncher(): void { + this.verticalProjectileLauncher.upgrade(); + } + + private upgradeHaloProjectileLauncher(): void { + this.haloProjectileLauncher.upgrade(); + } + private upgradeRegeneration(): void { this.player.Regeneration.upgrade(); }