From 4a58449773f3b87e3798ea1405bc2eef35648436 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 19 Dec 2022 13:48:03 +0100 Subject: [PATCH] spawner settings --- assets/Data/GameSettings.json | 11 +++++++++++ .../Game/{Enemy1.prefab => Bat.prefab} | 4 ++-- .../{Enemy1.prefab.meta => Bat.prefab.meta} | 2 +- .../Game/{Enemy2.prefab => Goblin.prefab} | 4 ++-- ...{Enemy2.prefab.meta => Goblin.prefab.meta} | 2 +- .../Game/{Enemy3.prefab => Shark.prefab} | 4 ++-- .../{Enemy3.prefab.meta => Shark.prefab.meta} | 2 +- assets/Scenes/Game.scene | 10 +++++++++- assets/Scripts/Game/Data/GameSettings.ts | 1 + .../Game/Unit/Enemy/EnemyGraphicsType.ts | 5 +++++ .../Game/Unit/Enemy/EnemyGraphicsType.ts.meta | 9 +++++++++ .../Unit/Enemy/EnemySpawner/EnemySpawner.ts | 19 +++++++++++++------ 12 files changed, 57 insertions(+), 16 deletions(-) rename assets/Media/Prefabs/Game/{Enemy1.prefab => Bat.prefab} (98%) rename assets/Media/Prefabs/Game/{Enemy1.prefab.meta => Bat.prefab.meta} (86%) rename assets/Media/Prefabs/Game/{Enemy2.prefab => Goblin.prefab} (98%) rename assets/Media/Prefabs/Game/{Enemy2.prefab.meta => Goblin.prefab.meta} (86%) rename assets/Media/Prefabs/Game/{Enemy3.prefab => Shark.prefab} (98%) rename assets/Media/Prefabs/Game/{Enemy3.prefab.meta => Shark.prefab.meta} (86%) create mode 100644 assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts create mode 100644 assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts.meta diff --git a/assets/Data/GameSettings.json b/assets/Data/GameSettings.json index 6035fd3..6e6a4ac 100644 --- a/assets/Data/GameSettings.json +++ b/assets/Data/GameSettings.json @@ -139,6 +139,7 @@ { "id": "BasicEnemy", "moveType": "Follow", + "graphicsType": "Bat", "health": 2, "damage": 1, "speed": 60, @@ -149,6 +150,7 @@ { "id": "StandardEnemy", "moveType": "Follow", + "graphicsType": "Goblin", "health": 3, "damage": 2, "speed": 65, @@ -159,6 +161,7 @@ { "id": "FastEnemy", "moveType": "Follow", + "graphicsType": "Shark", "health": 3, "damage": 2, "speed": 75, @@ -169,6 +172,7 @@ { "id": "CircleEnemy", "moveType": "Follow", + "graphicsType": "Bat", "health": 4, "damage": 1, "speed": 25, @@ -179,6 +183,7 @@ { "id": "CircleEnemyStandard", "moveType": "Follow", + "graphicsType": "Goblin", "health": 7, "damage": 2, "speed": 35, @@ -189,6 +194,7 @@ { "id": "WaveEnemy", "moveType": "Launch", + "graphicsType": "Shark", "health": 1, "damage": 2, "speed": 390, @@ -199,6 +205,7 @@ { "id": "WaveEnemyArmor", "moveType": "Launch", + "graphicsType": "Bat", "health": 5, "damage": 3, "speed": 70, @@ -209,6 +216,7 @@ { "id": "WaveEnemyArmorFast", "moveType": "Launch", + "graphicsType": "Goblin", "health": 5, "damage": 3, "speed": 320, @@ -219,6 +227,7 @@ { "id": "BasicBoss", "moveType": "Follow", + "graphicsType": "Shark", "health": 8, "damage": 2, "speed": 65, @@ -229,6 +238,7 @@ { "id": "StandardBoss", "moveType": "Follow", + "graphicsType": "Shark", "health": 12, "damage": 3, "speed": 75, @@ -239,6 +249,7 @@ { "id": "BasicCheetah", "moveType": "PeriodicFollow", + "graphicsType": "Goblin", "health": 4, "damage": 1, "speed": 120, diff --git a/assets/Media/Prefabs/Game/Enemy1.prefab b/assets/Media/Prefabs/Game/Bat.prefab similarity index 98% rename from assets/Media/Prefabs/Game/Enemy1.prefab rename to assets/Media/Prefabs/Game/Bat.prefab index 1b205a4..eff9bc5 100644 --- a/assets/Media/Prefabs/Game/Enemy1.prefab +++ b/assets/Media/Prefabs/Game/Bat.prefab @@ -1,7 +1,7 @@ [ { "__type__": "cc.Prefab", - "_name": "Enemy1", + "_name": "Bat", "_objFlags": 0, "_native": "", "data": { @@ -13,7 +13,7 @@ }, { "__type__": "cc.Node", - "_name": "Enemy1", + "_name": "Bat", "_objFlags": 0, "__editorExtras__": {}, "_parent": null, diff --git a/assets/Media/Prefabs/Game/Enemy1.prefab.meta b/assets/Media/Prefabs/Game/Bat.prefab.meta similarity index 86% rename from assets/Media/Prefabs/Game/Enemy1.prefab.meta rename to assets/Media/Prefabs/Game/Bat.prefab.meta index 8230efb..f91f124 100644 --- a/assets/Media/Prefabs/Game/Enemy1.prefab.meta +++ b/assets/Media/Prefabs/Game/Bat.prefab.meta @@ -8,6 +8,6 @@ ], "subMetas": {}, "userData": { - "syncNodeName": "Enemy1" + "syncNodeName": "Bat" } } diff --git a/assets/Media/Prefabs/Game/Enemy2.prefab b/assets/Media/Prefabs/Game/Goblin.prefab similarity index 98% rename from assets/Media/Prefabs/Game/Enemy2.prefab rename to assets/Media/Prefabs/Game/Goblin.prefab index 5709a81..ba88071 100644 --- a/assets/Media/Prefabs/Game/Enemy2.prefab +++ b/assets/Media/Prefabs/Game/Goblin.prefab @@ -1,7 +1,7 @@ [ { "__type__": "cc.Prefab", - "_name": "Enemy2", + "_name": "Goblin", "_objFlags": 0, "_native": "", "data": { @@ -13,7 +13,7 @@ }, { "__type__": "cc.Node", - "_name": "Enemy2", + "_name": "Goblin", "_objFlags": 0, "__editorExtras__": {}, "_parent": null, diff --git a/assets/Media/Prefabs/Game/Enemy2.prefab.meta b/assets/Media/Prefabs/Game/Goblin.prefab.meta similarity index 86% rename from assets/Media/Prefabs/Game/Enemy2.prefab.meta rename to assets/Media/Prefabs/Game/Goblin.prefab.meta index 738414b..6a159d2 100644 --- a/assets/Media/Prefabs/Game/Enemy2.prefab.meta +++ b/assets/Media/Prefabs/Game/Goblin.prefab.meta @@ -8,6 +8,6 @@ ], "subMetas": {}, "userData": { - "syncNodeName": "Enemy2" + "syncNodeName": "Goblin" } } diff --git a/assets/Media/Prefabs/Game/Enemy3.prefab b/assets/Media/Prefabs/Game/Shark.prefab similarity index 98% rename from assets/Media/Prefabs/Game/Enemy3.prefab rename to assets/Media/Prefabs/Game/Shark.prefab index c888b65..ebdecab 100644 --- a/assets/Media/Prefabs/Game/Enemy3.prefab +++ b/assets/Media/Prefabs/Game/Shark.prefab @@ -1,7 +1,7 @@ [ { "__type__": "cc.Prefab", - "_name": "Enemy3", + "_name": "Shark", "_objFlags": 0, "_native": "", "data": { @@ -13,7 +13,7 @@ }, { "__type__": "cc.Node", - "_name": "Enemy3", + "_name": "Shark", "_objFlags": 0, "__editorExtras__": {}, "_parent": null, diff --git a/assets/Media/Prefabs/Game/Enemy3.prefab.meta b/assets/Media/Prefabs/Game/Shark.prefab.meta similarity index 86% rename from assets/Media/Prefabs/Game/Enemy3.prefab.meta rename to assets/Media/Prefabs/Game/Shark.prefab.meta index f1c2eee..6d04f22 100644 --- a/assets/Media/Prefabs/Game/Enemy3.prefab.meta +++ b/assets/Media/Prefabs/Game/Shark.prefab.meta @@ -8,6 +8,6 @@ ], "subMetas": {}, "userData": { - "syncNodeName": "Enemy3" + "syncNodeName": "Shark" } } diff --git a/assets/Scenes/Game.scene b/assets/Scenes/Game.scene index af96334..edf6366 100644 --- a/assets/Scenes/Game.scene +++ b/assets/Scenes/Game.scene @@ -195,7 +195,7 @@ }, "_enabled": true, "__prefab": null, - "startTime": 500, + "startTime": 0, "startXP": 10, "maxHpLevel": 0, "bonusDamageLevel": 0, @@ -825,6 +825,14 @@ { "__uuid__": "fc9a455d-1b5f-460e-96eb-7c0ebf07d3d0", "__expectedType__": "cc.Prefab" + }, + { + "__uuid__": "29d85a71-476d-4a52-bfac-a43c53b616cb", + "__expectedType__": "cc.Prefab" + }, + { + "__uuid__": "6135fac4-6678-4e23-b655-b4ff7fb42026", + "__expectedType__": "cc.Prefab" } ], "_id": "ebqmDEqu5OGJivYBW47skm" diff --git a/assets/Scripts/Game/Data/GameSettings.ts b/assets/Scripts/Game/Data/GameSettings.ts index cfcbf40..e52be9f 100644 --- a/assets/Scripts/Game/Data/GameSettings.ts +++ b/assets/Scripts/Game/Data/GameSettings.ts @@ -99,6 +99,7 @@ export interface ISpawner { export class EnemySettings { public id = ""; public moveType = ""; + public graphicsType = ""; public health = 0; public damage = 0; public speed = 0; diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts b/assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts new file mode 100644 index 0000000..01de696 --- /dev/null +++ b/assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts @@ -0,0 +1,5 @@ +export enum EnemyGraphicsType { + Bat = "Bat", + Goblin = "Goblin", + Shark = "Shark" +} diff --git a/assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts.meta b/assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts.meta new file mode 100644 index 0000000..3c1aee1 --- /dev/null +++ b/assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "13c8fc48-a1ab-4a00-aa10-d286e8521b88", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts index 1ad3018..05e8959 100644 --- a/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts +++ b/assets/Scripts/Game/Unit/Enemy/EnemySpawner/EnemySpawner.ts @@ -4,6 +4,7 @@ import { Signal } from "../../../../Services/EventSystem/Signal"; import { ObjectPool } from "../../../../Services/ObjectPool"; import { EnemySettings } from "../../../Data/GameSettings"; import { Enemy } from "../Enemy"; +import { EnemyGraphicsType } from "../EnemyGraphicsType"; const { ccclass, property } = _decorator; @@ -14,15 +15,18 @@ export class EnemySpawner extends Component { public enemyAddedEvent: Signal = new Signal(); public enemyRemovedEvent: Signal = new Signal(); - private enemyPool: ObjectPool; - + private enemyGraphicsTypeToPool = new Map>(); private targetNode: Node; private idToSettings = new Map(); public init(targetNode: Node, enemiesSettings: EnemySettings[]): void { this.targetNode = targetNode; - this.enemyPool = new ObjectPool(this.enemies[0], this.node, 50, "Enemy"); + + for (const enemy of this.enemies) { + const enemyPool: ObjectPool = new ObjectPool(enemy, this.node, 50, "Enemy"); + this.enemyGraphicsTypeToPool.set(enemy.name, enemyPool); + } for (const enemySettings of enemiesSettings) { 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); } - const enemy = this.enemyPool.borrow(); + const enemySettings = this.idToSettings.get(id); + + const enemy = this.enemyGraphicsTypeToPool.get(enemySettings.graphicsType).borrow(); const spawnPosition = new Vec3(); spawnPosition.x = this.targetNode.worldPosition.x + positionX; 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.LifetimeEndedEvent.on(this.returnEnemy, this); @@ -60,7 +66,8 @@ export class EnemySpawner extends Component { enemy.DeathEvent.off(this.returnEnemy); enemy.LifetimeEndedEvent.off(this.returnEnemy); - this.enemyPool.return(enemy); + console.log(enemy.name); + this.enemyGraphicsTypeToPool.get(enemy.node.name).return(enemy); this.enemyRemovedEvent.trigger(enemy); }