Item refactoring

This commit is contained in:
Martin 2022-12-23 09:22:22 +01:00
parent 1b5b449d0b
commit 4b2d35a733
34 changed files with 618 additions and 578 deletions

View File

@ -308,23 +308,6 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "cfXyVJoitMGp/0liEUZfNP"
},
{
"__type__": "7a536G2OudFtpTsoF8yLXiW",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 15
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "72AObOIbxCf6LIYsYqoFZF"
},
{
"__type__": "cc.Animation",
"_name": "",
@ -334,7 +317,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 17
"__id__": 15
},
"playOnLoad": true,
"_clips": [
@ -362,10 +345,10 @@
},
"_enabled": true,
"__prefab": {
"__id__": 19
"__id__": 17
},
"tag": 0,
"_group": 1,
"_group": 16,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
@ -386,6 +369,24 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "b5zZIKDzhK3q3Rd8OiKUPa"
},
{
"__type__": "724bauqfhVH0YWsXug16uHL",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 19
},
"itemType": 4,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "9eD6pXLdNKw4xswCPxsN+q"
},
{
"__type__": "cc.PrefabInfo",
"root": {

View File

@ -348,7 +348,7 @@
"__id__": 17
},
"tag": 0,
"_group": 128,
"_group": 16,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
@ -370,7 +370,7 @@
"fileId": "67joCa7ptP34A+uWLWHsEf"
},
{
"__type__": "41f67AOEYRMTLXwNf7CG9iO",
"__type__": "724bauqfhVH0YWsXug16uHL",
"_name": "",
"_objFlags": 0,
"node": {
@ -380,11 +380,12 @@
"__prefab": {
"__id__": 19
},
"itemType": 1,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "08V7VtIFBG1bgEhFLO5GoU"
"fileId": "9eg+N94AJL7qX1hwDoulo4"
},
{
"__type__": "cc.PrefabInfo",

View File

@ -320,7 +320,7 @@
"__id__": 15
},
"tag": 0,
"_group": 256,
"_group": 16,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
@ -366,7 +366,7 @@
"fileId": "3ag4rexLNJW6A/sp6OpwZ8"
},
{
"__type__": "18f8d5p42FOc4uYonNdBzCm",
"__type__": "724bauqfhVH0YWsXug16uHL",
"_name": "",
"_objFlags": 0,
"node": {
@ -376,14 +376,12 @@
"__prefab": {
"__id__": 19
},
"animation": {
"__id__": 16
},
"itemType": 2,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "65lXWGNONBy5ucPc5KmOaR"
"fileId": "c3RTRN6tpK45dDIl3T8NlW"
},
{
"__type__": "cc.PrefabInfo",

View File

@ -306,23 +306,6 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "75WVRoLrtKLrJihCVsxa4D"
},
{
"__type__": "7a536G2OudFtpTsoF8yLXiW",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": false,
"__prefab": {
"__id__": 15
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "72AObOIbxCf6LIYsYqoFZF"
},
{
"__type__": "cc.Animation",
"_name": "",
@ -332,7 +315,7 @@
},
"_enabled": false,
"__prefab": {
"__id__": 17
"__id__": 15
},
"playOnLoad": true,
"_clips": [
@ -351,6 +334,24 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "3ag4rexLNJW6A/sp6OpwZ8"
},
{
"__type__": "724bauqfhVH0YWsXug16uHL",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 17
},
"itemType": 3,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "acBeV6ARtPG5vuHymyG+Tp"
},
{
"__type__": "cc.PrefabInfo",
"root": {

View File

@ -337,26 +337,6 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "75WVRoLrtKLrJihCVsxa4D"
},
{
"__type__": "7a536G2OudFtpTsoF8yLXiW",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 17
},
"animation": {
"__id__": 18
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "72AObOIbxCf6LIYsYqoFZF"
},
{
"__type__": "cc.Animation",
"_name": "",
@ -366,7 +346,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 19
"__id__": 17
},
"playOnLoad": true,
"_clips": [
@ -385,6 +365,27 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "3ag4rexLNJW6A/sp6OpwZ8"
},
{
"__type__": "801bc1fEuVM5pPn2btm9NKZ",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 19
},
"itemType": 0,
"animation": {
"__id__": 16
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "2aiKM2kApHv7jncY6Pmvgt"
},
{
"__type__": "cc.PrefabInfo",
"root": {

View File

@ -26,22 +26,25 @@
},
{
"__id__": 40
},
{
"__id__": 136
}
],
"_active": true,
"_components": [
{
"__id__": 136
},
{
"__id__": 138
},
{
"__id__": 140
},
{
"__id__": 142
},
{
"__id__": 144
}
],
"_prefab": {
"__id__": 142
"__id__": 146
},
"_lpos": {
"__type__": "cc.Vec3",
@ -2902,6 +2905,90 @@
},
"fileId": "c6aL8FlztEHJ6sRFCXQnge"
},
{
"__type__": "cc.Node",
"_name": "Magnet",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 137
}
],
"_prefab": {
"__id__": 139
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.CircleCollider2D",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 136
},
"_enabled": true,
"__prefab": {
"__id__": 138
},
"tag": 0,
"_group": 1,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_radius": 260,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "2cKwIyAIBAm5fq0pDIOT0e"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "aec1+SeS9G0b8TjOixk1ws"
},
{
"__type__": "cc.UITransform",
"_name": "",
@ -2911,7 +2998,7 @@
},
"_enabled": false,
"__prefab": {
"__id__": 137
"__id__": 141
},
"_contentSize": {
"__type__": "cc.Size",
@ -2938,10 +3025,10 @@
},
"_enabled": true,
"__prefab": {
"__id__": 139
"__id__": 143
},
"collider": {
"__id__": 140
"__id__": 144
},
"playerUI": {
"__id__": 37
@ -2973,7 +3060,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 141
"__id__": 145
},
"tag": 0,
"_group": 2,

View File

@ -2317,7 +2317,7 @@
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "96r5a19KlArZj66lP1XbqT"
"fileId": "e4VgJe0ytLH585U+gaoqU4"
},
{
"__type__": "cc.PrefabInfo",

View File

@ -429,34 +429,6 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "2eO+M9deJI1KYyU2Otv4xD"
},
{
"__type__": "f7ac68qK+pC7LXQWJdgAYVs",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 21
},
"animation": {
"__id__": 15
},
"testField": "",
"skillPrefab": {
"__uuid__": "5dccf426-aeb0-4b4e-9e1c-ae9fd74dcf7a",
"__expectedType__": "cc.Prefab"
},
"skillParent": {
"__id__": 9
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "2f6poVi1pJKJ3WzVB7L/Nq"
},
{
"__type__": "cc.Widget",
"_name": "",
@ -467,7 +439,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 23
"__id__": 21
},
"_alignFlags": 45,
"_target": null,
@ -493,6 +465,35 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "67Ws0zREFMYKNYvOHw9C0b"
},
{
"__type__": "f7ac68qK+pC7LXQWJdgAYVs",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 23
},
"animation": {
"__id__": 15
},
"closeButton": null,
"backgroundCloseButton": null,
"skillPrefab": {
"__uuid__": "5dccf426-aeb0-4b4e-9e1c-ae9fd74dcf7a",
"__expectedType__": "cc.Prefab"
},
"skillParent": {
"__id__": 9
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "00cUXISL9FB7Ezx2pI9k4V"
},
{
"__type__": "cc.PrefabInfo",
"root": {
@ -502,31 +503,6 @@
"__id__": 0
},
"fileId": "32U/bJCUBDlaQxxGFNXZTu",
"targetOverrides": [
{
"__id__": 25
}
]
},
{
"__type__": "cc.TargetOverrideInfo",
"source": {
"__id__": 20
},
"sourceInfo": null,
"propertyPath": [
"skills",
"2"
],
"target": null,
"targetInfo": {
"__id__": 26
}
},
{
"__type__": "cc.TargetInfo",
"localID": [
"8fXLBTR/JKgZXZPA29Dci3"
]
"targetOverrides": []
}
]

View File

@ -1112,7 +1112,7 @@
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "dcTNwE4SNLOZujvnWi9lB6"
"fileId": "0cPaLYMJxO4aigeWF8icoV"
},
{
"__type__": "cc.PrefabInfo",

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
import { _decorator, Component, Node, AudioClip } from "cc";
import { AppRoot } from "../../AppRoot/AppRoot";
import { AudioPlayer } from "../../Services/AudioPlayer/AudioPlayer";
import { ItemManager, ItemType } from "../Items/ItemManager";
import { ItemManager } from "../Items/ItemManager";
import { ItemType } from "../Items/ItemType";
import { Enemy } from "../Unit/Enemy/Enemy";
import { EnemyManager } from "../Unit/Enemy/EnemyManager";
import { Player } from "../Unit/Player/Player";

View File

@ -3,10 +3,8 @@ import { ISignal } from "../../Services/EventSystem/ISignal";
import { Signal } from "../../Services/EventSystem/Signal";
import { GameTimer } from "../../Services/GameTimer";
import { GroupType } from "../GroupType";
import { Gold } from "../Items/Gold/Gold";
import { HealthPotion } from "../Items/HealthPotion/HealthPotion";
import { Item } from "../Items/Item";
import { ItemManager } from "../Items/ItemManager";
import { XP } from "../Items/XP/XP";
import { Projectile } from "../Projectile/Projectile";
import { Enemy } from "../Unit/Enemy/Enemy";
import { Player } from "../Unit/Player/Player";
@ -29,9 +27,7 @@ export class PlayerCollisionSystem {
this.groupToResolver.set(GroupType.ENEMY, this.resolveEnemyContact.bind(this));
this.groupToResolver.set(GroupType.ENEMY_PROJECTILE, this.resolveEnemyProjectileContact.bind(this));
this.groupToResolver.set(GroupType.XP, this.resolveXpContact.bind(this));
this.groupToResolver.set(GroupType.GOLD, this.resolveGoldContact.bind(this));
this.groupToResolver.set(GroupType.HEALTH_POTION, this.resolveHealthPotionContact.bind(this));
this.groupToResolver.set(GroupType.ITEM, this.resolveItemContact.bind(this));
}
public gameTick(deltaTime: number): void {
@ -86,16 +82,8 @@ export class PlayerCollisionSystem {
this.player.Health.damage(damage);
}
private resolveXpContact(xpCollider: Collider2D): void {
console.log("Collided with XP");
this.itemManager.pickupXP(xpCollider.node.getComponent(XP));
}
private resolveGoldContact(goldCollider: Collider2D): void {
this.itemManager.pickupGold(goldCollider.node.getComponent(Gold));
}
private resolveHealthPotionContact(healthPotionCollider: Collider2D): void {
this.itemManager.pickupHealthPotion(healthPotionCollider.node.getComponent(HealthPotion));
private resolveItemContact(xpCollider: Collider2D): void {
console.log("Collided with item");
this.itemManager.pickupItem(xpCollider.node.getComponent(Item));
}
}

View File

@ -5,9 +5,8 @@ export enum GroupType {
PLAYER = 1 << 1,
ENEMY = 1 << 2,
WEAPON = 1 << 3,
XP = 1 << 4,
ITEM = 1 << 4,
PLAYER_PROJECTILE = 1 << 5,
ENEMY_PROJECTILE = 1 << 6,
GOLD = 1 << 7,
HEALTH_POTION = 1 << 8
MAGNET_RANGE = 1 << 7
}

View File

@ -1,12 +0,0 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "51704601-c62e-4fff-93ee-73a81cac6e1b",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@ -1,24 +0,0 @@
import { Component, Vec3, _decorator } from "cc";
import { ISignal } from "../../../Services/EventSystem/ISignal";
import { Signal } from "../../../Services/EventSystem/Signal";
const { ccclass, property } = _decorator;
@ccclass("Gold")
export class Gold extends Component {
private pickUpEvent: Signal<Gold> = new Signal<Gold>();
public setup(position: Vec3): void {
this.node.setWorldPosition(position);
this.node.active = true;
}
public get PickupEvent(): ISignal<Gold> {
return this.pickUpEvent;
}
public pickup(): void {
this.pickUpEvent.trigger(this);
this.node.active = false;
}
}

View File

@ -1,26 +0,0 @@
import { Component, Prefab, Vec3, _decorator } from "cc";
import { ObjectPool } from "../../../Services/ObjectPool";
import { Gold } from "./Gold";
const { ccclass, property } = _decorator;
@ccclass("GoldSpawner")
export class GoldSpawner extends Component {
@property(Prefab) public goldPrefab: Prefab;
private goldPool: ObjectPool<Gold>;
public init(): void {
this.goldPool = new ObjectPool<Gold>(this.goldPrefab, this.node, 5, "Gold");
}
public spawn(position: Vec3): void {
const gold: Gold = this.goldPool.borrow();
gold.setup(position);
gold.PickupEvent.on(this.return, this);
}
private return(gold: Gold): void {
gold.PickupEvent.off(this.return);
this.goldPool.return(gold);
}
}

View File

@ -1,12 +0,0 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "5f34fac0-e23f-42da-9c26-d55b9df6ef32",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@ -1,27 +0,0 @@
import { Animation, Component, Vec3, _decorator } from "cc";
import { ISignal } from "../../../Services/EventSystem/ISignal";
import { Signal } from "../../../Services/EventSystem/Signal";
const { ccclass, property } = _decorator;
@ccclass("HealthPotion")
export class HealthPotion extends Component {
@property(Animation) private animation: Animation;
private pickUpEvent: Signal<HealthPotion> = new Signal<HealthPotion>();
public setup(position: Vec3): void {
this.node.setWorldPosition(position);
this.node.active = true;
this.animation.play("DropStart");
}
public get PickupEvent(): ISignal<HealthPotion> {
return this.pickUpEvent;
}
public pickup(): void {
this.pickUpEvent.trigger(this);
this.node.active = false;
}
}

View File

@ -1,27 +0,0 @@
import { Component, Prefab, Vec3, _decorator } from "cc";
import { ObjectPool } from "../../../Services/ObjectPool";
import { HealthPotion } from "./HealthPotion";
const { ccclass, property } = _decorator;
@ccclass("HealthPotionSpawner")
export class HealthPotionSpawner extends Component {
@property(Prefab) public healthPotionPrefab: Prefab;
private healthPotionPool: ObjectPool<HealthPotion>;
public init(): void {
this.healthPotionPool = new ObjectPool<HealthPotion>(this.healthPotionPrefab, this.node, 5, "HealthPotion");
}
public spawn(position: Vec3): void {
const healthPotion: HealthPotion = this.healthPotionPool.borrow();
healthPotion.setup(position);
healthPotion.PickupEvent.on(this.return, this);
}
private return(healthPotion: HealthPotion): void {
healthPotion.PickupEvent.off(this.return);
this.healthPotionPool.return(healthPotion);
}
}

View File

@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1e3b0c7f-c831-4778-8688-d8e2c0f6dc00",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,30 @@
import { _decorator, Component, Node, Vec3, ccenum, Enum } from "cc";
import { ISignal } from "../../Services/EventSystem/ISignal";
import { Signal } from "../../Services/EventSystem/Signal";
import { ItemType } from "./ItemType";
const { ccclass, property } = _decorator;
@ccclass("Item")
export class Item extends Component {
@property({ type: Enum(ItemType) }) private itemType: ItemType;
private pickUpEvent = new Signal<Item>();
public get ItemType(): ItemType {
return <ItemType>this.itemType;
}
public setup(position: Vec3): void {
this.node.setWorldPosition(position);
this.node.active = true;
}
public get PickupEvent(): ISignal<Item> {
return this.pickUpEvent;
}
public pickup(): void {
this.pickUpEvent.trigger(this);
this.node.active = false;
}
}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "18f8de69-e361-4e73-8b98-a2735d0730a6",
"uuid": "724babaa-7e15-47d1-85ac-5ee835eae1cb",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -6,20 +6,20 @@ import { GameResult } from "../Game";
import { Enemy } from "../Unit/Enemy/Enemy";
import { EnemyManager } from "../Unit/Enemy/EnemyManager";
import { Player } from "../Unit/Player/Player";
import { Gold } from "./Gold/Gold";
import { GoldSpawner } from "./Gold/GoldSpawner";
import { HealthPotion } from "./HealthPotion/HealthPotion";
import { HealthPotionSpawner } from "./HealthPotion/HealthPotionSpawner";
import { Item } from "./Item";
import { ItemSpawner } from "./ItemSpawner";
import { ItemType } from "./ItemType";
import { PickupEffectManager } from "./PickupEffect/PickupEffectManager";
import { XP } from "./XP/XP";
import { XPSpawner } from "./XP/XPSpawner";
const { ccclass, property } = _decorator;
@ccclass("ItemManager")
export class ItemManager extends Component {
@property(XPSpawner) private xpSpawner: XPSpawner;
@property(GoldSpawner) private goldSpawner: GoldSpawner;
@property(HealthPotionSpawner) private healthPotionSpawner: HealthPotionSpawner;
@property(ItemSpawner) private xpSpawner: ItemSpawner;
@property(ItemSpawner) private goldSpawner: ItemSpawner;
@property(ItemSpawner) private healthPotionSpawner: ItemSpawner;
@property(ItemSpawner) private magnetSpawner: ItemSpawner;
@property(ItemSpawner) private chestSpawner: ItemSpawner;
@property(PickupEffectManager) private pickupEffectManager: PickupEffectManager;
private player: Player;
@ -28,6 +28,8 @@ export class ItemManager extends Component {
private pickupEvent = new Signal<ItemType>();
private itemTypeToAction = new Map<ItemType, () => void>();
public init(enemyManager: EnemyManager, player: Player, gameResult: GameResult, settings: ItemSettings): void {
this.player = player;
this.gameResult = gameResult;
@ -39,34 +41,40 @@ export class ItemManager extends Component {
this.xpSpawner.init();
this.goldSpawner.init();
this.healthPotionSpawner.init();
this.magnetSpawner.init();
this.chestSpawner.init();
this.pickupEffectManager.init();
this.itemTypeToAction.set(ItemType.XP, this.addXP.bind(this));
this.itemTypeToAction.set(ItemType.Gold, this.addGold.bind(this));
this.itemTypeToAction.set(ItemType.HealthPotion, this.useHealthPotion.bind(this));
}
public get PickupEvent(): ISignal<ItemType> {
return this.pickupEvent;
}
public pickupXP(xp: XP): void {
this.pickupEffectManager.showEffect(xp.node.worldPosition);
this.pickupEvent.trigger(ItemType.XP);
public pickupItem(item: Item): void {
if (!this.itemTypeToAction.has(item.ItemType)) throw new Error("Does not have behaviour set for " + item.ItemType);
this.player.Level.addXp(xp.Value);
xp.pickup();
this.pickupEffectManager.showEffect(item.node.worldPosition);
this.pickupEvent.trigger(item.ItemType);
this.itemTypeToAction.get(item.ItemType)();
item.pickup();
}
public pickupGold(gold: Gold): void {
this.pickupEffectManager.showEffect(gold.node.worldPosition);
this.pickupEvent.trigger(ItemType.Gold);
private addXP(): void {
this.player.Level.addXp(1);
}
gold.pickup();
private addGold(): void {
this.gameResult.goldCoins++;
}
public pickupHealthPotion(healthPotion: HealthPotion): void {
this.pickupEffectManager.showEffect(healthPotion.node.worldPosition);
this.pickupEvent.trigger(ItemType.HealthPotion);
healthPotion.pickup();
private useHealthPotion(): void {
this.player.Health.heal(this.healthPerPotion);
}
@ -86,7 +94,7 @@ export class ItemManager extends Component {
private trySpawnXP(enemy: Enemy): void {
for (let index = 0; index < enemy.XPReward; index++) {
this.xpSpawner.spawnXp(this.getRandomPosition(enemy), 1);
this.xpSpawner.spawn(this.getRandomPosition(enemy));
}
}
@ -121,9 +129,3 @@ export class ItemManager extends Component {
return position;
}
}
export enum ItemType {
XP,
Gold,
HealthPotion
}

View File

@ -0,0 +1,26 @@
import { Component, Prefab, Vec3, _decorator } from "cc";
import { ObjectPool } from "../../Services/ObjectPool";
import { Item } from "./Item";
const { ccclass, property } = _decorator;
@ccclass("ItemSpawner")
export class ItemSpawner extends Component {
@property(Prefab) public itemPrefab: Prefab;
private itemPool: ObjectPool<Item>;
public init(): void {
this.itemPool = new ObjectPool<Item>(this.itemPrefab, this.node, 5, "Item");
}
public spawn(position: Vec3): void {
const item: Item = this.itemPool.borrow();
item.setup(position);
item.PickupEvent.on(this.return, this);
}
private return(gold: Item): void {
gold.PickupEvent.off(this.return);
this.itemPool.return(gold);
}
}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "abf1ff90-c9a3-4d65-8bb9-1ac9ebeb7d51",
"uuid": "74c52c0a-cced-4f28-a00d-a012374264bb",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -0,0 +1,7 @@
export enum ItemType {
XP,
Gold,
HealthPotion,
Magnet,
Chest
}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "41f6700e-1184-4c4c-b5f0-35fec21bd88e",
"uuid": "bd234201-f46c-4031-8e2d-930fa90b2277",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -1,12 +0,0 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "1e85dd0e-3cbc-4870-9a6a-50e0c29cfeb7",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@ -0,0 +1,14 @@
import { Animation, Vec3, _decorator } from "cc";
import { Item } from "./Item";
const { ccclass, property } = _decorator;
@ccclass("XP")
export class XP extends Item {
@property(Animation) private animation: Animation;
public setup(position: Vec3): void {
super.setup(position);
this.animation.play("DropStart");
}
}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7a5361b6-3ae7-45b6-94ec-a05f322d7896",
"uuid": "801bcd5f-12e5-4ce6-93e7-d9bb66f4d299",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -1,33 +0,0 @@
import { Animation, Component, Vec3, _decorator } from "cc";
import { ISignal } from "../../../Services/EventSystem/ISignal";
import { Signal } from "../../../Services/EventSystem/Signal";
const { ccclass, property } = _decorator;
@ccclass("XP")
export class XP extends Component {
@property(Animation) private animation: Animation;
private pickUpEvent: Signal<XP> = new Signal<XP>();
private value = 2;
public setup(position: Vec3, value: number): void {
this.node.setWorldPosition(position);
this.value = value;
this.node.active = true;
this.animation.play("DropStart");
}
public get Value(): number {
return this.value;
}
public get PickupEvent(): ISignal<XP> {
return this.pickUpEvent;
}
public pickup(): void {
this.pickUpEvent.trigger(this);
this.node.active = false;
}
}

View File

@ -1,26 +0,0 @@
import { Component, Prefab, Vec3, _decorator } from "cc";
import { ObjectPool } from "../../../Services/ObjectPool";
import { XP } from "./XP";
const { ccclass, property } = _decorator;
@ccclass("XPSpawner")
export class XPSpawner extends Component {
@property(Prefab) public xpPrefab: Prefab;
private xpPool: ObjectPool<XP>;
public init(): void {
this.xpPool = new ObjectPool<XP>(this.xpPrefab, this.node, 5, "XP");
}
public spawnXp(position: Vec3, value: number): void {
const xp: XP = this.xpPool.borrow();
xp.setup(position, value);
xp.PickupEvent.on(this.returnXp, this);
}
private returnXp(xp: XP): void {
xp.PickupEvent.off(this.returnXp);
this.xpPool.return(xp);
}
}

View File

@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ab9e206b-f11a-417c-814b-07d29c59ed6e",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -15,7 +15,7 @@
},
{
"index": 4,
"name": "XP"
"name": "ITEM"
},
{
"index": 5,
@ -26,12 +26,8 @@
"name": "ENEMY_PROJECTILE"
},
{
"index": 7,
"name": "GOLD"
},
{
"index": 8,
"name": "HEALTH_POTION"
"index": 9,
"name": "MAGNET_RANGE"
}
],
"collisionMatrix": {
@ -43,7 +39,8 @@
"5": 4,
"6": 2,
"7": 2,
"8": 2
"8": 2,
"9": 0
}
},
"general": {