mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-01-04 01:53:32 +00:00
29 lines
856 B
TypeScript
29 lines
856 B
TypeScript
import { Node, Vec3 } from "cc";
|
|
import { Enemy } from "./Enemy";
|
|
|
|
export class EnemyMover {
|
|
private targetNode: Node;
|
|
private enemies: Enemy[] = [];
|
|
public constructor(targetNode: Node) {
|
|
this.targetNode = targetNode;
|
|
}
|
|
public addEnemy(enemy: Enemy): void {
|
|
this.enemies.push(enemy);
|
|
}
|
|
|
|
public removeEnemy(enemy: Enemy): void {
|
|
const index: number = this.enemies.indexOf(enemy);
|
|
if (index != -1) {
|
|
this.enemies.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
public gameTick(deltaTime: number): void {
|
|
this.enemies.forEach((enemy) => {
|
|
let direction: Vec3 = new Vec3();
|
|
direction = Vec3.subtract(direction, this.targetNode.worldPosition, enemy.node.worldPosition);
|
|
enemy.moveBy(direction.multiplyScalar(deltaTime).normalize());
|
|
});
|
|
}
|
|
}
|