mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-10 09:06:03 +00:00
Added health potion
This commit is contained in:
27
assets/Scripts/Game/Items/HealthPotion/HealthPotion.ts
Normal file
27
assets/Scripts/Game/Items/HealthPotion/HealthPotion.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "18f8de69-e361-4e73-8b98-a2735d0730a6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1e3b0c7f-c831-4778-8688-d8e2c0f6dc00",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user