Slash-The-Hordes/assets/Scripts/Game/Unit/Enemy/EnemyManager.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-11-16 11:26:20 +00:00
import { Component, Node, _decorator } from "cc";
2022-11-28 11:19:04 +00:00
import { XPSpawner } from "../../XP/XPSpawner";
2022-11-16 11:26:20 +00:00
import { Enemy } from "./Enemy";
import { EnemyMover } from "./EnemyMover";
import { EnemySpawner } from "./EnemySpawner";
const { ccclass, property } = _decorator;
@ccclass("EnemyManager")
export class EnemyManager extends Component {
@property(EnemySpawner) private enemySpawner: EnemySpawner;
@property(XPSpawner) private xpSpawner: XPSpawner;
private enemyMover: EnemyMover;
public init(targetNode: Node): void {
this.enemyMover = new EnemyMover(targetNode);
2022-11-16 13:04:23 +00:00
this.enemySpawner.init(targetNode);
2022-11-16 11:26:20 +00:00
this.enemySpawner.EnemyAddedEvent.on(this.onEnemyAdded, this);
this.xpSpawner.init();
}
public gameTick(deltaTime: number): void {
this.enemySpawner.gameTick(deltaTime);
this.enemyMover.gameTick(deltaTime);
}
private onEnemyAdded(enemy: Enemy): void {
enemy.DeathEvent.on(this.onEnemyDied, this);
this.enemyMover.addEnemy(enemy);
}
private onEnemyDied(enemy: Enemy): void {
enemy.DeathEvent.off(this.onEnemyDied);
this.xpSpawner.spawnXp(enemy.node.worldPosition, 1);
this.enemyMover.removeEnemy(enemy);
}
}