mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 03:38:58 +00:00
Projectile Launcher refactor
This commit is contained in:
parent
a327fc4a8d
commit
370e960f95
@ -196,7 +196,7 @@
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"startTime": 0,
|
||||
"startXP": 0,
|
||||
"startXP": 200,
|
||||
"maxHpLevel": 0,
|
||||
"bonusDamageLevel": 0,
|
||||
"projectilePiercingLevel": 0,
|
||||
|
12
assets/Scripts/Game/Unit/Enemy/ProjectileLauncher.cs.meta
Normal file
12
assets/Scripts/Game/Unit/Enemy/ProjectileLauncher.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "d360ea8e-7bcb-4c85-bb9e-4a4bcfb800ae",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import { ProjectileLauncher } from "../../Player/ProjectileLauncher/ProjectileLauncher";
|
||||
|
||||
export class EnemyProjectileLauncher {
|
||||
public constructor(private projectileLauncher: ProjectileLauncher) {}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "057f6d42-fe19-45af-befe-8d665f8a201f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@ -10,21 +10,26 @@ export class HaloProjectileLauncher implements IProjectileCollisionSignaler {
|
||||
private currentUpgrade = 0;
|
||||
private defaultCooldown = 0;
|
||||
private cooldownDivisorPerUpgrade = 0;
|
||||
private directions: Vec2[] = [];
|
||||
|
||||
public constructor(private launcher: ProjectileLauncher, playerNode: Node, settings: HaloLauncherSettings, projectileData: ProjectileData) {
|
||||
public constructor(
|
||||
private launcher: ProjectileLauncher,
|
||||
private playerNode: Node,
|
||||
settings: HaloLauncherSettings,
|
||||
projectileData: ProjectileData
|
||||
) {
|
||||
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());
|
||||
this.directions.push(new Vec2(x, y).normalize());
|
||||
}
|
||||
|
||||
launcher.init(playerNode, directions, settings.launcher, projectileData);
|
||||
launcher.init(settings.launcher, projectileData);
|
||||
}
|
||||
|
||||
public get ProjectileCollisionEvent(): ISignal<ProjectileCollision> {
|
||||
@ -34,7 +39,7 @@ export class HaloProjectileLauncher implements IProjectileCollisionSignaler {
|
||||
public gameTick(deltaTime: number): void {
|
||||
if (this.currentUpgrade == 0) return;
|
||||
|
||||
this.launcher.gameTick(deltaTime);
|
||||
this.launcher.gameTick(deltaTime, this.playerNode.worldPosition, this.directions);
|
||||
}
|
||||
|
||||
public upgrade(): void {
|
||||
|
@ -24,15 +24,11 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
|
||||
private wavesDelayMs: number;
|
||||
private cooldown: number;
|
||||
|
||||
private fireDirections: Vec2[];
|
||||
|
||||
private projectiles: Projectile[] = [];
|
||||
private directions: Vec2[] = [];
|
||||
private expireTimes: number[] = [];
|
||||
private currentTime = 0;
|
||||
|
||||
private playerNode: Node;
|
||||
|
||||
public get WavesToShoot(): number {
|
||||
return this.wavesToShoot;
|
||||
}
|
||||
@ -54,7 +50,7 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
|
||||
return this.projectileCollisionEvent;
|
||||
}
|
||||
|
||||
public init(playerNode: Node, fireDirections: Vec2[], settings: ProjectileLauncherSettings, projectileData: ProjectileData): void {
|
||||
public init(settings: ProjectileLauncherSettings, projectileData: ProjectileData): void {
|
||||
this.projectileData = projectileData;
|
||||
this.projectileLifetime = settings.projectileLifetime;
|
||||
this.speed = settings.projectileSpeed;
|
||||
@ -62,37 +58,35 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
|
||||
this.wavesDelayMs = settings.wavesDelayMs;
|
||||
this.cooldown = settings.cooldown;
|
||||
|
||||
this.playerNode = playerNode;
|
||||
this.fireDirections = fireDirections;
|
||||
this.projectilePool = new ObjectPool<Projectile>(this.projectilePrefab, this.node, 6, "Projectile");
|
||||
this.fireTimer = new GameTimer(this.cooldown);
|
||||
}
|
||||
|
||||
public gameTick(deltaTime: number): void {
|
||||
public gameTick(deltaTime: number, startPosition: Vec3, fireDirections: Vec2[]): void {
|
||||
this.currentTime += deltaTime;
|
||||
this.fireTimer.gameTick(deltaTime);
|
||||
if (this.fireTimer.tryFinishPeriod()) {
|
||||
this.fireProjectiles();
|
||||
this.fireProjectiles(startPosition, fireDirections);
|
||||
}
|
||||
|
||||
this.tryRemoveExpiredProjectiles();
|
||||
this.moveAllProjectiles(deltaTime);
|
||||
}
|
||||
|
||||
private async fireProjectiles(): Promise<void> {
|
||||
private async fireProjectiles(startPosition: Vec3, fireDirections: Vec2[]): Promise<void> {
|
||||
for (let i = 0; i < this.wavesToShoot; i++) {
|
||||
for (const direction of this.fireDirections) {
|
||||
this.fireProjectile(direction);
|
||||
for (const direction of fireDirections) {
|
||||
this.fireProjectile(startPosition, direction);
|
||||
}
|
||||
|
||||
await delay(this.wavesDelayMs);
|
||||
}
|
||||
}
|
||||
|
||||
private fireProjectile(direction: Vec2): void {
|
||||
private fireProjectile(startPosition: Vec3, direction: Vec2): void {
|
||||
const projectile: Projectile = this.projectilePool.borrow();
|
||||
projectile.init(this.projectileData.damage, this.projectileData.pierces, getDegreeAngleFromDirection(direction.x, direction.y));
|
||||
projectile.node.setWorldPosition(this.playerNode.worldPosition);
|
||||
projectile.node.setWorldPosition(startPosition);
|
||||
projectile.node.active = true;
|
||||
projectile.ContactBeginEvent.on(this.onProjectileCollision, this);
|
||||
projectile.PiercesDepletedEvent.on(this.onPiercesDepleted, this);
|
||||
|
@ -11,13 +11,13 @@ export class WaveProjectileLauncher implements IProjectileCollisionSignaler {
|
||||
|
||||
public constructor(
|
||||
private launcher: ProjectileLauncher,
|
||||
playerNode: Node,
|
||||
directions: Vec2[],
|
||||
private playerNode: Node,
|
||||
private directions: Vec2[],
|
||||
settings: WaveLauncherSettings,
|
||||
projectileData: ProjectileData
|
||||
) {
|
||||
this.wavesToShootPerUpgrade = settings.wavesToShootPerUpgrade;
|
||||
launcher.init(playerNode, directions, settings.launcher, projectileData);
|
||||
launcher.init(settings.launcher, projectileData);
|
||||
}
|
||||
|
||||
public get ProjectileCollisionEvent(): ISignal<ProjectileCollision> {
|
||||
@ -27,7 +27,7 @@ export class WaveProjectileLauncher implements IProjectileCollisionSignaler {
|
||||
public gameTick(deltaTime: number): void {
|
||||
if (this.currentUpgrade == 0) return;
|
||||
|
||||
this.launcher.gameTick(deltaTime);
|
||||
this.launcher.gameTick(deltaTime, this.playerNode.worldPosition, this.directions);
|
||||
}
|
||||
|
||||
public upgrade(): void {
|
||||
|
Loading…
Reference in New Issue
Block a user