fix: booster gacha not inactive

feature/ads-smart-display
tiendat3699 2024-06-11 13:38:06 +07:00
parent 77e1e74333
commit ff838f52a0
13 changed files with 336 additions and 182 deletions

View File

@ -1133,6 +1133,9 @@
"_animation": { "_animation": {
"__id__": 82 "__id__": 82
}, },
"sprite": {
"__id__": 73
},
"displayName": "CHEESE", "displayName": "CHEESE",
"time": 10, "time": 10,
"_id": "" "_id": ""

View File

@ -1133,8 +1133,11 @@
"_animation": { "_animation": {
"__id__": 82 "__id__": 82
}, },
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX", "displayName": "SECRET BOX",
"time": 0, "duration": 1,
"gachaType": 2, "gachaType": 2,
"_id": "" "_id": ""
}, },

View File

@ -1133,8 +1133,11 @@
"_animation": { "_animation": {
"__id__": 82 "__id__": 82
}, },
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX", "displayName": "SECRET BOX",
"time": 0, "duration": 1,
"gachaType": 0, "gachaType": 0,
"_id": "" "_id": ""
}, },

View File

@ -1133,8 +1133,11 @@
"_animation": { "_animation": {
"__id__": 82 "__id__": 82
}, },
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX", "displayName": "SECRET BOX",
"time": 0, "duration": 1,
"gachaType": 2, "gachaType": 2,
"_id": "" "_id": ""
}, },

View File

@ -1133,8 +1133,11 @@
"_animation": { "_animation": {
"__id__": 82 "__id__": 82
}, },
"sprite": {
"__id__": 73
},
"displayName": "SECRET BOX", "displayName": "SECRET BOX",
"time": 0, "duration": 1,
"gachaType": 1, "gachaType": 1,
"_id": "" "_id": ""
}, },

View File

@ -24,18 +24,18 @@
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 31
},
{
"__id__": 33
},
{ {
"__id__": 35 "__id__": 35
},
{
"__id__": 37
},
{
"__id__": 39
} }
], ],
"_prefab": { "_prefab": {
"__id__": 37 "__id__": 41
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -84,18 +84,18 @@
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{
"__id__": 24
},
{
"__id__": 26
},
{ {
"__id__": 28 "__id__": 28
},
{
"__id__": 30
},
{
"__id__": 32
} }
], ],
"_prefab": { "_prefab": {
"__id__": 30 "__id__": 34
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -298,19 +298,22 @@
"_children": [ "_children": [
{ {
"__id__": 11 "__id__": 11
},
{
"__id__": 17
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 19 "__id__": 23
}, },
{ {
"__id__": 21 "__id__": 25
} }
], ],
"_prefab": { "_prefab": {
"__id__": 23 "__id__": 27
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -357,17 +360,14 @@
}, },
{ {
"__id__": 14 "__id__": 14
},
{
"__id__": 16
} }
], ],
"_prefab": { "_prefab": {
"__id__": 18 "__id__": 16
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -231.45703125, "x": -125.884765625,
"y": 0, "y": 0,
"z": 0 "z": 0
}, },
@ -420,7 +420,7 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "33YwxJiIZFx52T+GuIPANS" "fileId": "18zn0tVhhFMpybcPN2M0FU"
}, },
{ {
"__type__": "cc.Label", "__type__": "cc.Label",
@ -445,7 +445,7 @@
"a": 255 "a": 255
}, },
"_string": "100", "_string": "100",
"_horizontalAlign": 2, "_horizontalAlign": 1,
"_verticalAlign": 1, "_verticalAlign": 1,
"_actualFontSize": 100, "_actualFontSize": 100,
"_fontSize": 100, "_fontSize": 100,
@ -491,43 +491,7 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "abqDTVc0pLFJAI+MKxq3eQ" "fileId": "f0DWlVpChH9b/FpF1x9GMP"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 11
},
"_enabled": true,
"__prefab": {
"__id__": 17
},
"_alignFlags": 10,
"_target": null,
"_left": -161.572265625,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "a0YsiditVM1JgTlUtoFyOX"
}, },
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
@ -537,27 +501,77 @@
"asset": { "asset": {
"__id__": 0 "__id__": 0
}, },
"fileId": "c6lHFE6oBJM6bTulGiWcBC", "fileId": "2au8tDWs9GiJ0Z29DO/vrO",
"instance": null, "instance": null,
"targetOverrides": null, "targetOverrides": null,
"nestedPrefabInstanceRoots": null "nestedPrefabInstanceRoots": null
}, },
{
"__type__": "cc.Node",
"_name": "Sprite",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 10
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 18
},
{
"__id__": 20
}
],
"_prefab": {
"__id__": 22
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 58.23046875,
"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
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 10 "__id__": 17
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 20 "__id__": 19
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 288, "width": 200,
"height": 281 "height": 200
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -568,7 +582,7 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "00TALsq4ZHl6Ld0LVWiUr7" "fileId": "eeSLyxaSdA14MnU1JhQE8L"
}, },
{ {
"__type__": "cc.Sprite", "__type__": "cc.Sprite",
@ -576,11 +590,11 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 10 "__id__": 17
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 22 "__id__": 21
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -592,7 +606,10 @@
"b": 255, "b": 255,
"a": 255 "a": 255
}, },
"_spriteFrame": null, "_spriteFrame": {
"__uuid__": "5b5a3073-f986-4350-9ef0-e1fddb56a494@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0, "_type": 0,
"_fillType": 0, "_fillType": 0,
"_sizeMode": 0, "_sizeMode": 0,
@ -610,7 +627,86 @@
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "6dTw63zDlHr4d6fvs5Jqp2" "fileId": "ecbp9qmr5AsK8U3oG22/LR"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "01q2I1EmNPXr4APxBvWUXg",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 24
},
"_contentSize": {
"__type__": "cc.Size",
"width": 400,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "00TALsq4ZHl6Ld0LVWiUr7"
},
{
"__type__": "cc.Layout",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 26
},
"_resizeMode": 0,
"_layoutType": 1,
"_cellSize": {
"__type__": "cc.Size",
"width": 40,
"height": 40
},
"_startAxis": 0,
"_paddingLeft": 0,
"_paddingRight": 0,
"_paddingTop": 0,
"_paddingBottom": 0,
"_spacingX": 10,
"_spacingY": 0,
"_verticalDirection": 1,
"_horizontalDirection": 0,
"_constraint": 0,
"_constraintNum": 2,
"_affectedByScale": false,
"_isAlign": true,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "289shnSS9OzLTNRZIo1ZaP"
}, },
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
@ -635,7 +731,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 25 "__id__": 29
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -663,7 +759,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 27 "__id__": 31
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -708,7 +804,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 29 "__id__": 33
}, },
"ignoreTimeScale": true, "ignoreTimeScale": true,
"_id": "" "_id": ""
@ -740,7 +836,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 32 "__id__": 36
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -768,10 +864,10 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 34 "__id__": 38
}, },
"skeleton": { "skeleton": {
"__id__": 26 "__id__": 30
}, },
"_flipX": false, "_flipX": false,
"_flipY": false, "_flipY": false,
@ -791,16 +887,19 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 36 "__id__": 40
}, },
"animationHandler": { "animationHandler": {
"__id__": 33 "__id__": 37
}, },
"spineRoot": { "spineRoot": {
"__id__": 2 "__id__": 2
}, },
"rewardRoot": {
"__id__": 10
},
"rewardSprite": { "rewardSprite": {
"__id__": 21 "__id__": 20
}, },
"rewardLabel": { "rewardLabel": {
"__id__": 14 "__id__": 14

View File

@ -34389,7 +34389,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": null, "__prefab": null,
"_colliderDebug": false, "_colliderDebug": true,
"_floatingScoreFactory": { "_floatingScoreFactory": {
"__id__": 6 "__id__": 6
}, },

View File

@ -1,7 +1,21 @@
import { _decorator, Animation, AudioClip, CCFloat, CCString, Collider2D, Component, Contact2DType } from 'cc'; import {
_decorator,
Animation,
AudioClip,
CCFloat,
CCString,
Collider2D,
Component,
Contact2DType,
Node,
Sprite,
Vec3,
} from 'cc';
import BoosterType from '../Enum/BoosterType';
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 { 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 Utils from '../Utilities'; import Utils from '../Utilities';
@ -15,35 +29,73 @@ export class BoosterBase extends Component implements IPoolable {
protected _collectSound: AudioClip; protected _collectSound: AudioClip;
@property({ type: Animation, visible: true }) @property({ type: Animation, visible: true })
private _animation: Animation; private _animation: Animation;
@property(Sprite)
private sprite: Sprite;
@property(CCString) @property(CCString)
public readonly displayName: string = 'CHEESE'; public readonly displayName: string = 'CHEESE';
@property(CCFloat) @property(CCFloat)
protected time: number = 10; protected duration: number = 10;
private active: boolean = true; public readonly type: BoosterType;
private _timer: number = 0;
private _activeCollider: boolean = true;
private _active: boolean = false;
public get active() {
return this._active;
}
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.active = false; this._activeCollider = false;
} }
private onContactBegin(self: Collider2D, other: Collider2D) { private onContactBegin(self: Collider2D, other: Collider2D) {
if (!this.active) return; if (!this._activeCollider) return;
this.boosterActive(); this._activeCollider = 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); GameManager.instance.addBooster(this);
} }
protected boosterActive() {} public tick(dt: number) {
if (!this._active) return;
this.node.setPosition(Vec3.ZERO);
this._timer += dt;
if (this._timer >= this.duration) {
this._active = false;
}
}
public resetTime() {
this._timer = 0;
}
public collect(collector: Node) {
this._active = true;
this._timer = 0;
this.sprite.setNodeActive(false);
this.node.setParent(collector);
}
public end() {
if (!this.node.releaseToPool()) {
this.node.destroy();
}
}
public dispose() {
if (!this.node.releaseToPool()) {
this.node.destroy();
}
}
async onGet() { async onGet() {
this._animation.play(); this._animation.play();
await Utils.delay(this._animation.defaultClip.duration); await Utils.delay(this._animation.defaultClip.duration);
this.active = true; this._activeCollider = true;
this.sprite.setNodeActive(true);
} }
onRelease() { onRelease() {
this.active = false; this._activeCollider = false;
} }
} }

View File

@ -1,12 +1,20 @@
import { _decorator, Component, Node } from 'cc'; import { _decorator, Component, Node } from 'cc';
import { BoosterBase } from './BoosterBase';
import { GameManager } from '../Manager/GameManager';
import BoosterType from '../Enum/BoosterType'; import BoosterType from '../Enum/BoosterType';
import AudioManager from '../Manager/AudioManager';
import { BoosterBase } from './BoosterBase';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('CumulativeBooster') @ccclass('CumulativeBooster')
export class CumulativeBooster extends BoosterBase { export class CumulativeBooster extends BoosterBase {
protected boosterActive(): void { public readonly type: BoosterType = BoosterType.CumulativeBar;
GameManager.instance.ActiveBooster(BoosterType.CumulativeBar, this.time, this.displayName);
public collect(collector: Node): void {
super.collect(collector);
AudioManager.setPlayRateBGM(1.5);
}
public end(): void {
super.end();
AudioManager.setPlayRateBGM(1);
} }
} }

View File

@ -1,18 +1,24 @@
import { _decorator, Component, Node } from 'cc'; import { _decorator, Component, game, Node, TweenSystem } from 'cc';
import BoosterType from '../Enum/BoosterType'; import BoosterType from '../Enum/BoosterType';
import GachaManager, { GachaType } from '../Manager/GachaManager'; import GachaManager, { GachaType } from '../Manager/GachaManager';
import { GameManager } from '../Manager/GameManager';
import { BoosterBase } from './BoosterBase'; import { BoosterBase } from './BoosterBase';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('SecretBoxBooster') @ccclass('SecretBoxBooster')
export default class SecretBoxBooster extends BoosterBase { export default class SecretBoxBooster extends BoosterBase {
public readonly type: BoosterType = BoosterType.Gacha;
@property({ type: GachaType }) @property({ type: GachaType })
private gachaType: GachaType; private gachaType: GachaType;
protected boosterActive() { public collect(collector: Node) {
GameManager.instance.ActiveBooster(BoosterType.Gacha, this.time, this.displayName); super.collect(collector);
GachaManager.instance.show(this.gachaType, 1.5); GachaManager.instance.show(this.gachaType, 1.5);
} }
public tick(dt: number): void {
super.tick(dt);
TweenSystem.instance.update(game.deltaTime);
}
} }

View File

@ -12,6 +12,8 @@ export default class FreeReward extends GachaBase {
private animationHandler: SpineAnimationHandler; private animationHandler: SpineAnimationHandler;
@property(Node) @property(Node)
private spineRoot: Node; private spineRoot: Node;
@property(Node)
private rewardRoot: Node;
@property(Sprite) @property(Sprite)
private rewardSprite: Sprite; private rewardSprite: Sprite;
@property(Label) @property(Label)
@ -24,7 +26,7 @@ export default class FreeReward extends GachaBase {
protected onEnable(): void { protected onEnable(): void {
this.spineRoot.setActive(false); this.spineRoot.setActive(false);
this.rewardSprite.setNodeActive(false); this.rewardRoot.setActive(false);
this._opened = false; this._opened = false;
} }
@ -32,18 +34,13 @@ export default class FreeReward extends GachaBase {
if (this._startShowReward) { if (this._startShowReward) {
let k = clamp01(this._timer / 0.3); let k = clamp01(this._timer / 0.3);
k = easing.quintInOut(k); k = easing.quintInOut(k);
const targetScale = Vec3.lerp(this.rewardSprite.node.scale, Vec3.ZERO, Vec3.ONE, k); const targetScale = Vec3.lerp(this.rewardRoot.scale, Vec3.ZERO, Vec3.ONE, k);
const targetPosition = Vec3.lerp(this.rewardSprite.node.position, new Vec3(0, 150), new Vec3(0, 700), k); const targetPosition = Vec3.lerp(this.rewardRoot.position, new Vec3(0, 150), new Vec3(0, 700), k);
this.rewardSprite.node.setScale(targetScale); this.rewardRoot.setScale(targetScale);
this.rewardSprite.node.setPosition(targetPosition); this.rewardRoot.setPosition(targetPosition);
this._timer += game.deltaTime; this._timer += game.deltaTime;
if (k === 1) { if (k === 1) {
this._startShowReward = false; this._startShowReward = false;
GachaManager.instance.showFloatingText(
this._reward.quantity.toString(),
this.rewardSprite.node.worldPosition,
this._reward.icon,
);
GachaManager.instance.gachaDone(); GachaManager.instance.gachaDone();
} }
} }
@ -65,7 +62,7 @@ export default class FreeReward extends GachaBase {
this.rewardSprite.spriteFrame = this._reward.icon; this.rewardSprite.spriteFrame = this._reward.icon;
this.rewardLabel.string = this._reward.quantity.toString(); this.rewardLabel.string = this._reward.quantity.toString();
await Utils.delay(1); await Utils.delay(1);
this.rewardSprite.setNodeActive(true); this.rewardRoot.setActive(true);
this._startShowReward = true; this._startShowReward = true;
return; return;
} }

View File

@ -15,6 +15,7 @@ import {
} from 'cc'; } from 'cc';
import BEConnector from '../API/BEConnector'; import BEConnector from '../API/BEConnector';
import Timer, { TimerType } from '../Base/Timer'; import Timer, { TimerType } from '../Base/Timer';
import { BoosterBase } from '../Booster/BoosterBase';
import BoosterType from '../Enum/BoosterType'; 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';
@ -42,17 +43,6 @@ window.addEventListener('message', (data) => {
} }
}); });
class Booster {
public type: BoosterType;
public time: number;
public runningTime: number = 0;
constructor(type: BoosterType, time: number) {
this.type = type;
this.time = time;
}
}
@ccclass('GameManager') @ccclass('GameManager')
export class GameManager extends Singleton<GameManager>() { export class GameManager extends Singleton<GameManager>() {
@property({ visible: true }) @property({ visible: true })
@ -82,7 +72,7 @@ export class GameManager extends Singleton<GameManager>() {
private _gameState: GameState; private _gameState: GameState;
private _timer: Timer = new Timer(TimerType.countDown); private _timer: Timer = new Timer(TimerType.countDown);
private _boostersActive: Booster[] = []; private _activeBoosters: Map<BoosterType, BoosterBase> = new Map();
private _score = 0; private _score = 0;
private isReplayed = false; private isReplayed = false;
@ -124,17 +114,7 @@ export class GameManager extends Singleton<GameManager>() {
protected update(dt: number): void { protected update(dt: number): void {
this._timer.update(dt); 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++) { this.runBooster(dt);
const booster = this._boostersActive[i];
booster.runningTime += dt;
if (booster.runningTime >= booster.time) {
this._boostersActive.splice(i, 1);
if (this._boostersActive.length == 0) {
AudioManager.setPlayRateBGM(1);
}
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
}
}
} }
private async changeGameState(state: GameState) { private async changeGameState(state: GameState) {
@ -237,7 +217,7 @@ export class GameManager extends Singleton<GameManager>() {
if (playStartSound) AudioManager.playSfx(this._startSound); if (playStartSound) AudioManager.playSfx(this._startSound);
this.setCurrentBallInGame(1); this.setCurrentBallInGame(1);
const ball = BallFactory.instance.create(this._ballHolder); const ball = BallFactory.instance.create(this._ballHolder);
ball.init(this._boostersActive.length > 0); ball.init(this._activeBoosters.size > 0);
ball.node.setRotation(Quat.IDENTITY); ball.node.setRotation(Quat.IDENTITY);
ball.node.setPosition(this._ballSpawnPosition); ball.node.setPosition(this._ballSpawnPosition);
if (!throwBall) return ball; if (!throwBall) return ball;
@ -255,7 +235,7 @@ export class GameManager extends Singleton<GameManager>() {
if (this._currentBallInGame <= 0) { if (this._currentBallInGame <= 0) {
EventManger.instance.emit(GameEvent.BallOut, null); EventManger.instance.emit(GameEvent.BallOut, null);
AudioManager.playSfx(this._ballOutSound); AudioManager.playSfx(this._ballOutSound);
this.DisableAllBooster(); this.cleanBooster();
await Utils.delay(TimeConfig.DelayPLay); await Utils.delay(TimeConfig.DelayPLay);
this.spawnBall(true); this.spawnBall(true);
} }
@ -303,7 +283,7 @@ export class GameManager extends Singleton<GameManager>() {
public async gameOver() { public async gameOver() {
BallFactory.instance.releaseAll(); BallFactory.instance.releaseAll();
this.DisableAllBooster(); this.cleanBooster();
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 });
BEConnector.gameScore = this.score; BEConnector.gameScore = this.score;
@ -344,23 +324,46 @@ export class GameManager extends Singleton<GameManager>() {
this.spawnBall(true); this.spawnBall(true);
} }
private DisableAllBooster() { public addBooster(booster: BoosterBase) {
for (let i = 0; i < this._boostersActive.length; i++) { let activeBooster = this._activeBoosters.get(booster.type);
const booster = this._boostersActive[i]; if (activeBooster) {
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type); booster.dispose();
activeBooster.resetTime();
return;
} else {
activeBooster = booster;
} }
this._boostersActive = []; activeBooster.collect(this.node);
AudioManager.setPlayRateBGM(1); console.log(booster.displayName + ' active');
this._activeBoosters.set(booster.type, booster);
EventManger.instance.emit(GameEvent.BoosterActive, [booster.type, booster.displayName]);
} }
public async ActiveBooster(type: BoosterType, time: number, displayName: string) { private cleanBooster() {
//check booster already active this._activeBoosters.forEach((booster) => {
for (let i = 0; i < this._boostersActive.length; i++) { booster.end();
const booster = this._boostersActive[i]; EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
if (booster.type == type) return; });
this._activeBoosters.clear();
}
private runBooster(dt: number) {
if (this._activeBoosters.size > 0) {
const boosterToRemove: BoosterBase[] = [];
this._activeBoosters.forEach((booster) => {
booster.tick(dt);
if (!booster.active) {
boosterToRemove.push(booster);
}
});
console.log(boosterToRemove.length);
boosterToRemove.forEach((booster) => {
booster.end();
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
this._activeBoosters.delete(booster.type);
console.log(booster.displayName + ' inactive');
});
} }
this._boostersActive.push(new Booster(type, time));
EventManger.instance.emit(GameEvent.BoosterActive, [type, displayName]);
AudioManager.setPlayRateBGM(1.25);
} }
} }

View File

@ -1,18 +1,4 @@
import { import { _decorator, CCString, Color, Label, Node, Sprite, SpriteFrame, Tween, tween, Vec3 } from 'cc';
_decorator,
CCString,
Color,
Component,
game,
Label,
Node,
Sprite,
SpriteFrame,
Tween,
tween,
TweenSystem,
Vec3,
} from 'cc';
import Singleton from '../Singleton'; import Singleton from '../Singleton';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ -33,21 +19,12 @@ export class StickerManager extends Singleton<StickerManager>() {
@property({ type: Sticker, visible: true }) @property({ type: Sticker, visible: true })
private _stickers: Sticker[] = []; private _stickers: Sticker[] = [];
private _showing: boolean = false;
protected start(): void { protected start(): void {
this._popup.setScale(Vec3.ZERO); this._popup.setScale(Vec3.ZERO);
this._label.string = ''; this._label.string = '';
} }
protected update(dt: number): void {
if (this._showing && game.timeScale == 0) {
TweenSystem.instance.ActionManager.update(game.deltaTime);
}
}
public Show(stickerName: string, position: Vec3 = Vec3.ZERO) { public Show(stickerName: string, position: Vec3 = Vec3.ZERO) {
this._showing = true;
let sticker = this._stickers.find((s) => s.Name == stickerName); let sticker = this._stickers.find((s) => s.Name == stickerName);
this._popup.setPosition(position); this._popup.setPosition(position);
this._popup.getComponent(Sprite).spriteFrame = sticker.SpriteFrame; this._popup.getComponent(Sprite).spriteFrame = sticker.SpriteFrame;
@ -56,12 +33,10 @@ export class StickerManager extends Singleton<StickerManager>() {
.to(0.3, { scale: Vec3.ONE }, { easing: 'backOut' }) .to(0.3, { scale: Vec3.ONE }, { easing: 'backOut' })
.delay(0.5) .delay(0.5)
.to(0.2, { scale: Vec3.ZERO }, { easing: 'backIn' }) .to(0.2, { scale: Vec3.ZERO }, { easing: 'backIn' })
.call(() => (this._showing = false))
.start(); .start();
} }
public showLabel(string: string, opts?: { color?: Color; outLineColor?: Color; position?: Vec3 }) { public showLabel(string: string, opts?: { color?: Color; outLineColor?: Color; position?: Vec3 }) {
this._showing = true;
this._label.string = string; this._label.string = string;
this._label.color = opts?.color || new Color('#FFFF00'); this._label.color = opts?.color || new Color('#FFFF00');
this._label.node.setPosition(opts?.position || Vec3.ZERO); this._label.node.setPosition(opts?.position || Vec3.ZERO);
@ -82,7 +57,6 @@ export class StickerManager extends Singleton<StickerManager>() {
easing: 'backIn', easing: 'backIn',
}, },
) )
.call(() => (this._showing = false))
.start(); .start();
} }
} }