mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 11:48:54 +00:00
Start stop spawner delay
This commit is contained in:
parent
07996fdd6a
commit
0886d1d7e4
@ -67,22 +67,23 @@
|
|||||||
"health": 1,
|
"health": 1,
|
||||||
"damage": 1,
|
"damage": 1,
|
||||||
"speed": 50
|
"speed": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "Wave",
|
||||||
|
"moveType": "Launch",
|
||||||
|
"health": 1,
|
||||||
|
"damage": 1,
|
||||||
|
"speed": 100
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"waveEnemySpawner": {
|
"waveEnemySpawners": [
|
||||||
|
{
|
||||||
|
"startDelay": 0,
|
||||||
|
"stopDelay": 100,
|
||||||
"cooldown": 5,
|
"cooldown": 5,
|
||||||
"enemiesPerWave": 30,
|
"enemiesPerWave": 30,
|
||||||
"waveLifetime": 20,
|
"waveLifetime": 20,
|
||||||
"enemyId": "Basic"
|
"enemyId": "Wave"
|
||||||
},
|
|
||||||
"waveEnemySpawners": [
|
|
||||||
{
|
|
||||||
"cooldown": 0,
|
|
||||||
"enemiesPerWave": 0,
|
|
||||||
"waveLifetime": 0,
|
|
||||||
"enemyName": "",
|
|
||||||
"enemyMoveType": "",
|
|
||||||
"enemyType": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,12 @@ export class UpgradeSettings {
|
|||||||
|
|
||||||
export class EnemyManagerSettings {
|
export class EnemyManagerSettings {
|
||||||
public enemies: EnemySettings[] = [new EnemySettings()];
|
public enemies: EnemySettings[] = [new EnemySettings()];
|
||||||
public waveEnemySpawner = new WaveEnemySpawnerSettings();
|
|
||||||
public waveEnemySpawners: WaveEnemySpawnerSettings[] = [new WaveEnemySpawnerSettings()];
|
public waveEnemySpawners: WaveEnemySpawnerSettings[] = [new WaveEnemySpawnerSettings()];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WaveEnemySpawnerSettings {
|
export class WaveEnemySpawnerSettings {
|
||||||
|
public startDelay = 0;
|
||||||
|
public stopDelay = 0;
|
||||||
public cooldown = 0;
|
public cooldown = 0;
|
||||||
public enemiesPerWave = 0;
|
public enemiesPerWave = 0;
|
||||||
public waveLifetime = 0;
|
public waveLifetime = 0;
|
||||||
|
@ -8,6 +8,7 @@ import { FollowTargetEnemyMover } from "./EnemyMover/FollowTargetEnemyMover";
|
|||||||
import { PeriodicFollowTargetEnemyMover } from "./EnemyMover/PeriodicFollowTargetEnemyMover";
|
import { PeriodicFollowTargetEnemyMover } from "./EnemyMover/PeriodicFollowTargetEnemyMover";
|
||||||
import { WaveEnemyMover } from "./EnemyMover/WaveEnemyMover";
|
import { WaveEnemyMover } from "./EnemyMover/WaveEnemyMover";
|
||||||
import { CircularEnemySpawner } from "./EnemySpawner/CircularEnemySpawner";
|
import { CircularEnemySpawner } from "./EnemySpawner/CircularEnemySpawner";
|
||||||
|
import { DelayedEnemySpawner } from "./EnemySpawner/DelayedEnemySpawner";
|
||||||
import { EnemySpawner } from "./EnemySpawner/EnemySpawner";
|
import { EnemySpawner } from "./EnemySpawner/EnemySpawner";
|
||||||
import { IndividualEnemySpawner } from "./EnemySpawner/IndividualEnemySpawner";
|
import { IndividualEnemySpawner } from "./EnemySpawner/IndividualEnemySpawner";
|
||||||
import { WaveEnemySpawner } from "./EnemySpawner/WaveEnemySpawner";
|
import { WaveEnemySpawner } from "./EnemySpawner/WaveEnemySpawner";
|
||||||
@ -21,18 +22,23 @@ export class EnemyManager extends Component {
|
|||||||
|
|
||||||
private movementTypeToMover: Map<EnemyMovementType, EnemyMover> = new Map<EnemyMovementType, EnemyMover>();
|
private movementTypeToMover: Map<EnemyMovementType, EnemyMover> = new Map<EnemyMovementType, EnemyMover>();
|
||||||
|
|
||||||
|
private spawners: DelayedEnemySpawner[] = [];
|
||||||
|
|
||||||
private individualEnemySpawner: IndividualEnemySpawner;
|
private individualEnemySpawner: IndividualEnemySpawner;
|
||||||
private circularEnemySpawner: CircularEnemySpawner;
|
private circularEnemySpawner: CircularEnemySpawner;
|
||||||
private waveEnemySpawner: WaveEnemySpawner;
|
|
||||||
|
|
||||||
public init(targetNode: Node, settings: EnemyManagerSettings): void {
|
public init(targetNode: Node, settings: EnemyManagerSettings): void {
|
||||||
this.enemySpawner.init(targetNode, settings.enemies);
|
this.enemySpawner.init(targetNode, settings.enemies);
|
||||||
this.enemySpawner.EnemyAddedEvent.on(this.onEnemyAdded, this);
|
this.enemySpawner.EnemyAddedEvent.on(this.onEnemyAdded, this);
|
||||||
this.enemySpawner.enemyRemovedEvent.on(this.onRemoveEnemy, this);
|
this.enemySpawner.enemyRemovedEvent.on(this.onRemoveEnemy, this);
|
||||||
|
|
||||||
this.individualEnemySpawner = new IndividualEnemySpawner(this.enemySpawner, "Basic");
|
for (const waveSpawnerSettings of settings.waveEnemySpawners) {
|
||||||
this.circularEnemySpawner = new CircularEnemySpawner(this.enemySpawner, 30, "Basic");
|
const waveSpawner = new WaveEnemySpawner(this.enemySpawner, waveSpawnerSettings);
|
||||||
this.waveEnemySpawner = new WaveEnemySpawner(this.enemySpawner, settings.waveEnemySpawner);
|
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.Follow, new FollowTargetEnemyMover(targetNode));
|
||||||
this.movementTypeToMover.set(EnemyMovementType.Launch, new WaveEnemyMover(targetNode));
|
this.movementTypeToMover.set(EnemyMovementType.Launch, new WaveEnemyMover(targetNode));
|
||||||
@ -44,7 +50,10 @@ export class EnemyManager extends Component {
|
|||||||
public gameTick(deltaTime: number): void {
|
public gameTick(deltaTime: number): void {
|
||||||
this.individualEnemySpawner.gameTick(deltaTime);
|
this.individualEnemySpawner.gameTick(deltaTime);
|
||||||
this.circularEnemySpawner.gameTick(deltaTime);
|
this.circularEnemySpawner.gameTick(deltaTime);
|
||||||
this.waveEnemySpawner.gameTick(deltaTime);
|
|
||||||
|
for (const spawner of this.spawners) {
|
||||||
|
spawner.gameTick(deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
for (const kvp of this.movementTypeToMover) {
|
for (const kvp of this.movementTypeToMover) {
|
||||||
kvp[1].gameTick(deltaTime);
|
kvp[1].gameTick(deltaTime);
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
import { GameTimer } from "../../../../Services/GameTimer";
|
import { GameTimer } from "../../../../Services/GameTimer";
|
||||||
import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils";
|
import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils";
|
||||||
|
|
||||||
|
import { DelayedEnemySpawner } from "./DelayedEnemySpawner";
|
||||||
import { EnemySpawner } from "./EnemySpawner";
|
import { EnemySpawner } from "./EnemySpawner";
|
||||||
|
|
||||||
export class CircularEnemySpawner {
|
export class CircularEnemySpawner extends DelayedEnemySpawner {
|
||||||
private spawnTimer: GameTimer = new GameTimer(10);
|
private spawnTimer: GameTimer = new GameTimer(10);
|
||||||
|
|
||||||
public constructor(private enemySpawner: EnemySpawner, private enemiesToSpawn: number, private enemyId: string) {}
|
public constructor(private enemySpawner: EnemySpawner, private enemiesToSpawn: number, private enemyId: string, startDelay = 0, stopDelay = 100) {
|
||||||
|
super(startDelay, stopDelay);
|
||||||
|
}
|
||||||
|
|
||||||
public gameTick(deltaTime: number): void {
|
public delayedGameTick(deltaTime: number): void {
|
||||||
this.spawnTimer.gameTick(deltaTime);
|
this.spawnTimer.gameTick(deltaTime);
|
||||||
|
|
||||||
if (this.spawnTimer.tryFinishPeriod()) {
|
if (this.spawnTimer.tryFinishPeriod()) {
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
export abstract class DelayedEnemySpawner {
|
||||||
|
private currentTime = 0;
|
||||||
|
public constructor(private startDelay: number, private stopDelay: number) {}
|
||||||
|
|
||||||
|
public gameTick(deltaTime: number): void {
|
||||||
|
this.currentTime += deltaTime;
|
||||||
|
if (this.startDelay <= this.currentTime && this.currentTime <= this.stopDelay) {
|
||||||
|
this.delayedGameTick(deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract delayedGameTick(deltaTime: number): void;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "98291995-7dbb-40da-bce6-4ca9dd7cc45f",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
@ -4,7 +4,6 @@ import { Signal } from "../../../../Services/EventSystem/Signal";
|
|||||||
import { ObjectPool } from "../../../../Services/ObjectPool";
|
import { ObjectPool } from "../../../../Services/ObjectPool";
|
||||||
import { EnemySettings } from "../../../Data/GameSettings";
|
import { EnemySettings } from "../../../Data/GameSettings";
|
||||||
import { Enemy } from "../Enemy";
|
import { Enemy } from "../Enemy";
|
||||||
import { EnemyMovementType } from "../EnemyMovementType";
|
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import { randomRange } from "cc";
|
import { randomRange } from "cc";
|
||||||
import { GameTimer } from "../../../../Services/GameTimer";
|
import { GameTimer } from "../../../../Services/GameTimer";
|
||||||
import { randomPositiveOrNegative } from "../../../../Services/Utils/MathUtils";
|
import { randomPositiveOrNegative } from "../../../../Services/Utils/MathUtils";
|
||||||
|
import { DelayedEnemySpawner } from "./DelayedEnemySpawner";
|
||||||
import { EnemySpawner } from "./EnemySpawner";
|
import { EnemySpawner } from "./EnemySpawner";
|
||||||
|
|
||||||
export class IndividualEnemySpawner {
|
export class IndividualEnemySpawner extends DelayedEnemySpawner {
|
||||||
private spawnTimer: GameTimer = new GameTimer(1);
|
private spawnTimer: GameTimer = new GameTimer(1);
|
||||||
|
|
||||||
public constructor(private enemySpawner: EnemySpawner, private enemyId: string) {}
|
public constructor(private enemySpawner: EnemySpawner, private enemyId: string, startDelay = 0, stopDelay = 100) {
|
||||||
|
super(startDelay, stopDelay);
|
||||||
|
}
|
||||||
|
|
||||||
public gameTick(deltaTime: number): void {
|
public delayedGameTick(deltaTime: number): void {
|
||||||
this.spawnTimer.gameTick(deltaTime);
|
this.spawnTimer.gameTick(deltaTime);
|
||||||
if (this.spawnTimer.tryFinishPeriod()) {
|
if (this.spawnTimer.tryFinishPeriod()) {
|
||||||
const posX: number = randomRange(300, 600) * randomPositiveOrNegative();
|
const posX: number = randomRange(300, 600) * randomPositiveOrNegative();
|
||||||
|
@ -3,9 +3,10 @@ import { GameTimer } from "../../../../Services/GameTimer";
|
|||||||
import { randomPositiveOrNegative } from "../../../../Services/Utils/MathUtils";
|
import { randomPositiveOrNegative } from "../../../../Services/Utils/MathUtils";
|
||||||
import { WaveEnemySpawnerSettings } from "../../../Data/GameSettings";
|
import { WaveEnemySpawnerSettings } from "../../../Data/GameSettings";
|
||||||
import { Enemy } from "../Enemy";
|
import { Enemy } from "../Enemy";
|
||||||
|
import { DelayedEnemySpawner } from "./DelayedEnemySpawner";
|
||||||
import { EnemySpawner } from "./EnemySpawner";
|
import { EnemySpawner } from "./EnemySpawner";
|
||||||
|
|
||||||
export class WaveEnemySpawner {
|
export class WaveEnemySpawner extends DelayedEnemySpawner {
|
||||||
private enemiesPerWave: number;
|
private enemiesPerWave: number;
|
||||||
private waveLifetime: number;
|
private waveLifetime: number;
|
||||||
private enemyId: string;
|
private enemyId: string;
|
||||||
@ -14,13 +15,15 @@ export class WaveEnemySpawner {
|
|||||||
private waves: EnemyWave[] = [];
|
private waves: EnemyWave[] = [];
|
||||||
|
|
||||||
public constructor(private enemySpawner: EnemySpawner, settings: WaveEnemySpawnerSettings) {
|
public constructor(private enemySpawner: EnemySpawner, settings: WaveEnemySpawnerSettings) {
|
||||||
|
super(settings.startDelay, settings.stopDelay);
|
||||||
|
|
||||||
this.spawnTimer = new GameTimer(settings.cooldown);
|
this.spawnTimer = new GameTimer(settings.cooldown);
|
||||||
this.enemiesPerWave = settings.enemiesPerWave;
|
this.enemiesPerWave = settings.enemiesPerWave;
|
||||||
this.waveLifetime = settings.waveLifetime;
|
this.waveLifetime = settings.waveLifetime;
|
||||||
this.enemyId = settings.enemyId;
|
this.enemyId = settings.enemyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public gameTick(deltaTime: number): void {
|
public delayedGameTick(deltaTime: number): void {
|
||||||
this.spawnTimer.gameTick(deltaTime);
|
this.spawnTimer.gameTick(deltaTime);
|
||||||
|
|
||||||
this.tryRemoveExpiredEnemies(deltaTime);
|
this.tryRemoveExpiredEnemies(deltaTime);
|
||||||
|
Loading…
Reference in New Issue
Block a user