mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
Projectile piercing, meta upgrades
This commit is contained in:
@@ -21,7 +21,7 @@ export class Player extends Component {
|
||||
private level: UnitLevel;
|
||||
private regeneration: PlayerRegeneration;
|
||||
|
||||
public init(input: IInput, settings: PlayerSettings): void {
|
||||
public init(input: IInput, settings: PlayerData): void {
|
||||
this.input = input;
|
||||
this.health = new UnitHealth(settings.defaultHP);
|
||||
this.level = new UnitLevel(settings.requiredXP);
|
||||
@@ -30,6 +30,8 @@ export class Player extends Component {
|
||||
this.weapon.init(settings.weapon);
|
||||
|
||||
this.playerUI.init(this.health);
|
||||
|
||||
console.log("Bonus damage " + settings.bonusDamage);
|
||||
}
|
||||
|
||||
public get Health(): UnitHealth {
|
||||
@@ -67,3 +69,11 @@ export class Player extends Component {
|
||||
this.regeneration.gameTick(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
export class PlayerData extends PlayerSettings {
|
||||
public bonusDamage = 0;
|
||||
public bonusHp = 0;
|
||||
public bonusSpeed = 0;
|
||||
public bonusXP = 0;
|
||||
public bonusGold = 0;
|
||||
}
|
||||
|
@@ -4,14 +4,14 @@ 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";
|
||||
import { ProjectileData, 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) {
|
||||
public constructor(private launcher: ProjectileLauncher, playerNode: Node, settings: HaloLauncherSettings, projectileData: ProjectileData) {
|
||||
this.defaultCooldown = settings.launcher.cooldown;
|
||||
this.cooldownDivisorPerUpgrade = settings.cooldownDivisorPerUpgrade;
|
||||
|
||||
@@ -24,7 +24,7 @@ export class HaloProjectileLauncher implements IProjectileCollisionSignaler {
|
||||
directions.push(new Vec2(x, y).normalize());
|
||||
}
|
||||
|
||||
launcher.init(playerNode, directions, settings.launcher);
|
||||
launcher.init(playerNode, directions, settings.launcher, projectileData);
|
||||
}
|
||||
|
||||
public get ProjectileCollisionEvent(): ISignal<ProjectileCollision> {
|
||||
@@ -39,6 +39,6 @@ export class HaloProjectileLauncher implements IProjectileCollisionSignaler {
|
||||
|
||||
public upgrade(): void {
|
||||
this.currentUpgrade++;
|
||||
this.launcher.Cooldown = (this.defaultCooldown / this.cooldownDivisorPerUpgrade) * this.currentUpgrade;
|
||||
this.launcher.Cooldown = this.defaultCooldown / (this.cooldownDivisorPerUpgrade * this.currentUpgrade);
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ const { ccclass, property } = _decorator;
|
||||
export class ProjectileLauncher extends Component implements IProjectileCollisionSignaler {
|
||||
@property(Prefab) private projectilePrefab: Prefab;
|
||||
private projectileCollisionEvent: Signal<ProjectileCollision> = new Signal<ProjectileCollision>();
|
||||
|
||||
private projectileData: ProjectileData;
|
||||
private projectilePool: ObjectPool<Projectile>;
|
||||
private fireTimer: GameTimer;
|
||||
private projectileLifetime: number;
|
||||
@@ -53,7 +53,8 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
|
||||
return this.projectileCollisionEvent;
|
||||
}
|
||||
|
||||
public init(playerNode: Node, fireDirections: Vec2[], settings: ProjectileLauncherSettings): void {
|
||||
public init(playerNode: Node, fireDirections: Vec2[], settings: ProjectileLauncherSettings, projectileData: ProjectileData): void {
|
||||
this.projectileData = projectileData;
|
||||
this.projectileLifetime = settings.projectileLifetime;
|
||||
this.speed = settings.projectileSpeed;
|
||||
this.wavesToShoot = settings.wavesToShoot;
|
||||
@@ -89,10 +90,11 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
|
||||
|
||||
private fireProjectile(direction: Vec2): void {
|
||||
const projectile: Projectile = this.projectilePool.borrow();
|
||||
projectile.tryInit();
|
||||
projectile.init(this.projectileData.damage, this.projectileData.pierces);
|
||||
projectile.node.setWorldPosition(this.playerNode.worldPosition);
|
||||
projectile.node.active = true;
|
||||
projectile.ContactBeginEvent.on(this.onProjectileCollision, this);
|
||||
projectile.PiercesDepletedEvent.on(this.onPiercesDepleted, this);
|
||||
|
||||
this.projectiles.push(projectile);
|
||||
this.directions.push(direction);
|
||||
@@ -104,16 +106,31 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
|
||||
if (this.currentTime < this.expireTimes[i]) break; // the oldest particles are at the start of the array
|
||||
|
||||
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);
|
||||
this.removeProjectile(projectile, i);
|
||||
i--; // Check the same index
|
||||
}
|
||||
}
|
||||
|
||||
private onPiercesDepleted(projectile: Projectile): void {
|
||||
const index = this.projectiles.indexOf(projectile);
|
||||
if (index === -1) {
|
||||
throw new Error("Projectile not found!");
|
||||
}
|
||||
|
||||
this.removeProjectile(projectile, index);
|
||||
}
|
||||
|
||||
private removeProjectile(projectile: Projectile, index: number): void {
|
||||
projectile.ContactBeginEvent.off(this.onProjectileCollision);
|
||||
projectile.PiercesDepletedEvent.off(this.onPiercesDepleted);
|
||||
|
||||
this.projectilePool.return(projectile);
|
||||
|
||||
this.projectiles.splice(index, 1);
|
||||
this.directions.splice(index, 1);
|
||||
this.expireTimes.splice(index, 1);
|
||||
}
|
||||
|
||||
private moveAllProjectiles(deltaTime: number): void {
|
||||
for (let i = 0; i < this.projectiles.length; i++) {
|
||||
const newPosition: Vec3 = this.projectiles[i].node.worldPosition;
|
||||
@@ -128,3 +145,8 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
|
||||
this.projectileCollisionEvent.trigger(projectlieCollision);
|
||||
}
|
||||
}
|
||||
|
||||
export class ProjectileData {
|
||||
public pierces = 0;
|
||||
public damage = 0;
|
||||
}
|
||||
|
@@ -3,15 +3,21 @@ 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";
|
||||
import { ProjectileData, ProjectileLauncher } from "./ProjectileLauncher";
|
||||
|
||||
export class WaveProjectileLauncher implements IProjectileCollisionSignaler {
|
||||
private currentUpgrade = 0;
|
||||
private wavesToShootPerUpgrade = 0;
|
||||
|
||||
public constructor(private launcher: ProjectileLauncher, playerNode: Node, directions: Vec2[], settings: WaveLauncherSettings) {
|
||||
public constructor(
|
||||
private launcher: ProjectileLauncher,
|
||||
playerNode: Node,
|
||||
directions: Vec2[],
|
||||
settings: WaveLauncherSettings,
|
||||
projectileData: ProjectileData
|
||||
) {
|
||||
this.wavesToShootPerUpgrade = settings.wavesToShootPerUpgrade;
|
||||
launcher.init(playerNode, directions, settings.launcher);
|
||||
launcher.init(playerNode, directions, settings.launcher, projectileData);
|
||||
}
|
||||
|
||||
public get ProjectileCollisionEvent(): ISignal<ProjectileCollision> {
|
||||
|
Reference in New Issue
Block a user