refactory: refactory object pool

feature/ads-smart-display
tiendat3699 2024-06-09 19:12:08 +07:00
parent 1f219422a3
commit 73d3848b3a
41 changed files with 10307 additions and 9388 deletions

15
.vscode/settings.json vendored
View File

@ -5,10 +5,21 @@
"source.sortImports": "explicit" "source.sortImports": "explicit"
}, },
"files.exclude": { "files.exclude": {
"**/*.meta": true "**/.git": true,
"**/.DS_Store": true,
"**/*.meta": true,
"library/": true,
"local/": true,
"temp/": true
}, },
"search.exclude": { "search.exclude": {
"**/*.meta": true "**/node_modules": true,
"**/bower_components": true,
"build/": true,
"temp/": true,
"library/": true,
"**/*.anim": true
}, },
"cSpell.ignoreWords": ["Poolable", "ccclass", "endregion", "lerp"] "cSpell.ignoreWords": ["Poolable", "ccclass", "endregion", "lerp"]
} }

View File

@ -3,6 +3,7 @@
"__type__": "cc.Prefab", "__type__": "cc.Prefab",
"_name": "Star", "_name": "Star",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {},
"_native": "", "_native": "",
"data": { "data": {
"__id__": 1 "__id__": 1
@ -24,10 +25,13 @@
}, },
{ {
"__id__": 4 "__id__": 4
},
{
"__id__": 6
} }
], ],
"_prefab": { "_prefab": {
"__id__": 6 "__id__": 8
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -62,6 +66,7 @@
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {},
"node": { "node": {
"__id__": 1 "__id__": 1
}, },
@ -89,6 +94,7 @@
"__type__": "cc.Sprite", "__type__": "cc.Sprite",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {},
"node": { "node": {
"__id__": 1 "__id__": 1
}, },
@ -129,6 +135,24 @@
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "1fsjnPw61KILwwKyxIzU9M" "fileId": "1fsjnPw61KILwwKyxIzU9M"
}, },
{
"__type__": "311acO2pExPzqOfHKtlFueX",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 7
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "7eB0KBZi5KVZke5B84PCR4"
},
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
"root": { "root": {
@ -138,6 +162,7 @@
"__id__": 0 "__id__": 0
}, },
"fileId": "d3ooykM2hC97QNNNBYXSSK", "fileId": "d3ooykM2hC97QNNNBYXSSK",
"instance": null,
"targetOverrides": null "targetOverrides": null
} }
] ]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,3 @@
import { Director, director, game } from 'cc';
export enum TimerType { export enum TimerType {
countDown, countDown,
CountUp, CountUp,
@ -12,7 +10,6 @@ export default class Timer {
constructor(type: TimerType) { constructor(type: TimerType) {
this._type = type; this._type = type;
director.on(Director.EVENT_AFTER_UPDATE, this.update, this);
} }
public get time() { public get time() {
@ -27,12 +24,12 @@ export default class Timer {
this._timer = value; this._timer = value;
} }
protected update(dt: number): void { public update(dt: number): void {
if (this._paused) return; if (this._paused) return;
if (this._type == TimerType.CountUp) { if (this._type == TimerType.CountUp) {
this._timer += game.deltaTime; this._timer += dt;
} else { } else {
this._timer -= game.deltaTime; this._timer -= dt;
} }
} }

View File

@ -4,7 +4,7 @@ import AudioManager from '../Manager/AudioManager';
import { EventManger } from '../Manager/EventManger'; import { EventManger } from '../Manager/EventManger';
import IPoolable from '../Pool/IPoolable'; import IPoolable from '../Pool/IPoolable';
import ObjectPool from '../Pool/ObjectPool'; import ObjectPool from '../Pool/ObjectPool';
import Utilities from '../Utilities'; import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('BoosterBase') @ccclass('BoosterBase')
@ -20,17 +20,17 @@ export class BoosterBase extends Component implements IPoolable {
@property(CCFloat) @property(CCFloat)
protected time: number = 10; protected time: number = 10;
private _enabled: boolean = true; private active: boolean = true;
protected onLoad(): void { protected onLoad(): void {
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this); this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this);
this._enabled = false; this.active = false;
} }
private onContactBegin(self: Collider2D, other: Collider2D) { private onContactBegin(self: Collider2D, other: Collider2D) {
if (!this._enabled) return; if (!this.active) return;
this.boosterActive(); this.boosterActive();
this._enabled = false; this.active = false;
AudioManager.playSfx(this._collectSound); AudioManager.playSfx(this._collectSound);
EventManger.instance.emit(GameEvent.ObjectRelease, this.node); EventManger.instance.emit(GameEvent.ObjectRelease, this.node);
ObjectPool.release(this.node); ObjectPool.release(this.node);
@ -40,10 +40,10 @@ export class BoosterBase extends Component implements IPoolable {
async onGet() { async onGet() {
this._animation.play(); this._animation.play();
await Utilities.delay(this._animation.defaultClip.duration); await Utils.delay(this._animation.defaultClip.duration);
this._enabled = true; this.active = true;
} }
onRelease() { onRelease() {
this._enabled = false; this.active = false;
} }
} }

View File

@ -1,6 +1,6 @@
import { _decorator, Animation, Vec3 } from 'cc'; import { _decorator, Animation, Vec3 } from 'cc';
import Utilities from '../Utilities';
import Singleton from '../Singleton'; import Singleton from '../Singleton';
import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('CameraController') @ccclass('CameraController')
@ -10,7 +10,7 @@ export class CameraController extends Singleton<CameraController>() {
public async shake(time: number) { public async shake(time: number) {
this._animation.play(); this._animation.play();
await Utilities.delay(time); await Utils.delay(time);
this._animation.stop(); this._animation.stop();
this.node.setPosition(new Vec3(0, 0, 1000)); this.node.setPosition(new Vec3(0, 0, 1000));
} }

View File

@ -19,11 +19,12 @@ import {
import BoosterType from '../Enum/BoosterType'; import BoosterType from '../Enum/BoosterType';
import ScoreType from '../Enum/ScoreType'; import ScoreType from '../Enum/ScoreType';
import GameEvent from '../Events/GameEvent'; import GameEvent from '../Events/GameEvent';
import SpriteFloatingFactory from '../Factory/SpriteFloatingFactory';
import AudioManager from '../Manager/AudioManager'; import AudioManager from '../Manager/AudioManager';
import { EventManger } from '../Manager/EventManger'; import { EventManger } from '../Manager/EventManger';
import { GameManager } from '../Manager/GameManager'; import { GameManager } from '../Manager/GameManager';
import ObjectPool from '../Pool/ObjectPool'; import ObjectPool from '../Pool/ObjectPool';
import Utilities from '../Utilities'; import Utils from '../Utilities';
import { SequenceSound } from './SequenceSound'; import { SequenceSound } from './SequenceSound';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ -56,8 +57,8 @@ export class CumulativeBar extends Component {
@property({ type: Prefab, visible: true }) @property({ type: Prefab, visible: true })
private _starFxObjectPrefab: Prefab; private _starFxObjectPrefab: Prefab;
@property({ type: Prefab, visible: true }) @property({ type: SpriteFloatingFactory, visible: true })
private _scoreObjectPrefab: Prefab; private _floatingStartFactory: SpriteFloatingFactory;
@property({ visible: true }) @property({ visible: true })
private _centerOffset: Vec3 = new Vec3(); private _centerOffset: Vec3 = new Vec3();
@ -80,7 +81,6 @@ export class CumulativeBar extends Component {
@property({ type: Reward, visible: true }) @property({ type: Reward, visible: true })
private _rewards: Reward[] = []; private _rewards: Reward[] = [];
private _starPool: ObjectPool;
private _fxPool: ObjectPool; private _fxPool: ObjectPool;
private _currentValue = 0; private _currentValue = 0;
private _fillValue = 0; private _fillValue = 0;
@ -94,7 +94,6 @@ export class CumulativeBar extends Component {
protected onLoad(): void { protected onLoad(): void {
this._fillBar.fillRange = 0; this._fillBar.fillRange = 0;
this._starPool = new ObjectPool(this._scoreObjectPrefab, 50, true);
this._fxPool = new ObjectPool(this._starFxObjectPrefab, 50, true); this._fxPool = new ObjectPool(this._starFxObjectPrefab, 50, true);
EventManger.instance.on(GameEvent.Score, this.onScore, this); EventManger.instance.on(GameEvent.Score, this.onScore, this);
EventManger.instance.on(GameEvent.BoosterActive, this.onBoosterActive, this); EventManger.instance.on(GameEvent.BoosterActive, this.onBoosterActive, this);
@ -132,9 +131,9 @@ export class CumulativeBar extends Component {
switch (type) { switch (type) {
case ScoreType.DestroyObject: case ScoreType.DestroyObject:
if (!this._active) return; if (!this._active) return;
const star = this._starPool.get(GameManager.instance.topContainer); const star = this._floatingStartFactory.create(GameManager.instance.topContainer);
star.setWorldPosition(position); star.node.setWorldPosition(position);
tween(star) tween(star.node)
.to( .to(
1, 1,
{ worldPosition: this._currentValuePosition }, { worldPosition: this._currentValuePosition },
@ -146,12 +145,12 @@ export class CumulativeBar extends Component {
) )
.call(async () => { .call(async () => {
const fx = this._fxPool.get(ParticleSystem, GameManager.instance.topContainer); const fx = this._fxPool.get(ParticleSystem, GameManager.instance.topContainer);
const pos = star.getWorldPosition(); const pos = star.node.getWorldPosition();
pos.z = 10; pos.z = 10;
fx.node.setWorldPosition(pos); fx.node.setWorldPosition(pos);
this._starPool.release(star); star.node.releaseToPool();
AudioManager.playSfx(this._collectStartSoundFx); AudioManager.playSfx(this._collectStartSoundFx);
await Utilities.waitUntil(() => { await Utils.waitUntil(() => {
return fx.isStopped; return fx.isStopped;
}, 0.1); }, 0.1);
this._fxPool.release(fx); this._fxPool.release(fx);
@ -199,14 +198,14 @@ export class CumulativeBar extends Component {
while (items > 0) { while (items > 0) {
items--; items--;
const obj = this._starPool.get(this._scoreUI); const obj = this._floatingStartFactory.create(GameManager.instance.topContainer);
Vec3.random(offset, 30); Vec3.random(offset, 30);
offset.y = 0; offset.y = 0;
obj.setWorldPosition(this.node.getWorldPosition().add(offset)); obj.node.setWorldPosition(this.node.getWorldPosition().add(offset));
this._soundFx.playSound(0.2); this._soundFx.playSound(0.2);
tween(obj) tween(obj.node)
.to(randomRange(0.3, 0.4), { worldPosition: this._scoreUI.worldPosition }, { easing: 'sineIn' }) .to(randomRange(0.3, 0.4), { worldPosition: this._scoreUI.worldPosition }, { easing: 'sineIn' })
.call(() => this._starPool.release(obj)) .call(() => obj.node.releaseToPool())
.call(() => { .call(() => {
Tween.stopAllByTarget(this._scoreUI); Tween.stopAllByTarget(this._scoreUI);
tween(this._scoreUI) tween(this._scoreUI)
@ -216,12 +215,12 @@ export class CumulativeBar extends Component {
.start(); .start();
}) })
.start(); .start();
await Utilities.delay(time); await Utils.delay(time);
} }
await Utilities.waitUntil(() => this._starPool.countActive == 0, 0.1); await Utils.waitUntil(() => this._floatingStartFactory.countActive == 0, 0.1);
this._comboComplete = true; this._comboComplete = true;
this._soundFx.playSound(); this._soundFx.playSound();
await Utilities.delay(0.8); await Utils.delay(0.8);
this.calcReward(score); this.calcReward(score);
} }
@ -240,7 +239,7 @@ export class CumulativeBar extends Component {
pos.z = 10; pos.z = 10;
fx.node.setWorldPosition(pos); fx.node.setWorldPosition(pos);
AudioManager.playSfx(selectReward.sound); AudioManager.playSfx(selectReward.sound);
await Utilities.waitUntil(() => fx.isStopped, 0.1); await Utils.waitUntil(() => fx.isStopped, 0.1);
selectReward.pool.release(fx); selectReward.pool.release(fx);
} }
} }

View File

@ -16,7 +16,7 @@ import { EventManger } from '../Manager/EventManger';
import { GameManager } from '../Manager/GameManager'; import { GameManager } from '../Manager/GameManager';
import IPoolable from '../Pool/IPoolable'; import IPoolable from '../Pool/IPoolable';
import ObjectPool from '../Pool/ObjectPool'; import ObjectPool from '../Pool/ObjectPool';
import Utilities from '../Utilities'; import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('ScoreObject') @ccclass('ScoreObject')
@ -83,14 +83,14 @@ export class ScoreObject extends Component implements IPoolable {
this.node.setSiblingIndex(this.node.parent.children.length - 1); this.node.setSiblingIndex(this.node.parent.children.length - 1);
GameManager.instance.destroyEnvironmentObject(this._score, this.node.getWorldPosition(), this._bonusTime); GameManager.instance.destroyEnvironmentObject(this._score, this.node.getWorldPosition(), this._bonusTime);
this._animation.play(this._animation.clips[1].name); this._animation.play(this._animation.clips[1].name);
await Utilities.delay(this._animation.clips[1].duration); await Utils.delay(this._animation.clips[1].duration);
EventManger.instance.emit(GameEvent.ObjectRelease, this.node); EventManger.instance.emit(GameEvent.ObjectRelease, this.node);
ObjectPool.release(this.node); ObjectPool.release(this.node);
} }
public async onGet() { public async onGet() {
this._animation.play(this._animation.clips[0].name); this._animation.play(this._animation.clips[0].name);
await Utilities.delay(this._animation.clips[0].duration); await Utils.delay(this._animation.clips[0].duration);
this._enabled = true; this._enabled = true;
} }

View File

@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "bf479cad-c3c8-41db-aae0-d2f03d00d532",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,26 @@
import { _decorator, Component, Node } from 'cc';
import { Ball } from '../GamePlay/Ball';
import ObjectPool from '../Pool/ObjectPool';
import { FactorySingleton } from './FactorySingleton';
const { ccclass, property } = _decorator;
@ccclass('BallFactory')
export default class BallFactory extends FactorySingleton<BallFactory, Ball>() {
private pool: ObjectPool;
public get listActive() {
return this.pool.listActive;
}
public init(): void {
this.pool = new ObjectPool(this.prefab, 5, true, Ball);
}
public create(parent: Node): Ball {
return this.pool.get(Ball, parent);
}
public releaseAll() {
this.pool.releaseAll();
}
}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "bc911ddc-f6b6-45ed-bdf9-ae20f48dfd80", "uuid": "230ab747-30a1-4a14-85c1-628ed8179978",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}

View File

@ -0,0 +1,26 @@
import { _decorator, Component, Node, Prefab } from 'cc';
const { ccclass, property, executionOrder } = _decorator;
@ccclass('Factory')
export abstract class Factory<T> {
@property(Prefab)
protected prefab: Prefab;
public init() {}
public abstract create(parent: Node): T;
}
@ccclass('FactoryComponent')
export abstract class FactoryComponent<T> extends Component {
@property(Prefab)
protected prefab: Prefab;
protected onLoad(): void {
this.init();
}
public init() {}
public abstract create(parent: Node): T;
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2632db1a-1931-482f-a05e-66504ef5ded6",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,26 @@
import { _decorator, Component, Node, Prefab } from 'cc';
const { ccclass, property, executionOrder } = _decorator;
export function FactorySingleton<T, P>() {
@executionOrder(0)
abstract class FactorySingleton extends Component {
private static _instance: T = null;
public static get instance(): T {
return FactorySingleton._instance;
}
@property(Prefab)
protected prefab: Prefab;
protected onLoad(): void {
FactorySingleton._instance = this as any as T;
this.init();
}
public init() {}
public abstract create(parent: Node): P;
}
return FactorySingleton;
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ef7591aa-b8d8-427e-9f5f-7fe363bde4eb",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,19 @@
import { _decorator, Component, Node } from 'cc';
import { FloatingText } from '../Environments/FloatingText';
import ObjectPool from '../Pool/ObjectPool';
import { FactoryComponent } from './Base';
const { ccclass, property } = _decorator;
@ccclass('FloatingTextFactory')
export default class FloatingTextFactory extends FactoryComponent<FloatingText> {
private pool: ObjectPool;
public init(): void {
this.pool = new ObjectPool(this.prefab, 10, true);
}
public create(parent: Node): FloatingText {
return this.pool.get(FloatingText, parent);
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bf80455b-882b-4e67-b3f5-d232b7825cf1",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,22 @@
import { _decorator, Component, Node } from 'cc';
import ObjectPool from '../Pool/ObjectPool';
import FloatingSprite from '../UI/FloatingSprite';
import { FactoryComponent } from './Base';
const { ccclass, property } = _decorator;
@ccclass('SpriteFloatingFactory')
export default class SpriteFloatingFactory extends FactoryComponent<FloatingSprite> {
private pool: ObjectPool;
public get countActive() {
return this.pool?.countActive || 0;
}
public init(): void {
this.pool = new ObjectPool(this.prefab, 10, true);
}
public create(parent: Node): FloatingSprite {
return this.pool.get(FloatingSprite, parent);
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a1de0d36-addf-4ca7-a9d4-0699ee040794",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -1,126 +0,0 @@
import {
Node,
AnimationState,
director,
TweenSystem,
PhysicsSystem2D,
PhysicsSystem,
AnimationManager,
Animation,
} from 'cc';
export class pauseConfig {
exclude?: Node[];
recuExclude?: Node[];
}
export default class GameDirector {
public static pauseData = new (class {
state = false;
physics2D: boolean;
physics3D: boolean;
scheduler: any[];
anim: AnimationState[] = [];
tweenTarget: any[];
})();
private static recuNodeList(node: Node, result: Node[] = []): Node[] {
if (!node) {
return result;
}
result.push(node);
node.children.forEach((v1) => {
result.push(v1);
this.recuNodeList(v1);
});
return result;
}
public static pause(config?: pauseConfig): void {
if (GameDirector.pauseData.state) {
return;
}
GameDirector.pauseData.scheduler = director.getScheduler().pauseAllTargets();
let animSystem = director.getSystem(AnimationManager.ID);
GameDirector.pauseData.anim.splice(0, GameDirector.pauseData.anim.length, ...animSystem['_anims'].array);
GameDirector.pauseData.anim.forEach((v1) => {
v1.pause();
});
GameDirector.pauseData.tweenTarget = TweenSystem.instance.ActionManager.pauseAllRunningActions();
{
if (PhysicsSystem2D && PhysicsSystem2D.instance.enable) {
GameDirector.pauseData.physics2D = PhysicsSystem2D.instance.enable;
PhysicsSystem2D.instance.enable = false;
}
if (PhysicsSystem && PhysicsSystem.instance.enable) {
GameDirector.pauseData.physics3D = PhysicsSystem.instance.enable;
PhysicsSystem.instance.enable = false;
}
}
if (config) {
let exclude: Node[] = [];
exclude.push(...config.exclude);
config.recuExclude?.forEach((v1) => {
exclude.push(...GameDirector.recuNodeList(v1));
});
exclude.forEach((v1) => {
GameDirector.resumeNode(v1);
});
}
GameDirector.pauseData.state = true;
}
public static resume(): void {
director.getScheduler().resumeTargets(GameDirector.pauseData.scheduler);
GameDirector.pauseData.anim.forEach((v1) => {
if (v1.isPlaying && v1.isPaused) {
v1.play();
}
});
TweenSystem.instance.ActionManager.resumeTargets(GameDirector.pauseData.tweenTarget);
if (GameDirector.pauseData.physics2D) {
PhysicsSystem2D.instance.enable = GameDirector.pauseData.physics2D;
}
if (GameDirector.pauseData.physics3D) {
PhysicsSystem.instance.enable = GameDirector.pauseData.physics3D;
}
GameDirector.pauseData.state = false;
}
public static pauseNode(node: Node): void;
public static pauseNode(node: Node[]): void;
public static pauseNode(args: Node | Node[]): void {
let node: Node[];
if (Array.isArray(args)) {
node = args;
} else {
node = [args];
}
node.forEach((v1) => {
director.getScheduler().pauseTarget(v1);
v1.getComponent(Animation)?.pause();
TweenSystem.instance.ActionManager.pauseTarget(v1);
});
}
public static resumeNode(node: Node): void;
public static resumeNode(node: Node[]): void;
public static resumeNode(args: Node | Node[]): void {
let node: Node[];
if (Array.isArray(args)) {
node = args;
} else {
node = [args];
}
node.forEach((v1) => {
director.getScheduler().resumeTarget(v1);
v1.getComponent(Animation)?.resume();
TweenSystem.instance.ActionManager.resumeTarget(v1);
});
}
}

View File

@ -16,7 +16,7 @@ import { CameraController } from '../Environments/CameraController';
import GameEvent from '../Events/GameEvent'; import GameEvent from '../Events/GameEvent';
import AudioManager from '../Manager/AudioManager'; import AudioManager from '../Manager/AudioManager';
import { EventManger } from '../Manager/EventManger'; import { EventManger } from '../Manager/EventManger';
import Utilities from '../Utilities'; import Utils from '../Utilities';
import { Ball } from './Ball'; import { Ball } from './Ball';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ -49,13 +49,13 @@ export class Cannon extends Component {
if (ball) { if (ball) {
ball.clearRigiState(false); ball.clearRigiState(false);
tween(ball.node).to(0.1, { worldPosition: this.node.worldPosition }).start(); tween(ball.node).to(0.1, { worldPosition: this.node.worldPosition }).start();
await Utilities.delay(TimeConfig.DelayCannonFire); await Utils.delay(TimeConfig.DelayCannonFire);
CameraController.instance.shake(0.2); CameraController.instance.shake(0.2);
this._animation.play(); this._animation.play();
ball.clearRigiState(true); ball.clearRigiState(true);
ball.throwBall(new Vec2(0, this._force)); ball.throwBall(new Vec2(0, this._force));
AudioManager.playSfx(this._soundFx); AudioManager.playSfx(this._soundFx);
await Utilities.delay(TimeConfig.DelayCannonDone); await Utils.delay(TimeConfig.DelayCannonDone);
tween(this._collider.node).to(0.5, { scale: Vec3.ZERO }, { easing: 'backIn' }).start(); tween(this._collider.node).to(0.5, { scale: Vec3.ZERO }, { easing: 'backIn' }).start();
EventHandler.emitEvents(this.onDone, ball); EventHandler.emitEvents(this.onDone, ball);
} }

View File

@ -1,19 +1,9 @@
import { import { _decorator, Animation, CCInteger, Collider2D, Component, Contact2DType, ParticleSystem, Prefab } from 'cc';
_decorator,
Animation,
AudioClip,
CCInteger,
Collider2D,
Component,
Contact2DType,
ParticleSystem,
Prefab,
} from 'cc';
import TimeConfig from '../Enum/TimeConfig'; import TimeConfig from '../Enum/TimeConfig';
import { CameraController } from '../Environments/CameraController'; import { CameraController } from '../Environments/CameraController';
import { GameManager } from '../Manager/GameManager'; import { GameManager } from '../Manager/GameManager';
import ObjectPool from '../Pool/ObjectPool'; import ObjectPool from '../Pool/ObjectPool';
import Utilities from '../Utilities'; import Utils from '../Utilities';
import { Ball } from './Ball'; import { Ball } from './Ball';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ -48,14 +38,14 @@ export class Goal extends Component {
ObjectPool.release(ball.node); ObjectPool.release(ball.node);
CameraController.instance.shake(0.5); CameraController.instance.shake(0.5);
this.playAnimationGoal(); this.playAnimationGoal();
await Utilities.waitUntil(() => fx.isStopped); await Utils.waitUntil(() => fx.isStopped);
this._goalFxPool.release(fx); this._goalFxPool.release(fx);
} }
} }
public async playAnimationGoal() { public async playAnimationGoal() {
this._animation.play(this._animation.clips[1].name); this._animation.play(this._animation.clips[1].name);
await Utilities.delay(TimeConfig.DelayGoal); await Utils.delay(TimeConfig.DelayGoal);
this._animation.play(); this._animation.play();
} }
} }

View File

@ -10,17 +10,15 @@ import {
PolygonCollider2D, PolygonCollider2D,
Prefab, Prefab,
Vec2, Vec2,
Vec3,
} from 'cc'; } from 'cc';
import TimeConfig from '../Enum/TimeConfig'; import TimeConfig from '../Enum/TimeConfig';
import { CameraController } from '../Environments/CameraController'; import { CameraController } from '../Environments/CameraController';
import { registerGizmos } from '../Gizmos/Decorator'; import { registerGizmos } from '../Gizmos/Decorator';
import Gizmos2D from '../Gizmos/Gizmos2D'; import Gizmos2D from '../Gizmos/Gizmos2D';
import Gizmos3D from '../Gizmos/Gizmos3D';
import AudioManager from '../Manager/AudioManager'; import AudioManager from '../Manager/AudioManager';
import { GameManager } from '../Manager/GameManager'; import { GameManager } from '../Manager/GameManager';
import ObjectPool from '../Pool/ObjectPool'; import ObjectPool from '../Pool/ObjectPool';
import Utilities from '../Utilities'; import Utils from '../Utilities';
import { Ball } from './Ball'; import { Ball } from './Ball';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ -92,9 +90,9 @@ export class MultiBall extends Component {
pos.z = 10; pos.z = 10;
fx.node.setWorldPosition(pos); fx.node.setWorldPosition(pos);
AudioManager.playSfx(this._soundFX); AudioManager.playSfx(this._soundFX);
await Utilities.delay(TimeConfig.DelayMultiBall); await Utils.delay(TimeConfig.DelayMultiBall);
this._colliderEnabled = true; this._colliderEnabled = true;
await Utilities.waitUntil(() => fx.isStopped); await Utils.waitUntil(() => fx.isStopped);
this._fxPool.release(fx); this._fxPool.release(fx);
} }
} }

View File

@ -28,7 +28,7 @@ import AudioManager from '../Manager/AudioManager';
import { EventManger } from '../Manager/EventManger'; import { EventManger } from '../Manager/EventManger';
import IPoolable from '../Pool/IPoolable'; import IPoolable from '../Pool/IPoolable';
import ObjectPool from '../Pool/ObjectPool'; import ObjectPool from '../Pool/ObjectPool';
import Utilities from '../Utilities'; import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('Ball') @ccclass('Ball')
@ -169,7 +169,7 @@ export class Ball extends Component implements IPoolable {
AudioManager.playSfx( AudioManager.playSfx(
otherCollider.group == PhysicsGroup.FLIPPER ? this._impactFlipperSound : this._impactSound, otherCollider.group == PhysicsGroup.FLIPPER ? this._impactFlipperSound : this._impactSound,
); );
await Utilities.waitUntil(() => hitFx.isStopped, 0.1); await Utils.waitUntil(() => hitFx.isStopped, 0.1);
this._impactPool.release(hitFx); this._impactPool.release(hitFx);
} }
} else if (otherCollider.tag == 1) { } else if (otherCollider.tag == 1) {

View File

@ -39,7 +39,7 @@ class GizmosDebugDraw extends Component {
private _useLocalPosition: boolean = false; private _useLocalPosition: boolean = false;
private _layer: Layers.Enum = Gizmos2D.DEFAULT_LAYER; private _layer: Layers.Enum = Gizmos2D.DEFAULT_LAYER;
protected update(dt: number): void { protected lateUpdate(dt: number): void {
this._renderers.forEach((renderer) => { this._renderers.forEach((renderer) => {
renderer.clear(); renderer.clear();
renderer.draw(); renderer.draw();
@ -58,6 +58,7 @@ class GizmosDebugDraw extends Component {
g.fillColor = color; g.fillColor = color;
g.node.layer = this.node.layer; g.node.layer = this.node.layer;
g.node.parent = this.node; g.node.parent = this.node;
g.node.setPosition(Vec3.ZERO);
const renderer = new GizmosRenderer(g); const renderer = new GizmosRenderer(g);
return renderer; return renderer;
} }
@ -287,6 +288,7 @@ export default class Gizmos2D {
debugNode.node.layer = this.DEFAULT_LAYER; debugNode.node.layer = this.DEFAULT_LAYER;
debugNode.node.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy; debugNode.node.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy;
debugNode.node.parent = node; debugNode.node.parent = node;
debugNode.node.setPosition(Vec3.ZERO);
} }
return debugNode; return debugNode;
} }

View File

@ -45,7 +45,7 @@ class GizmosDebugDraw extends Component {
} }
} }
protected update(dt: number): void { protected lateUpdate(dt: number): void {
this._color = Gizmos3D.DEFAULT_COLOR; this._color = Gizmos3D.DEFAULT_COLOR;
this._useLocalPosition = false; this._useLocalPosition = false;
} }

View File

@ -1,6 +1,6 @@
import { _decorator, assetManager, Component, ImageAsset, JsonAsset, Node, SpriteFrame, Texture2D } from 'cc'; import { _decorator, assetManager, Component, ImageAsset, JsonAsset, Node, SpriteFrame, Texture2D } from 'cc';
import Singleton from '../Singleton'; import Singleton from '../Singleton';
import Utilities from '../Utilities'; import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ -50,7 +50,7 @@ export default class DynamicSpriteManager extends Singleton<DynamicSpriteManager
} }
public async getSpriteFrame(id: string): Promise<SpriteFrame> { public async getSpriteFrame(id: string): Promise<SpriteFrame> {
await Utilities.waitUntil(() => this.initialized); await Utils.waitUntil(() => this.initialized);
return this.spriteMap.get(id); return this.spriteMap.get(id);
} }
} }

View File

@ -6,7 +6,6 @@ import {
EPhysics2DDrawFlags, EPhysics2DDrawFlags,
Node, Node,
PhysicsSystem2D, PhysicsSystem2D,
Prefab,
Quat, Quat,
randomRangeInt, randomRangeInt,
SpriteFrame, SpriteFrame,
@ -19,12 +18,12 @@ import BoosterType from '../Enum/BoosterType';
import GameState from '../Enum/GameState'; import GameState from '../Enum/GameState';
import ScoreType from '../Enum/ScoreType'; import ScoreType from '../Enum/ScoreType';
import TimeConfig from '../Enum/TimeConfig'; import TimeConfig from '../Enum/TimeConfig';
import { FloatingText } from '../Environments/FloatingText';
import GameEvent from '../Events/GameEvent'; import GameEvent from '../Events/GameEvent';
import BallFactory from '../Factory/BallFactory';
import FloatingTextFactory from '../Factory/FloatingTextFactory';
import { Ball } from '../GamePlay/Ball'; import { Ball } from '../GamePlay/Ball';
import ObjectPool from '../Pool/ObjectPool';
import Singleton from '../Singleton'; import Singleton from '../Singleton';
import Utilities from '../Utilities'; import Utils from '../Utilities';
import AudioManager from './AudioManager'; import AudioManager from './AudioManager';
import { EventManger } from './EventManger'; import { EventManger } from './EventManger';
import { StickerManager } from './StickerManager'; import { StickerManager } from './StickerManager';
@ -32,7 +31,7 @@ const { ccclass, property } = _decorator;
window.addEventListener('message', (data) => { window.addEventListener('message', (data) => {
const { data: res } = data; const { data: res } = data;
const objectRes = Utilities.getJson(res); const objectRes = Utils.getJson(res);
if (objectRes) { if (objectRes) {
const { type, value } = objectRes; const { type, value } = objectRes;
if (type === 'newTicket') { if (type === 'newTicket') {
@ -57,16 +56,14 @@ class Booster {
export class GameManager extends Singleton<GameManager>() { export class GameManager extends Singleton<GameManager>() {
@property({ visible: true }) @property({ visible: true })
private _colliderDebug: boolean = false; private _colliderDebug: boolean = false;
@property({ type: Prefab, visible: true }) @property({ type: FloatingTextFactory, visible: true })
private _ballPrefab: Prefab; private _floatingScoreFactory: FloatingTextFactory;
@property({ type: Prefab, visible: true })
private _floatingScoreText: Prefab;
@property({ type: Node, visible: true }) @property({ type: Node, visible: true })
private _topContainer: Node; private _topContainer: Node;
@property({ type: Node, visible: true }) @property({ type: Node, visible: true })
private _ballHolder: Node; private _ballHolder: Node;
@property({ visible: true }) @property({ visible: true })
private _ballSpawnPosition: Vec3; private _ballSpawnPosition: Vec3 = new Vec3();
@property({ type: CCInteger, visible: true }) @property({ type: CCInteger, visible: true })
private readonly _timePlay = 120; private readonly _timePlay = 120;
@ -84,8 +81,6 @@ export class GameManager extends Singleton<GameManager>() {
@property({ type: AudioClip, visible: true }) @property({ type: AudioClip, visible: true })
private _gameOverMusic: AudioClip; private _gameOverMusic: AudioClip;
private _ballPool: ObjectPool;
private _FloatingScorePool: ObjectPool;
private _gameState: GameState; private _gameState: GameState;
private _timer: Timer = new Timer(TimerType.countDown); private _timer: Timer = new Timer(TimerType.countDown);
private _boostersActive: Booster[] = []; private _boostersActive: Booster[] = [];
@ -119,8 +114,6 @@ export class GameManager extends Singleton<GameManager>() {
protected onLoad(): void { protected onLoad(): void {
super.onLoad(); super.onLoad();
this._ballPool = new ObjectPool(this._ballPrefab, 10, true, Ball);
this._FloatingScorePool = new ObjectPool(this._floatingScoreText, 10, true);
BEConnector.getGameData(); BEConnector.getGameData();
if (this._colliderDebug) PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Shape; if (this._colliderDebug) PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Shape;
} }
@ -130,6 +123,7 @@ export class GameManager extends Singleton<GameManager>() {
} }
protected update(dt: number): void { protected update(dt: number): void {
this._timer.update(dt);
if (this._gameState != GameState.Playing) return; if (this._gameState != GameState.Playing) return;
for (let i = 0; i < this._boostersActive.length; i++) { for (let i = 0; i < this._boostersActive.length; i++) {
const booster = this._boostersActive[i]; const booster = this._boostersActive[i];
@ -179,7 +173,7 @@ export class GameManager extends Singleton<GameManager>() {
opts?: { scaleMin?: number; scaleMax?: number; duration?: number }, opts?: { scaleMin?: number; scaleMax?: number; duration?: number },
) { ) {
this._score += score; this._score += score;
const floatingScore = this._FloatingScorePool.get(FloatingText, this._topContainer); const floatingScore = this._floatingScoreFactory.create(this._topContainer);
floatingScore.show( floatingScore.show(
`+${score}`, `+${score}`,
position, position,
@ -197,9 +191,9 @@ export class GameManager extends Singleton<GameManager>() {
opts: { scaleMin: number; scaleMax: number; duration: number }, opts: { scaleMin: number; scaleMax: number; duration: number },
) { ) {
this._isWaitingUpdateScore = true; this._isWaitingUpdateScore = true;
await Utilities.waitUntil(predicate); await Utils.waitUntil(predicate);
this._score += score; this._score += score;
const floatingScore = this._FloatingScorePool.get(FloatingText, this._topContainer); const floatingScore = this._floatingScoreFactory.create(this._topContainer);
floatingScore.show(`+${score}`, position, score >= 100 ? opts.scaleMax : opts.scaleMin, opts.duration); floatingScore.show(`+${score}`, position, score >= 100 ? opts.scaleMax : opts.scaleMin, opts.duration);
EventManger.instance.emit(GameEvent.Score, [this._score, score, type, position]); EventManger.instance.emit(GameEvent.Score, [this._score, score, type, position]);
this._isWaitingUpdateScore = false; this._isWaitingUpdateScore = false;
@ -217,7 +211,7 @@ export class GameManager extends Singleton<GameManager>() {
EventManger.instance.emit(GameEvent.WarningTime, true); EventManger.instance.emit(GameEvent.WarningTime, true);
} }
EventManger.instance.emit(GameEvent.TimeUpdate, this._timer.timeRound); EventManger.instance.emit(GameEvent.TimeUpdate, this._timer.timeRound);
await Utilities.delay(1); await Utils.delay(1);
} }
} }
@ -226,7 +220,7 @@ export class GameManager extends Singleton<GameManager>() {
if (value > 0 && this._currentBallInGame >= 2) { if (value > 0 && this._currentBallInGame >= 2) {
this._isMultiBall = true; this._isMultiBall = true;
EventManger.instance.emit(GameEvent.MultiBall, true); EventManger.instance.emit(GameEvent.MultiBall, true);
this._ballPool.listActive.forEach((ball) => ball.getComponent(Ball).playMultiBallEffect()); BallFactory.instance.listActive.forEach((ball) => ball.getComponent(Ball).playMultiBallEffect());
} }
if (this._currentBallInGame <= 0) { if (this._currentBallInGame <= 0) {
@ -241,7 +235,7 @@ export class GameManager extends Singleton<GameManager>() {
if (this._gameState != GameState.Playing) return; if (this._gameState != GameState.Playing) return;
if (playStartSound) AudioManager.playSfx(this._startSound); if (playStartSound) AudioManager.playSfx(this._startSound);
this.setCurrentBallInGame(1); this.setCurrentBallInGame(1);
const ball = this._ballPool.get(Ball, this._ballHolder); const ball = BallFactory.instance.create(this._ballHolder);
ball.init(this._boostersActive.length > 0); ball.init(this._boostersActive.length > 0);
ball.node.setRotation(Quat.IDENTITY); ball.node.setRotation(Quat.IDENTITY);
ball.node.setPosition(this._ballSpawnPosition); ball.node.setPosition(this._ballSpawnPosition);
@ -261,7 +255,7 @@ export class GameManager extends Singleton<GameManager>() {
EventManger.instance.emit(GameEvent.BallOut, null); EventManger.instance.emit(GameEvent.BallOut, null);
AudioManager.playSfx(this._ballOutSound); AudioManager.playSfx(this._ballOutSound);
this.DisableAllBooster(); this.DisableAllBooster();
await Utilities.delay(TimeConfig.DelayPLay); await Utils.delay(TimeConfig.DelayPLay);
this.spawnBall(true); this.spawnBall(true);
} }
} }
@ -274,7 +268,7 @@ export class GameManager extends Singleton<GameManager>() {
}); });
this.setCurrentBallInGame(-1); this.setCurrentBallInGame(-1);
if (this._currentBallInGame <= 0) { if (this._currentBallInGame <= 0) {
await Utilities.delay(TimeConfig.DelayGoal); await Utils.delay(TimeConfig.DelayGoal);
this.spawnBall(true); this.spawnBall(true);
} }
} }
@ -286,11 +280,11 @@ export class GameManager extends Singleton<GameManager>() {
scaleMax: 2, scaleMax: 2,
duration: 0.7, duration: 0.7,
}); });
await Utilities.delay(0.3); await Utils.delay(0.3);
} }
if (bonusTime) { if (bonusTime) {
this.addTime(bonusTime); this.addTime(bonusTime);
const floatingScore = this._FloatingScorePool.get(FloatingText, this._topContainer); const floatingScore = this._floatingScoreFactory.create(this._topContainer);
floatingScore.show(`+${bonusTime}`, position, 1.5, 1, this._clockIcon); floatingScore.show(`+${bonusTime}`, position, 1.5, 1, this._clockIcon);
} }
} }
@ -305,7 +299,7 @@ export class GameManager extends Singleton<GameManager>() {
} }
public async gameOver() { public async gameOver() {
this._ballPool.releaseAll(); BallFactory.instance.releaseAll();
this.DisableAllBooster(); this.DisableAllBooster();
AudioManager.playBGM(this._gameOverMusic); AudioManager.playBGM(this._gameOverMusic);
StickerManager.instance.showLabel('TIME UP!!!', { color: new Color('#ed3a18'), outLineColor: Color.WHITE }); StickerManager.instance.showLabel('TIME UP!!!', { color: new Color('#ed3a18'), outLineColor: Color.WHITE });
@ -330,7 +324,7 @@ export class GameManager extends Singleton<GameManager>() {
this._currentBallInGame = 0; this._currentBallInGame = 0;
this._isMultiBall = false; this._isMultiBall = false;
this.changeGameState(GameState.Playing); this.changeGameState(GameState.Playing);
await Utilities.delay(TimeConfig.DelayPLay); await Utils.delay(TimeConfig.DelayPLay);
this._timer.startCount(); this._timer.startCount();
this.spawnBall(true); this.spawnBall(true);
} }
@ -342,7 +336,7 @@ export class GameManager extends Singleton<GameManager>() {
this._isMultiBall = false; this._isMultiBall = false;
AudioManager.playBGM(this._backgroundMusic); AudioManager.playBGM(this._backgroundMusic);
this.changeGameState(GameState.Playing); this.changeGameState(GameState.Playing);
await Utilities.delay(TimeConfig.DelayPLay); await Utils.delay(TimeConfig.DelayPLay);
this._timer.startCount(); this._timer.startCount();
this.spawnBall(true); this.spawnBall(true);
} }

View File

@ -1,4 +1,4 @@
import { _decorator, CCFloat, CCInteger, Color, Component, Node, Prefab, randomRangeInt } from 'cc'; import { _decorator, CCFloat, CCInteger, Color, Component, Node, Prefab, randomRangeInt, Vec3 } from 'cc';
import { BoosterBase } from '../Booster/BoosterBase'; import { BoosterBase } from '../Booster/BoosterBase';
import GameState from '../Enum/GameState'; import GameState from '../Enum/GameState';
import ScoreType from '../Enum/ScoreType'; import ScoreType from '../Enum/ScoreType';
@ -55,8 +55,8 @@ export class SpawnObjectManager extends Component {
private _spawnTimeObject = 0; private _spawnTimeObject = 0;
onDrawGizmos(): void { onDrawGizmos(): void {
for (let i = 0; i < this._spawnPoints.length; i++) {
Gizmos2D.beginColor(this.node, new Color(0, 255, 0, 180)); Gizmos2D.beginColor(this.node, new Color(0, 255, 0, 180));
for (let i = 0; i < this._spawnPoints.length; i++) {
Gizmos2D.drawSolidCircle(this.node, this._spawnPoints[i].worldPosition, 15); Gizmos2D.drawSolidCircle(this.node, this._spawnPoints[i].worldPosition, 15);
} }
} }

View File

@ -0,0 +1,22 @@
import { _decorator, Component, Node, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('FloatingSprite')
export default class FloatingSprite extends Component {
public moveToPosition(target: Vec3, onComplete?: () => void) {
tween(this.node)
.to(
1,
{ worldPosition: target },
{
easing: 'cubicOut',
onComplete: () => {
this.node.releaseToPool();
onComplete?.();
},
},
)
.start();
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "311ac3b6-a44c-4fce-a39f-1cab6516e797",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -1,18 +1,20 @@
import { _decorator, AudioClip, Component, geometry, Label, Node, Prefab, Tween, tween, Vec3 } from 'cc'; import { _decorator, AudioClip, Component, geometry, Label, Node, Tween, tween, Vec3 } from 'cc';
import BEConnector from '../API/BEConnector'; import BEConnector from '../API/BEConnector';
import GameState from '../Enum/GameState'; import GameState from '../Enum/GameState';
import GameEvent from '../Events/GameEvent'; import GameEvent from '../Events/GameEvent';
import SpriteFloatingFactory from '../Factory/SpriteFloatingFactory';
import AudioManager from '../Manager/AudioManager'; import AudioManager from '../Manager/AudioManager';
import { EventManger } from '../Manager/EventManger'; import { EventManger } from '../Manager/EventManger';
import { GameManager } from '../Manager/GameManager'; import { GameManager } from '../Manager/GameManager';
import ObjectPool from '../Pool/ObjectPool'; import Utils from '../Utilities';
import Utilities from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('GameOverPanel') @ccclass('GameOverPanel')
export class GameOverPanel extends Component { export class GameOverPanel extends Component {
@property(Label) private topScore: Label = null; @property(Label)
@property(Label) private yourScore: Label = null; private topScore: Label = null;
@property(Label)
private yourScore: Label = null;
@property({ type: Label, visible: true }) @property({ type: Label, visible: true })
private _ticketMinus: Label; private _ticketMinus: Label;
@ -24,8 +26,8 @@ export class GameOverPanel extends Component {
@property({ type: Node, visible: true }) @property({ type: Node, visible: true })
private _scoreUI: Node; private _scoreUI: Node;
@property({ type: Prefab, visible: true }) @property({ type: SpriteFloatingFactory, visible: true })
private _scorePrefab: Prefab; private _floatingStarFactory: SpriteFloatingFactory;
@property({ type: AudioClip, visible: true }) @property({ type: AudioClip, visible: true })
private _soundCollectCoinFx: AudioClip; private _soundCollectCoinFx: AudioClip;
@ -38,13 +40,11 @@ export class GameOverPanel extends Component {
@property({ type: geometry.AnimationCurve, visible: true }) @property({ type: geometry.AnimationCurve, visible: true })
private _starScaleCurve: geometry.AnimationCurve = new geometry.AnimationCurve(); private _starScaleCurve: geometry.AnimationCurve = new geometry.AnimationCurve();
private _pool: ObjectPool;
private _active = false; private _active = false;
private _clicked = false; private _clicked = false;
private _end = false; private _end = false;
protected onLoad(): void { protected onLoad(): void {
this._pool = new ObjectPool(this._scorePrefab, 100, true);
EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this); EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this);
} }
@ -74,7 +74,7 @@ export class GameOverPanel extends Component {
this._quitBtn.active = false; this._quitBtn.active = false;
this._end = true; this._end = true;
if (this._active) { if (this._active) {
await Utilities.delay(1); await Utils.delay(1);
BEConnector.postScoreToServer(); BEConnector.postScoreToServer();
} }
break; break;
@ -131,9 +131,9 @@ export class GameOverPanel extends Component {
score += x; score += x;
duration = this._starSpeedCurve.evaluate(i / items - 1); duration = this._starSpeedCurve.evaluate(i / items - 1);
score = score > totalScore ? totalScore : score; score = score > totalScore ? totalScore : score;
const obj = this._pool.get(this._scoreUI); const obj = this._floatingStarFactory.create(this.node);
obj.setWorldPosition(this._scoreUI.worldPosition); obj.node.setWorldPosition(this._scoreUI.worldPosition);
tween(obj) tween(obj.node)
.to( .to(
duration, duration,
{ worldPosition: target }, { worldPosition: target },
@ -145,7 +145,7 @@ export class GameOverPanel extends Component {
}, },
}, },
) )
.call(() => this._pool.release(obj)) .call(() => obj.node.releaseToPool())
.call(async () => { .call(async () => {
Tween.stopAllByTarget(this.yourScore.node); Tween.stopAllByTarget(this.yourScore.node);
this.yourScore.string = score.toString(); this.yourScore.string = score.toString();
@ -156,10 +156,10 @@ export class GameOverPanel extends Component {
}) })
.start(); .start();
AudioManager.playSfx(this._soundCollectCoinFx); AudioManager.playSfx(this._soundCollectCoinFx);
await Utilities.delay(duration / 3); await Utils.delay(duration / 3);
} }
await Utilities.waitUntil(() => this._pool.countActive == 0, 0.1); await Utils.waitUntil(() => this._floatingStarFactory.countActive == 0, 0.1);
this.yourScore.string = totalScore.toString(); this.yourScore.string = totalScore.toString();
AudioManager.playSfx(this._soundScore); AudioManager.playSfx(this._soundScore);
Tween.stopAllByTarget(this.yourScore.node); Tween.stopAllByTarget(this.yourScore.node);
@ -169,7 +169,7 @@ export class GameOverPanel extends Component {
.to(0.3, { scale: new Vec3(1, 1) }, { easing: 'backOut' }) .to(0.3, { scale: new Vec3(1, 1) }, { easing: 'backOut' })
.start(); .start();
if (!this._end) return; if (!this._end) return;
await Utilities.delay(1); await Utils.delay(1);
BEConnector.postScoreToServer(); BEConnector.postScoreToServer();
} }
} }

View File

@ -1,5 +1,5 @@
import { _decorator, Animation, Component, Node } from 'cc'; import { _decorator, Animation, Component, Node } from 'cc';
import Utilities from '../Utilities'; import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('StartScreenController') @ccclass('StartScreenController')
@ -9,7 +9,7 @@ export class StartScreenController extends Component {
protected async start() { protected async start() {
this._animation.play(); this._animation.play();
await Utilities.waitUntil(() => !this._animation.getState(this._animation.defaultClip.name).isPlaying); await Utils.waitUntil(() => !this._animation.getState(this._animation.defaultClip.name).isPlaying);
this._animation.play(this._animation.clips[1].name); this._animation.play(this._animation.clips[1].name);
} }
} }

View File

@ -12,12 +12,12 @@ import {
tween, tween,
Vec3, Vec3,
} from 'cc'; } from 'cc';
import { GameManager } from '../Manager/GameManager';
import TimeConfig from '../Enum/TimeConfig';
import Utilities from '../Utilities';
import { EventManger } from '../Manager/EventManger';
import GameEvent from '../Events/GameEvent';
import GameState from '../Enum/GameState'; import GameState from '../Enum/GameState';
import TimeConfig from '../Enum/TimeConfig';
import GameEvent from '../Events/GameEvent';
import { EventManger } from '../Manager/EventManger';
import { GameManager } from '../Manager/GameManager';
import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('TutorialController') @ccclass('TutorialController')
@ -88,7 +88,7 @@ export class TutorialController extends Component {
.union() .union()
.repeatForever() .repeatForever()
.start(); .start();
await Utilities.delay(0.5); await Utils.delay(0.5);
tween(this._tapR) tween(this._tapR)
.call(() => this._tapREffect.clear()) .call(() => this._tapREffect.clear())
.to(0.5, { position: new Vec3(470, -500), scale: new Vec3(0.9, 0.9) }, { easing: 'quintOut' }) .to(0.5, { position: new Vec3(470, -500), scale: new Vec3(0.9, 0.9) }, { easing: 'quintOut' })

View File

@ -1,13 +1,13 @@
import { _decorator, Color, Component, Label, Node, ParticleSystem, Vec3 } from 'cc'; import { _decorator, Color, Component, Label, Node, ParticleSystem, Vec3 } from 'cc';
import { EventManger } from '../Manager/EventManger';
import GameEvent from '../Events/GameEvent';
import ScoreType from '../Enum/ScoreType';
import GameState from '../Enum/GameState';
import { GameManager } from '../Manager/GameManager';
import BEConnector from '../API/BEConnector'; import BEConnector from '../API/BEConnector';
import Utilities from '../Utilities';
import { StickerManager } from '../Manager/StickerManager';
import BoosterType from '../Enum/BoosterType'; import BoosterType from '../Enum/BoosterType';
import GameState from '../Enum/GameState';
import ScoreType from '../Enum/ScoreType';
import GameEvent from '../Events/GameEvent';
import { EventManger } from '../Manager/EventManger';
import { GameManager } from '../Manager/GameManager';
import { StickerManager } from '../Manager/StickerManager';
import Utils from '../Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('UIController') @ccclass('UIController')
@ -71,12 +71,12 @@ export class UIController extends Component {
break; break;
case GameState.GameOver: case GameState.GameOver:
this._buffFx.setNodeActive(false); this._buffFx.setNodeActive(false);
await Utilities.waitUntil(() => !GameManager.instance.isWaitingUpdateScore); await Utils.waitUntil(() => !GameManager.instance.isWaitingUpdateScore);
await Utilities.delay(2); await Utils.delay(2);
this._overPanel.active = true; this._overPanel.active = true;
break; break;
case GameState.End: case GameState.End:
await Utilities.delay(2); await Utils.delay(2);
this._overPanel.active = true; this._overPanel.active = true;
break; break;
case GameState.Relive: case GameState.Relive:

View File

@ -1,4 +1,4 @@
export default class Utilities { export default class Utils {
/** /**
* *
* @param time (s) * @param time (s)

15
package-lock.json generated
View File

@ -6,22 +6,14 @@
"": { "": {
"name": "PinBallTCC", "name": "PinBallTCC",
"dependencies": { "dependencies": {
"crypto-es": "^2.1.0", "crypto-es": "^2.1.0"
"howler": "^2.2.4"
}, },
"devDependencies": { "devDependencies": {
"@types/howler": "^2.2.11",
"husky": "^9.0.11", "husky": "^9.0.11",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"pretty-quick": "^4.0.0" "pretty-quick": "^4.0.0"
} }
}, },
"node_modules/@types/howler": {
"version": "2.2.11",
"resolved": "https://registry.npmjs.org/@types/howler/-/howler-2.2.11.tgz",
"integrity": "sha512-7aBoUL6RbSIrqKnpEgfa1wSNUBK06mn08siP2QI0zYk7MXfEJAaORc4tohamQYqCqVESoDyRWSdQn2BOKWj2Qw==",
"dev": true
},
"node_modules/cross-spawn": { "node_modules/cross-spawn": {
"version": "7.0.3", "version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@ -92,11 +84,6 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/howler": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/howler/-/howler-2.2.4.tgz",
"integrity": "sha512-iARIBPgcQrwtEr+tALF+rapJ8qSc+Set2GJQl7xT1MQzWaVkFebdJhR3alVlSiUf5U7nAANKuj3aWpwerocD5w=="
},
"node_modules/human-signals": { "node_modules/human-signals": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",

View File

@ -5,11 +5,9 @@
"version": "3.8.2" "version": "3.8.2"
}, },
"dependencies": { "dependencies": {
"crypto-es": "^2.1.0", "crypto-es": "^2.1.0"
"howler": "^2.2.4"
}, },
"devDependencies": { "devDependencies": {
"@types/howler": "^2.2.11",
"husky": "^9.0.11", "husky": "^9.0.11",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"pretty-quick": "^4.0.0" "pretty-quick": "^4.0.0"