mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-25 11:18:54 +00:00
spawner settings
This commit is contained in:
parent
c04a9e74d4
commit
4a58449773
@ -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,
|
||||
|
@ -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,
|
@ -8,6 +8,6 @@
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "Enemy1"
|
||||
"syncNodeName": "Bat"
|
||||
}
|
||||
}
|
@ -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,
|
@ -8,6 +8,6 @@
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "Enemy2"
|
||||
"syncNodeName": "Goblin"
|
||||
}
|
||||
}
|
@ -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,
|
@ -8,6 +8,6 @@
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "Enemy3"
|
||||
"syncNodeName": "Shark"
|
||||
}
|
||||
}
|
@ -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"
|
||||
|
@ -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;
|
||||
|
5
assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts
Normal file
5
assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export enum EnemyGraphicsType {
|
||||
Bat = "Bat",
|
||||
Goblin = "Goblin",
|
||||
Shark = "Shark"
|
||||
}
|
9
assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts.meta
Normal file
9
assets/Scripts/Game/Unit/Enemy/EnemyGraphicsType.ts.meta
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "13c8fc48-a1ab-4a00-aa10-d286e8521b88",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@ -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<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 idToSettings = new Map<string, EnemySettings>();
|
||||
|
||||
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<Enemy> = new ObjectPool(enemy, this.node, 50, "Enemy");
|
||||
this.enemyGraphicsTypeToPool.set(<EnemyGraphicsType>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(<EnemyGraphicsType>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(<EnemyGraphicsType>enemy.node.name).return(enemy);
|
||||
|
||||
this.enemyRemovedEvent.trigger(enemy);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user