spawner settings

This commit is contained in:
Martin 2022-12-19 13:48:03 +01:00
parent c04a9e74d4
commit 4a58449773
12 changed files with 57 additions and 16 deletions

View File

@ -139,6 +139,7 @@
{ {
"id": "BasicEnemy", "id": "BasicEnemy",
"moveType": "Follow", "moveType": "Follow",
"graphicsType": "Bat",
"health": 2, "health": 2,
"damage": 1, "damage": 1,
"speed": 60, "speed": 60,
@ -149,6 +150,7 @@
{ {
"id": "StandardEnemy", "id": "StandardEnemy",
"moveType": "Follow", "moveType": "Follow",
"graphicsType": "Goblin",
"health": 3, "health": 3,
"damage": 2, "damage": 2,
"speed": 65, "speed": 65,
@ -159,6 +161,7 @@
{ {
"id": "FastEnemy", "id": "FastEnemy",
"moveType": "Follow", "moveType": "Follow",
"graphicsType": "Shark",
"health": 3, "health": 3,
"damage": 2, "damage": 2,
"speed": 75, "speed": 75,
@ -169,6 +172,7 @@
{ {
"id": "CircleEnemy", "id": "CircleEnemy",
"moveType": "Follow", "moveType": "Follow",
"graphicsType": "Bat",
"health": 4, "health": 4,
"damage": 1, "damage": 1,
"speed": 25, "speed": 25,
@ -179,6 +183,7 @@
{ {
"id": "CircleEnemyStandard", "id": "CircleEnemyStandard",
"moveType": "Follow", "moveType": "Follow",
"graphicsType": "Goblin",
"health": 7, "health": 7,
"damage": 2, "damage": 2,
"speed": 35, "speed": 35,
@ -189,6 +194,7 @@
{ {
"id": "WaveEnemy", "id": "WaveEnemy",
"moveType": "Launch", "moveType": "Launch",
"graphicsType": "Shark",
"health": 1, "health": 1,
"damage": 2, "damage": 2,
"speed": 390, "speed": 390,
@ -199,6 +205,7 @@
{ {
"id": "WaveEnemyArmor", "id": "WaveEnemyArmor",
"moveType": "Launch", "moveType": "Launch",
"graphicsType": "Bat",
"health": 5, "health": 5,
"damage": 3, "damage": 3,
"speed": 70, "speed": 70,
@ -209,6 +216,7 @@
{ {
"id": "WaveEnemyArmorFast", "id": "WaveEnemyArmorFast",
"moveType": "Launch", "moveType": "Launch",
"graphicsType": "Goblin",
"health": 5, "health": 5,
"damage": 3, "damage": 3,
"speed": 320, "speed": 320,
@ -219,6 +227,7 @@
{ {
"id": "BasicBoss", "id": "BasicBoss",
"moveType": "Follow", "moveType": "Follow",
"graphicsType": "Shark",
"health": 8, "health": 8,
"damage": 2, "damage": 2,
"speed": 65, "speed": 65,
@ -229,6 +238,7 @@
{ {
"id": "StandardBoss", "id": "StandardBoss",
"moveType": "Follow", "moveType": "Follow",
"graphicsType": "Shark",
"health": 12, "health": 12,
"damage": 3, "damage": 3,
"speed": 75, "speed": 75,
@ -239,6 +249,7 @@
{ {
"id": "BasicCheetah", "id": "BasicCheetah",
"moveType": "PeriodicFollow", "moveType": "PeriodicFollow",
"graphicsType": "Goblin",
"health": 4, "health": 4,
"damage": 1, "damage": 1,
"speed": 120, "speed": 120,

View File

@ -1,7 +1,7 @@
[ [
{ {
"__type__": "cc.Prefab", "__type__": "cc.Prefab",
"_name": "Enemy1", "_name": "Bat",
"_objFlags": 0, "_objFlags": 0,
"_native": "", "_native": "",
"data": { "data": {
@ -13,7 +13,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "Enemy1", "_name": "Bat",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": null, "_parent": null,

View File

@ -8,6 +8,6 @@
], ],
"subMetas": {}, "subMetas": {},
"userData": { "userData": {
"syncNodeName": "Enemy1" "syncNodeName": "Bat"
} }
} }

View File

@ -1,7 +1,7 @@
[ [
{ {
"__type__": "cc.Prefab", "__type__": "cc.Prefab",
"_name": "Enemy2", "_name": "Goblin",
"_objFlags": 0, "_objFlags": 0,
"_native": "", "_native": "",
"data": { "data": {
@ -13,7 +13,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "Enemy2", "_name": "Goblin",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": null, "_parent": null,

View File

@ -8,6 +8,6 @@
], ],
"subMetas": {}, "subMetas": {},
"userData": { "userData": {
"syncNodeName": "Enemy2" "syncNodeName": "Goblin"
} }
} }

View File

@ -1,7 +1,7 @@
[ [
{ {
"__type__": "cc.Prefab", "__type__": "cc.Prefab",
"_name": "Enemy3", "_name": "Shark",
"_objFlags": 0, "_objFlags": 0,
"_native": "", "_native": "",
"data": { "data": {
@ -13,7 +13,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "Enemy3", "_name": "Shark",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": null, "_parent": null,

View File

@ -8,6 +8,6 @@
], ],
"subMetas": {}, "subMetas": {},
"userData": { "userData": {
"syncNodeName": "Enemy3" "syncNodeName": "Shark"
} }
} }

View File

@ -195,7 +195,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": null, "__prefab": null,
"startTime": 500, "startTime": 0,
"startXP": 10, "startXP": 10,
"maxHpLevel": 0, "maxHpLevel": 0,
"bonusDamageLevel": 0, "bonusDamageLevel": 0,
@ -825,6 +825,14 @@
{ {
"__uuid__": "fc9a455d-1b5f-460e-96eb-7c0ebf07d3d0", "__uuid__": "fc9a455d-1b5f-460e-96eb-7c0ebf07d3d0",
"__expectedType__": "cc.Prefab" "__expectedType__": "cc.Prefab"
},
{
"__uuid__": "29d85a71-476d-4a52-bfac-a43c53b616cb",
"__expectedType__": "cc.Prefab"
},
{
"__uuid__": "6135fac4-6678-4e23-b655-b4ff7fb42026",
"__expectedType__": "cc.Prefab"
} }
], ],
"_id": "ebqmDEqu5OGJivYBW47skm" "_id": "ebqmDEqu5OGJivYBW47skm"

View File

@ -99,6 +99,7 @@ export interface ISpawner {
export class EnemySettings { export class EnemySettings {
public id = ""; public id = "";
public moveType = ""; public moveType = "";
public graphicsType = "";
public health = 0; public health = 0;
public damage = 0; public damage = 0;
public speed = 0; public speed = 0;

View File

@ -0,0 +1,5 @@
export enum EnemyGraphicsType {
Bat = "Bat",
Goblin = "Goblin",
Shark = "Shark"
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "13c8fc48-a1ab-4a00-aa10-d286e8521b88",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -4,6 +4,7 @@ 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 { EnemyGraphicsType } from "../EnemyGraphicsType";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ -14,15 +15,18 @@ export class EnemySpawner extends Component {
public enemyAddedEvent: Signal<Enemy> = new Signal<Enemy>(); public enemyAddedEvent: Signal<Enemy> = new Signal<Enemy>();
public enemyRemovedEvent: Signal<Enemy> = new Signal<Enemy>(); public enemyRemovedEvent: Signal<Enemy> = new Signal<Enemy>();
private enemyPool: ObjectPool<Enemy>; private enemyGraphicsTypeToPool = new Map<EnemyGraphicsType, ObjectPool<Enemy>>();
private targetNode: Node; private targetNode: Node;
private idToSettings = new Map<string, EnemySettings>(); private idToSettings = new Map<string, EnemySettings>();
public init(targetNode: Node, enemiesSettings: EnemySettings[]): void { public init(targetNode: Node, enemiesSettings: EnemySettings[]): void {
this.targetNode = targetNode; this.targetNode = targetNode;
this.enemyPool = new ObjectPool(this.enemies[0], this.node, 50, "Enemy");
for (const enemy of this.enemies) {
const enemyPool: ObjectPool<Enemy> = new ObjectPool(enemy, this.node, 50, "Enemy");
this.enemyGraphicsTypeToPool.set(<EnemyGraphicsType>enemy.name, enemyPool);
}
for (const enemySettings of enemiesSettings) { for (const enemySettings of enemiesSettings) {
this.idToSettings.set(enemySettings.id, enemySettings); this.idToSettings.set(enemySettings.id, enemySettings);
@ -42,11 +46,13 @@ export class EnemySpawner extends Component {
throw new Error("Does not have setting for enemy " + id); throw new Error("Does not have setting for enemy " + id);
} }
const enemy = this.enemyPool.borrow(); const enemySettings = this.idToSettings.get(id);
const enemy = this.enemyGraphicsTypeToPool.get(<EnemyGraphicsType>enemySettings.graphicsType).borrow();
const spawnPosition = new Vec3(); const spawnPosition = new Vec3();
spawnPosition.x = this.targetNode.worldPosition.x + positionX; spawnPosition.x = this.targetNode.worldPosition.x + positionX;
spawnPosition.y = this.targetNode.worldPosition.y + positionY; spawnPosition.y = this.targetNode.worldPosition.y + positionY;
enemy.setup(spawnPosition, this.idToSettings.get(id)); enemy.setup(spawnPosition, enemySettings);
enemy.DeathEvent.on(this.returnEnemy, this); enemy.DeathEvent.on(this.returnEnemy, this);
enemy.LifetimeEndedEvent.on(this.returnEnemy, this); enemy.LifetimeEndedEvent.on(this.returnEnemy, this);
@ -60,7 +66,8 @@ export class EnemySpawner extends Component {
enemy.DeathEvent.off(this.returnEnemy); enemy.DeathEvent.off(this.returnEnemy);
enemy.LifetimeEndedEvent.off(this.returnEnemy); enemy.LifetimeEndedEvent.off(this.returnEnemy);
this.enemyPool.return(enemy); console.log(enemy.name);
this.enemyGraphicsTypeToPool.get(<EnemyGraphicsType>enemy.node.name).return(enemy);
this.enemyRemovedEvent.trigger(enemy); this.enemyRemovedEvent.trigger(enemy);
} }