mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-25 19:28:53 +00:00
Periodic follow mover
This commit is contained in:
parent
8d953ec9f6
commit
1c009e9fa4
@ -258,6 +258,13 @@
|
|||||||
"goldReward": 1
|
"goldReward": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"periodicFollowMovers": [
|
||||||
|
{
|
||||||
|
"enemyIdToAffect": "BasicCheetah",
|
||||||
|
"followTime": 3,
|
||||||
|
"waitTime": 5
|
||||||
|
}
|
||||||
|
],
|
||||||
"individualEnemySpawners": [
|
"individualEnemySpawners": [
|
||||||
{
|
{
|
||||||
"common": {
|
"common": {
|
||||||
|
@ -66,11 +66,18 @@ export class MetaUpgradeSettings {
|
|||||||
|
|
||||||
export class EnemyManagerSettings {
|
export class EnemyManagerSettings {
|
||||||
public enemies: EnemySettings[] = [new EnemySettings()];
|
public enemies: EnemySettings[] = [new EnemySettings()];
|
||||||
|
public periodicFollowMovers: PeriodicFollowMoverSettings[] = [new PeriodicFollowMoverSettings()];
|
||||||
public individualEnemySpawners: IndividualEnemySpawnerSettings[] = [new IndividualEnemySpawnerSettings()];
|
public individualEnemySpawners: IndividualEnemySpawnerSettings[] = [new IndividualEnemySpawnerSettings()];
|
||||||
public circularEnemySpawners: CircularEnemySpawnerSettings[] = [new CircularEnemySpawnerSettings()];
|
public circularEnemySpawners: CircularEnemySpawnerSettings[] = [new CircularEnemySpawnerSettings()];
|
||||||
public waveEnemySpawners: WaveEnemySpawnerSettings[] = [new WaveEnemySpawnerSettings()];
|
public waveEnemySpawners: WaveEnemySpawnerSettings[] = [new WaveEnemySpawnerSettings()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class PeriodicFollowMoverSettings {
|
||||||
|
public enemyIdToAffect = "";
|
||||||
|
public followTime = 0;
|
||||||
|
public waitTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
export class GeneralEnemySpawnerSettings {
|
export class GeneralEnemySpawnerSettings {
|
||||||
public enemyId = "";
|
public enemyId = "";
|
||||||
public startDelay = 0;
|
public startDelay = 0;
|
||||||
|
@ -18,6 +18,7 @@ export class Enemy extends Component {
|
|||||||
private deathEvent: Signal<Enemy> = new Signal<Enemy>();
|
private deathEvent: Signal<Enemy> = new Signal<Enemy>();
|
||||||
private lifetimeEndedEvent: Signal<Enemy> = new Signal<Enemy>();
|
private lifetimeEndedEvent: Signal<Enemy> = new Signal<Enemy>();
|
||||||
|
|
||||||
|
private id: string;
|
||||||
private movementType: EnemyMovementType;
|
private movementType: EnemyMovementType;
|
||||||
private health: UnitHealth;
|
private health: UnitHealth;
|
||||||
private damage: number;
|
private damage: number;
|
||||||
@ -31,6 +32,7 @@ export class Enemy extends Component {
|
|||||||
private endOfLifetimeTriggered = false;
|
private endOfLifetimeTriggered = false;
|
||||||
|
|
||||||
public setup(position: Vec3, settings: EnemySettings): void {
|
public setup(position: Vec3, settings: EnemySettings): void {
|
||||||
|
this.id = settings.id;
|
||||||
this.movementType = <EnemyMovementType>settings.moveType;
|
this.movementType = <EnemyMovementType>settings.moveType;
|
||||||
this.health = new UnitHealth(settings.health);
|
this.health = new UnitHealth(settings.health);
|
||||||
this.damage = settings.damage;
|
this.damage = settings.damage;
|
||||||
@ -48,6 +50,10 @@ export class Enemy extends Component {
|
|||||||
this.endOfLifetimeTriggered = false;
|
this.endOfLifetimeTriggered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get Id(): string {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
public get MovementType(): EnemyMovementType {
|
public get MovementType(): EnemyMovementType {
|
||||||
return this.movementType;
|
return this.movementType;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ import { ISignal } from "../../../Services/EventSystem/ISignal";
|
|||||||
import { EnemyManagerSettings } from "../../Data/GameSettings";
|
import { EnemyManagerSettings } from "../../Data/GameSettings";
|
||||||
import { Enemy } from "./Enemy";
|
import { Enemy } from "./Enemy";
|
||||||
import { EnemyMovementType } from "./EnemyMovementType";
|
import { EnemyMovementType } from "./EnemyMovementType";
|
||||||
import { EnemyMover } from "./EnemyMover/EnemyMover";
|
import { IEnemyMover } from "./EnemyMover/EnemyMover";
|
||||||
import { FollowTargetEnemyMover } from "./EnemyMover/FollowTargetEnemyMover";
|
import { FollowTargetEnemyMover } from "./EnemyMover/FollowTargetEnemyMover";
|
||||||
import { PeriodicFollowTargetEnemyMover } from "./EnemyMover/PeriodicFollowTargetEnemyMover";
|
import { PeriodicFollowMovers } from "./EnemyMover/PeriodicFollow/PeriodicFollowMovers";
|
||||||
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 { DelayedEnemySpawner } from "./EnemySpawner/DelayedEnemySpawner";
|
||||||
@ -19,7 +19,7 @@ const { ccclass, property } = _decorator;
|
|||||||
export class EnemyManager extends Component {
|
export class EnemyManager extends Component {
|
||||||
@property(EnemySpawner) private enemySpawner: EnemySpawner;
|
@property(EnemySpawner) private enemySpawner: EnemySpawner;
|
||||||
|
|
||||||
private movementTypeToMover: Map<EnemyMovementType, EnemyMover> = new Map<EnemyMovementType, EnemyMover>();
|
private movementTypeToMover: Map<EnemyMovementType, IEnemyMover> = new Map<EnemyMovementType, IEnemyMover>();
|
||||||
|
|
||||||
private spawners: DelayedEnemySpawner[] = [];
|
private spawners: DelayedEnemySpawner[] = [];
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ export class EnemyManager extends Component {
|
|||||||
|
|
||||||
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 PeriodicFollowMovers(targetNode, settings.periodicFollowMovers));
|
||||||
}
|
}
|
||||||
|
|
||||||
public gameTick(deltaTime: number): void {
|
public gameTick(deltaTime: number): void {
|
||||||
@ -74,7 +74,7 @@ export class EnemyManager extends Component {
|
|||||||
this.getEnemyMover(enemy).removeEnemy(enemy);
|
this.getEnemyMover(enemy).removeEnemy(enemy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getEnemyMover(enemy: Enemy): EnemyMover {
|
private getEnemyMover(enemy: Enemy): IEnemyMover {
|
||||||
if (this.movementTypeToMover.has(enemy.MovementType)) {
|
if (this.movementTypeToMover.has(enemy.MovementType)) {
|
||||||
return this.movementTypeToMover.get(enemy.MovementType);
|
return this.movementTypeToMover.get(enemy.MovementType);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Node } from "cc";
|
import { Node } from "cc";
|
||||||
import { Enemy } from "../Enemy";
|
import { Enemy } from "../Enemy";
|
||||||
|
|
||||||
export abstract class EnemyMover {
|
export abstract class EnemyMover implements IEnemyMover {
|
||||||
protected targetNode: Node;
|
protected targetNode: Node;
|
||||||
protected enemies: Enemy[] = [];
|
protected enemies: Enemy[] = [];
|
||||||
|
|
||||||
@ -21,3 +21,9 @@ export abstract class EnemyMover {
|
|||||||
|
|
||||||
public abstract gameTick(deltaTime: number): void;
|
public abstract gameTick(deltaTime: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IEnemyMover {
|
||||||
|
addEnemy(enemy: Enemy): void;
|
||||||
|
removeEnemy(enemy: Enemy): void;
|
||||||
|
gameTick(deltaTime: number): void;
|
||||||
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.0",
|
||||||
|
"importer": "directory",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "6a81340e-e6eb-4fa0-9d0c-09d988986e6a",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"compressionType": {},
|
||||||
|
"isRemoteBundle": {}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
import { Node } from "cc";
|
||||||
|
import { PeriodicFollowMoverSettings } from "../../../../Data/GameSettings";
|
||||||
|
import { Enemy } from "../../Enemy";
|
||||||
|
import { IEnemyMover } from "../EnemyMover";
|
||||||
|
import { PeriodicFollowTargetEnemyMover } from "./PeriodicFollowTargetEnemyMover";
|
||||||
|
|
||||||
|
export class PeriodicFollowMovers implements IEnemyMover {
|
||||||
|
private enemyIdToMover = new Map<string, PeriodicFollowTargetEnemyMover>();
|
||||||
|
public constructor(targetNode: Node, settings: PeriodicFollowMoverSettings[]) {
|
||||||
|
for (const moverSettings of settings) {
|
||||||
|
this.enemyIdToMover.set(
|
||||||
|
moverSettings.enemyIdToAffect,
|
||||||
|
new PeriodicFollowTargetEnemyMover(targetNode, moverSettings.followTime, moverSettings.waitTime)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public addEnemy(enemy: Enemy): void {
|
||||||
|
this.requireEnemyMover(enemy);
|
||||||
|
this.enemyIdToMover.get(enemy.Id).addEnemy(enemy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public removeEnemy(enemy: Enemy): void {
|
||||||
|
this.requireEnemyMover(enemy);
|
||||||
|
this.enemyIdToMover.get(enemy.Id).removeEnemy(enemy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public gameTick(deltaTime: number): void {
|
||||||
|
for (const enemyMover of this.enemyIdToMover.values()) {
|
||||||
|
enemyMover.gameTick(deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private requireEnemyMover(enemy: Enemy): void {
|
||||||
|
if (!this.enemyIdToMover.has(enemy.Id)) {
|
||||||
|
throw new Error("There is no periodic follow mover for enemy with id " + enemy.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "dadbf2fc-29f0-4348-83e8-c186353581e9",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { Node, Vec3 } from "cc";
|
import { Node, Vec3 } from "cc";
|
||||||
import { Enemy } from "../Enemy";
|
import { Enemy } from "../../Enemy";
|
||||||
import { EnemyMover } from "./EnemyMover";
|
import { EnemyMover } from "../EnemyMover";
|
||||||
|
|
||||||
export class PeriodicFollowTargetEnemyMover extends EnemyMover {
|
export class PeriodicFollowTargetEnemyMover extends EnemyMover {
|
||||||
private enemyToFollowState: Map<Enemy, EnemyFollowState> = new Map<Enemy, EnemyFollowState>();
|
private enemyToFollowState: Map<Enemy, EnemyFollowState> = new Map<Enemy, EnemyFollowState>();
|
Loading…
Reference in New Issue
Block a user