mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 03:38:58 +00:00
Spawner settings
This commit is contained in:
parent
ba2a906fea
commit
6d90260ae8
@ -62,28 +62,51 @@
|
|||||||
"enemyManager": {
|
"enemyManager": {
|
||||||
"enemies": [
|
"enemies": [
|
||||||
{
|
{
|
||||||
"id": "Basic",
|
"id": "BasicEnemy",
|
||||||
"moveType": "Follow",
|
"moveType": "Follow",
|
||||||
"health": 1,
|
"health": 1,
|
||||||
"damage": 1,
|
"damage": 1,
|
||||||
"speed": 50
|
"speed": 50
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "Wave",
|
"id": "WaveEnemy",
|
||||||
"moveType": "Launch",
|
"moveType": "Launch",
|
||||||
"health": 1,
|
"health": 1,
|
||||||
"damage": 1,
|
"damage": 1,
|
||||||
"speed": 100
|
"speed": 100
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"individualEnemySpawners": [
|
||||||
|
{
|
||||||
|
"common": {
|
||||||
|
"enemyId": "BasicEnemy",
|
||||||
|
"startDelay": 0,
|
||||||
|
"stopDelay": -1,
|
||||||
|
"cooldown": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"circularEnemySpawners": [
|
||||||
|
{
|
||||||
|
"common": {
|
||||||
|
"enemyId": "BasicEnemy",
|
||||||
|
"startDelay": 5,
|
||||||
|
"stopDelay": -1,
|
||||||
|
"cooldown": 10
|
||||||
|
},
|
||||||
|
"enemiesToSpawn": 50
|
||||||
|
}
|
||||||
|
],
|
||||||
"waveEnemySpawners": [
|
"waveEnemySpawners": [
|
||||||
{
|
{
|
||||||
"startDelay": 0,
|
"common": {
|
||||||
"stopDelay": 10000,
|
"enemyId": "WaveEnemy",
|
||||||
"cooldown": 5,
|
"startDelay": 5,
|
||||||
"enemiesPerWave": 30,
|
"stopDelay": -1,
|
||||||
"waveLifetime": 20,
|
"cooldown": 5
|
||||||
"enemyId": "Wave"
|
},
|
||||||
|
"enemiesToSpawn": 10,
|
||||||
|
"waveLifetime": 50
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -50,16 +50,31 @@ export class UpgradeSettings {
|
|||||||
|
|
||||||
export class EnemyManagerSettings {
|
export class EnemyManagerSettings {
|
||||||
public enemies: EnemySettings[] = [new EnemySettings()];
|
public enemies: EnemySettings[] = [new EnemySettings()];
|
||||||
|
public individualEnemySpawners: IndividualEnemySpawnerSettings[] = [new IndividualEnemySpawnerSettings()];
|
||||||
|
public circularEnemySpawners: CircularEnemySpawnerSettings[] = [new CircularEnemySpawnerSettings()];
|
||||||
public waveEnemySpawners: WaveEnemySpawnerSettings[] = [new WaveEnemySpawnerSettings()];
|
public waveEnemySpawners: WaveEnemySpawnerSettings[] = [new WaveEnemySpawnerSettings()];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WaveEnemySpawnerSettings {
|
export class GeneralEnemySpawnerSettings {
|
||||||
|
public enemyId = "";
|
||||||
public startDelay = 0;
|
public startDelay = 0;
|
||||||
public stopDelay = 0;
|
public stopDelay = 0;
|
||||||
public cooldown = 0;
|
public cooldown = 0;
|
||||||
public enemiesPerWave = 0;
|
}
|
||||||
|
|
||||||
|
export class WaveEnemySpawnerSettings {
|
||||||
|
public common = new GeneralEnemySpawnerSettings();
|
||||||
|
public enemiesToSpawn = 0;
|
||||||
public waveLifetime = 0;
|
public waveLifetime = 0;
|
||||||
public enemyId = "";
|
}
|
||||||
|
|
||||||
|
export class CircularEnemySpawnerSettings {
|
||||||
|
public common = new GeneralEnemySpawnerSettings();
|
||||||
|
public enemiesToSpawn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IndividualEnemySpawnerSettings {
|
||||||
|
public common = new GeneralEnemySpawnerSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EnemySettings {
|
export class EnemySettings {
|
||||||
|
@ -24,22 +24,26 @@ export class EnemyManager extends Component {
|
|||||||
|
|
||||||
private spawners: DelayedEnemySpawner[] = [];
|
private spawners: DelayedEnemySpawner[] = [];
|
||||||
|
|
||||||
private individualEnemySpawner: IndividualEnemySpawner;
|
|
||||||
private circularEnemySpawner: CircularEnemySpawner;
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
for (const individualSpawnerSettings of settings.individualEnemySpawners) {
|
||||||
|
const individualSpawner = new IndividualEnemySpawner(this.enemySpawner, individualSpawnerSettings);
|
||||||
|
this.spawners.push(individualSpawner);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const circularSpawnerSettings of settings.circularEnemySpawners) {
|
||||||
|
const circularSpawner = new CircularEnemySpawner(this.enemySpawner, circularSpawnerSettings);
|
||||||
|
this.spawners.push(circularSpawner);
|
||||||
|
}
|
||||||
|
|
||||||
for (const waveSpawnerSettings of settings.waveEnemySpawners) {
|
for (const waveSpawnerSettings of settings.waveEnemySpawners) {
|
||||||
const waveSpawner = new WaveEnemySpawner(this.enemySpawner, waveSpawnerSettings);
|
const waveSpawner = new WaveEnemySpawner(this.enemySpawner, waveSpawnerSettings);
|
||||||
this.spawners.push(waveSpawner);
|
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));
|
||||||
this.movementTypeToMover.set(EnemyMovementType.PeriodicFollow, new PeriodicFollowTargetEnemyMover(targetNode, 5, 5));
|
this.movementTypeToMover.set(EnemyMovementType.PeriodicFollow, new PeriodicFollowTargetEnemyMover(targetNode, 5, 5));
|
||||||
@ -48,9 +52,6 @@ export class EnemyManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public gameTick(deltaTime: number): void {
|
public gameTick(deltaTime: number): void {
|
||||||
this.individualEnemySpawner.gameTick(deltaTime);
|
|
||||||
this.circularEnemySpawner.gameTick(deltaTime);
|
|
||||||
|
|
||||||
for (const spawner of this.spawners) {
|
for (const spawner of this.spawners) {
|
||||||
spawner.gameTick(deltaTime);
|
spawner.gameTick(deltaTime);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
import { GameTimer } from "../../../../Services/GameTimer";
|
import { GameTimer } from "../../../../Services/GameTimer";
|
||||||
import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils";
|
import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils";
|
||||||
|
import { CircularEnemySpawnerSettings } from "../../../Data/GameSettings";
|
||||||
|
|
||||||
import { DelayedEnemySpawner } from "./DelayedEnemySpawner";
|
import { DelayedEnemySpawner } from "./DelayedEnemySpawner";
|
||||||
import { EnemySpawner } from "./EnemySpawner";
|
import { EnemySpawner } from "./EnemySpawner";
|
||||||
|
|
||||||
export class CircularEnemySpawner extends DelayedEnemySpawner {
|
export class CircularEnemySpawner extends DelayedEnemySpawner {
|
||||||
private spawnTimer: GameTimer = new GameTimer(10);
|
private spawnTimer: GameTimer;
|
||||||
|
private enemyId: string;
|
||||||
|
private enemiesToSpawn: number;
|
||||||
|
|
||||||
public constructor(private enemySpawner: EnemySpawner, private enemiesToSpawn: number, private enemyId: string, startDelay = 0, stopDelay = 100) {
|
public constructor(private enemySpawner: EnemySpawner, settings: CircularEnemySpawnerSettings) {
|
||||||
super(startDelay, stopDelay);
|
super(settings.common.startDelay, settings.common.stopDelay);
|
||||||
|
|
||||||
|
this.spawnTimer = new GameTimer(settings.common.cooldown);
|
||||||
|
this.enemyId = settings.common.enemyId;
|
||||||
|
this.enemiesToSpawn = settings.enemiesToSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public delayedGameTick(deltaTime: number): void {
|
public delayedGameTick(deltaTime: number): void {
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
export abstract class DelayedEnemySpawner {
|
export abstract class DelayedEnemySpawner {
|
||||||
private currentTime = 0;
|
private currentTime = 0;
|
||||||
public constructor(private startDelay: number, private stopDelay: number) {}
|
public constructor(private startDelay: number, private stopDelay: number) {
|
||||||
|
if (stopDelay === -1) {
|
||||||
|
this.stopDelay = Number.MAX_SAFE_INTEGER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public gameTick(deltaTime: number): void {
|
public gameTick(deltaTime: number): void {
|
||||||
this.currentTime += deltaTime;
|
this.currentTime += deltaTime;
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
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 { IndividualEnemySpawnerSettings } from "../../../Data/GameSettings";
|
||||||
import { DelayedEnemySpawner } from "./DelayedEnemySpawner";
|
import { DelayedEnemySpawner } from "./DelayedEnemySpawner";
|
||||||
import { EnemySpawner } from "./EnemySpawner";
|
import { EnemySpawner } from "./EnemySpawner";
|
||||||
|
|
||||||
export class IndividualEnemySpawner extends DelayedEnemySpawner {
|
export class IndividualEnemySpawner extends DelayedEnemySpawner {
|
||||||
private spawnTimer: GameTimer = new GameTimer(1);
|
private spawnTimer: GameTimer;
|
||||||
|
private enemyId: string;
|
||||||
|
|
||||||
public constructor(private enemySpawner: EnemySpawner, private enemyId: string, startDelay = 0, stopDelay = 100) {
|
public constructor(private enemySpawner: EnemySpawner, settings: IndividualEnemySpawnerSettings) {
|
||||||
super(startDelay, stopDelay);
|
super(settings.common.startDelay, settings.common.stopDelay);
|
||||||
|
|
||||||
|
this.spawnTimer = new GameTimer(settings.common.cooldown);
|
||||||
|
this.enemyId = settings.common.enemyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public delayedGameTick(deltaTime: number): void {
|
public delayedGameTick(deltaTime: number): void {
|
||||||
|
@ -15,12 +15,12 @@ export class WaveEnemySpawner extends DelayedEnemySpawner {
|
|||||||
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);
|
super(settings.common.startDelay, settings.common.stopDelay);
|
||||||
|
|
||||||
this.spawnTimer = new GameTimer(settings.cooldown);
|
this.spawnTimer = new GameTimer(settings.common.cooldown);
|
||||||
this.enemiesPerWave = settings.enemiesPerWave;
|
this.enemiesPerWave = settings.enemiesToSpawn;
|
||||||
this.waveLifetime = settings.waveLifetime;
|
this.waveLifetime = settings.waveLifetime;
|
||||||
this.enemyId = settings.enemyId;
|
this.enemyId = settings.common.enemyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public delayedGameTick(deltaTime: number): void {
|
public delayedGameTick(deltaTime: number): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user