mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 00:26:04 +00:00
Projectiles
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PlayerProjectile')
|
||||
export class PlayerProjectile extends Component {
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6a24e600-866b-4c0d-9a39-59bf222c2e50",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
12
assets/Scripts/Game/Unit/Player/ProjectileLauncher.meta
Normal file
12
assets/Scripts/Game/Unit/Player/ProjectileLauncher.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "f996de47-37ab-489b-820f-fe7a38c09c64",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
@@ -1,9 +1,13 @@
|
||||
import { Component, Prefab, Vec2, Vec3, _decorator, Node } from "cc";
|
||||
import { GameTimer } from "../../../../Services/GameTimer";
|
||||
import { ObjectPool } from "../../../../Services/ObjectPool";
|
||||
import { roundToOneDecimal } from "../../../../Services/Utils/MathUtils";
|
||||
import { HaloLauncherSettings } from "../../../Data/GameSettings";
|
||||
import { PlayerProjectile } from "./PlayerProjectile";
|
||||
import { Component, Node, Prefab, Vec2, Vec3, _decorator } from "cc";
|
||||
import { ISignal } from "../../../../../Services/EventSystem/ISignal";
|
||||
import { Signal } from "../../../../../Services/EventSystem/Signal";
|
||||
import { GameTimer } from "../../../../../Services/GameTimer";
|
||||
import { ObjectPool } from "../../../../../Services/ObjectPool";
|
||||
import { roundToOneDecimal } from "../../../../../Services/Utils/MathUtils";
|
||||
import { HaloLauncherSettings } from "../../../../Data/GameSettings";
|
||||
import { Projectile } from "../../../../Projectile/Projectile";
|
||||
import { ProjectileCollision } from "../../../../Projectile/ProjectileCollision";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("HaloProjectileLauncher")
|
||||
@@ -18,16 +22,18 @@ export class HaloProjectileLauncher extends Component {
|
||||
|
||||
private isFiring = false;
|
||||
|
||||
private projectilePool: ObjectPool<PlayerProjectile>;
|
||||
private projectiles: PlayerProjectile[] = [];
|
||||
private projectilePool: ObjectPool<Projectile>;
|
||||
private projectiles: Projectile[] = [];
|
||||
private directions: Vec2[] = [];
|
||||
|
||||
private playerNode: Node;
|
||||
|
||||
private projectileCollisionEvent: Signal<ProjectileCollision> = new Signal<ProjectileCollision>();
|
||||
|
||||
public init(playerNode: Node, settings: HaloLauncherSettings): void {
|
||||
this.playerNode = playerNode;
|
||||
this.projectilesToSpawn = settings.projectilesToSpawn;
|
||||
this.projectilePool = new ObjectPool<PlayerProjectile>(this.projectilePrefab, this.node, this.projectilesToSpawn, "PlayerProjectile");
|
||||
this.projectilePool = new ObjectPool<Projectile>(this.projectilePrefab, this.node, this.projectilesToSpawn, "PlayerProjectile");
|
||||
|
||||
this.speed = settings.projectileSpeed;
|
||||
this.defaultCooldown = settings.cooldown;
|
||||
@@ -43,6 +49,10 @@ export class HaloProjectileLauncher extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public get ProjectileCollisionEvent(): ISignal<ProjectileCollision> {
|
||||
return this.projectileCollisionEvent;
|
||||
}
|
||||
|
||||
public upgrade(): void {
|
||||
this.currentLevel++;
|
||||
this.fireTimer = new GameTimer(this.defaultCooldown - this.currentLevel);
|
||||
@@ -64,9 +74,11 @@ export class HaloProjectileLauncher extends Component {
|
||||
|
||||
private fireProjectiles(): void {
|
||||
for (let index = 0; index < this.projectilesToSpawn; index++) {
|
||||
const projectile: PlayerProjectile = this.projectilePool.borrow();
|
||||
const projectile: Projectile = this.projectilePool.borrow();
|
||||
projectile.tryInit();
|
||||
projectile.node.setWorldPosition(this.playerNode.worldPosition);
|
||||
projectile.node.active = true;
|
||||
projectile.ContactBeginEvent.on(this.onProjectileCollision, this);
|
||||
this.projectiles.push(projectile);
|
||||
}
|
||||
|
||||
@@ -87,6 +99,7 @@ export class HaloProjectileLauncher extends Component {
|
||||
this.lifetimeTimer.gameTick(deltaTime);
|
||||
if (this.lifetimeTimer.tryFinishPeriod()) {
|
||||
for (const projectile of this.projectiles) {
|
||||
projectile.ContactBeginEvent.off(this.onProjectileCollision);
|
||||
this.projectilePool.return(projectile);
|
||||
}
|
||||
|
||||
@@ -94,4 +107,8 @@ export class HaloProjectileLauncher extends Component {
|
||||
this.isFiring = false;
|
||||
}
|
||||
}
|
||||
|
||||
private onProjectileCollision(projectileCollision: ProjectileCollision): void {
|
||||
this.projectileCollisionEvent.trigger(projectileCollision);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user