fix: score not update when game over on cheese mode

main
tiendat3699 2024-04-25 00:27:59 +07:00
parent 72cd72724e
commit fdcac05655
8 changed files with 1795 additions and 1741 deletions

View File

@ -8,6 +8,7 @@
],
"subMetas": {},
"userData": {
"syncNodeName": "CumulativeBooster"
"syncNodeName": "CumulativeBooster",
"persistent": false
}
}

File diff suppressed because it is too large Load Diff

View File

@ -89,6 +89,7 @@ export class CumulativeBar extends Component {
private _goal = false;
private _timer = 0;
private _multiplier = 1;
private _comboComplete = false;
private _currentValuePosition = new Vec3();
private _center = new Vec3();
@ -164,10 +165,10 @@ export class CumulativeBar extends Component {
break;
case ScoreType.Goal:
if (this._currentValue == 0) {
SoundManager.instance.playSfx(this._goalSound, 2);
SoundManager.instance.playSfx(this._goalSound, 3);
return;
}
SoundManager.instance.playSfx(this._cheeseModeGoalSound, 2);
SoundManager.instance.playSfx(this._cheeseModeGoalSound, 3);
this._multiplier = 0;
this._goal = true;
let items = Math.ceil(this._currentValue / 10);
@ -182,8 +183,21 @@ export class CumulativeBar extends Component {
private async playCollectEffect(items: number, score: number) {
const time = 0.04;
const offset = new Vec3();
this._comboComplete = false;
GameManager.instance.addScoreWithWaiting(
Math.round(score),
ScoreType.Combo,
this.node.getWorldPosition(),
() => this._comboComplete,
{
scaleMin: 2,
scaleMax: 4,
duration: 0.8,
},
);
for (let i = 0; i < items; i++) {
while (items > 0) {
items--;
const obj = this._starPool.get(this._scoreUI);
Vec3.random(offset, 30);
offset.y = 0;
@ -203,14 +217,10 @@ export class CumulativeBar extends Component {
.start();
await Utilities.delay(time);
}
await Utilities.waitUntil(() => this._starPool.countActive == 0);
await Utilities.waitUntil(() => this._starPool.countActive == 0, 0.1);
this._comboComplete = true;
this._soundFx.playSound();
GameManager.instance.addScore(Math.round(score), ScoreType.Combo, this.node.getWorldPosition(), {
scaleMin: 2,
scaleMax: 4,
duration: 1,
});
await Utilities.delay(1);
await Utilities.delay(0.8);
this.calcReward(score);
}
@ -227,7 +237,7 @@ export class CumulativeBar extends Component {
const fx = selectReward.pool.get(ParticleSystem, GameManager.instance.topContainer);
fx.node.setWorldPosition(this.node.worldPosition);
SoundManager.instance.playSfx(selectReward.sound);
await Utilities.waitUntil(() => fx.isStopped);
await Utilities.waitUntil(() => fx.isStopped, 0.1);
selectReward.pool.release(fx);
}
}

View File

@ -11,6 +11,7 @@ import {
EPhysics2DDrawFlags,
PhysicsSystem2D,
SpriteFrame,
Color,
} from 'cc';
import ObjectPool from '../Pool/ObjectPool';
import { Ball } from '../GamePlay/Ball';
@ -25,6 +26,7 @@ import TimeConfig from '../Enum/TimeConfig';
import BEConnector from '../API/BEConnector';
import BoosterType from '../Enum/BoosterType';
import Singleton from '../Singleton';
import { StickerManager } from './StickerManager';
const { ccclass, property } = _decorator;
window.addEventListener('message', (data) => {
@ -92,6 +94,11 @@ export class GameManager extends Singleton<GameManager>() {
private _isMultiBall = false;
private _warningTime = false;
private _currentBallInGame = 0;
private _isWaitingUpdateScore = false;
public get isWaitingUpdateScore() {
return this._isWaitingUpdateScore;
}
public get topContainer() {
return this._topContainer;
@ -123,7 +130,6 @@ export class GameManager extends Singleton<GameManager>() {
protected update(dt: number): void {
if (this._gameState != GameState.Playing) return;
for (let i = 0; i < this._boostersActive.length; i++) {
const booster = this._boostersActive[i];
booster.runningTime += dt;
@ -167,16 +173,37 @@ export class GameManager extends Singleton<GameManager>() {
score: number,
type: ScoreType,
position: Vec3,
opts?: { scaleMin?: number; scaleMax?: number; duration?: number },
) {
this._score += score;
const floatingScore = this._FloatingScorePool.get(FloatingText, this._topContainer);
floatingScore.show(
`+${score}`,
position,
score >= 100 ? opts?.scaleMax || 1 : opts?.scaleMin || 1,
opts?.duration || 1,
);
EventManger.instance.emit(GameEvent.Score, [this._score, score, type, position]);
}
public async addScoreWithWaiting(
score: number,
type: ScoreType,
position: Vec3,
predicate: () => boolean,
opts: { scaleMin: number; scaleMax: number; duration: number },
) {
this._isWaitingUpdateScore = true;
await Utilities.waitUntil(predicate);
this._score += score;
const floatingScore = this._FloatingScorePool.get(FloatingText, this._topContainer);
floatingScore.show(`+${score}`, position, score >= 100 ? opts.scaleMax : opts.scaleMin, opts.duration);
EventManger.instance.emit(GameEvent.Score, [this._score, score, type, position]);
this._isWaitingUpdateScore = false;
}
private async countTime() {
while (this.gameState == GameState.Playing) {
while (this._gameState == GameState.Playing) {
this._timer--;
if (this._timer <= 0) {
this._timer = 0;
@ -274,10 +301,11 @@ export class GameManager extends Singleton<GameManager>() {
EventManger.instance.emit(GameEvent.TimeUpdate, this._timer);
}
public gameOver() {
public async gameOver() {
this._ballPool.releaseAll();
this.DisableAllBooster();
SoundManager.instance.playBGM(this._gameOverMusic);
StickerManager.instance.showLabel('TIME UP!!!', { color: new Color('#ed3a18'), outLineColor: Color.WHITE });
BEConnector.instance.gameScore = this.score;
if (this.isReplayed) {
this.changeGameState(GameState.End);

View File

@ -1,4 +1,17 @@
import { _decorator, CCString, Component, Node, Sprite, SpriteFrame, tween, Vec3 } from 'cc';
import {
_decorator,
CCString,
Color,
Component,
Label,
LabelOutline,
Node,
Sprite,
SpriteFrame,
Tween,
tween,
Vec3,
} from 'cc';
import Singleton from '../Singleton';
const { ccclass, property } = _decorator;
@ -14,11 +27,14 @@ class Sticker {
export class StickerManager extends Singleton<StickerManager>() {
@property({ type: Node, visible: true })
private _popup: Node;
@property({ type: Label, visible: true })
private _label: Label;
@property({ type: Sticker, visible: true })
private _stickers: Sticker[] = [];
protected start(): void {
this._popup.setScale(Vec3.ZERO);
this._label.string = '';
}
public Show(stickerName: string, position: Vec3 = Vec3.ZERO) {
@ -32,4 +48,28 @@ export class StickerManager extends Singleton<StickerManager>() {
.to(0.2, { scale: Vec3.ZERO }, { easing: 'backIn' })
.start();
}
public showLabel(string: string, opts?: { color?: Color; outLineColor?: Color; position?: Vec3 }) {
this._label.string = string;
this._label.color = opts?.color || new Color('#FFFF00');
this._label.node.setPosition(opts?.position || Vec3.ZERO);
this._label.getComponent(LabelOutline).color = opts?.outLineColor || new Color('#FF6600');
Tween.stopAllByTarget(this._label.node);
tween(this._label.node)
.set({ scale: Vec3.ZERO })
.to(0.2, { scale: Vec3.ONE }, { easing: 'backOut' })
.delay(1)
.to(
0.1,
{ scale: Vec3.ZERO },
{
onComplete: () => {
this._label.string = '';
},
easing: 'backIn',
},
)
.start();
}
}

View File

@ -147,31 +147,29 @@ export class GameOverPanel extends Component {
)
.call(() => this._pool.release(obj))
.call(async () => {
if (i == items - 1) {
this.yourScore.string = totalScore.toString();
Tween.stopAllByTarget(this.yourScore.node);
tween(this.yourScore.node)
.set({ scale: Vec3.ONE })
.to(0.3, { scale: new Vec3(1.8, 1.8) }, { easing: 'backIn' })
.to(0.3, { scale: new Vec3(1, 1) }, { easing: 'backOut' })
.start();
if (this._end) {
await Utilities.delay(1);
BEConnector.instance.postScoreToServer();
}
} else {
Tween.stopAllByTarget(this.yourScore.node);
this.yourScore.string = score.toString();
tween(this.yourScore.node)
.to(duration / 6, { scale: new Vec3(1.3, 1.3) })
.to(duration / 6, { scale: new Vec3(1, 1) })
.start();
}
Tween.stopAllByTarget(this.yourScore.node);
this.yourScore.string = score.toString();
tween(this.yourScore.node)
.to(duration / 6, { scale: new Vec3(1.3, 1.3) })
.to(duration / 6, { scale: new Vec3(1, 1) })
.start();
})
.start();
SoundManager.instance.playSfx(this._soundCollectCoinFx);
await Utilities.delay(duration / 3);
}
await Utilities.waitUntil(() => this._pool.countActive == 0, 0.1);
this.yourScore.string = totalScore.toString();
Tween.stopAllByTarget(this.yourScore.node);
tween(this.yourScore.node)
.set({ scale: Vec3.ONE })
.to(0.3, { scale: new Vec3(1.8, 1.8) }, { easing: 'backIn' })
.to(0.3, { scale: new Vec3(1, 1) }, { easing: 'backOut' })
.start();
if (!this._end) return;
await Utilities.delay(1);
BEConnector.instance.postScoreToServer();
}
}
}

View File

@ -80,8 +80,8 @@ export class TutorialController extends Component {
tween(this._tapL)
.call(() => this._tapLEffect.clear())
.by(0.5, { position: new Vec3(0, 50), scale: new Vec3(-0.1, -0.1) }, { easing: 'quintOut' })
.by(0.5, { position: new Vec3(0, -50), scale: new Vec3(0.1, 0.1) }, { easing: 'sineOut' })
.to(0.5, { position: new Vec3(-470, -500), scale: new Vec3(0.9, 0.9) }, { easing: 'quintOut' })
.to(0.5, { position: new Vec3(-470, -550), scale: Vec3.ONE }, { easing: 'sineOut' })
.call(() => this._tapLEffect.play())
.union()
.repeatForever()
@ -89,8 +89,8 @@ export class TutorialController extends Component {
await Utilities.delay(0.5);
tween(this._tapR)
.call(() => this._tapREffect.clear())
.by(0.5, { position: new Vec3(0, 50), scale: new Vec3(-0.1, -0.1) }, { easing: 'quintOut' })
.by(0.5, { position: new Vec3(0, -50), scale: new Vec3(0.1, 0.1) }, { easing: 'sineOut' })
.to(0.5, { position: new Vec3(470, -500), scale: new Vec3(0.9, 0.9) }, { easing: 'quintOut' })
.to(0.5, { position: new Vec3(470, -550), scale: Vec3.ONE }, { easing: 'sineOut' })
.call(() => this._tapREffect.play())
.union()
.repeatForever()
@ -103,6 +103,8 @@ export class TutorialController extends Component {
Tween.stopAllByTarget(this._tapR);
this._timer = 0;
this._showed = false;
this._tapLEffect.stop();
this._tapREffect.stop();
this._tapL.active = false;
this._tapR.active = false;
}

View File

@ -15,8 +15,6 @@ export class UIController extends Component {
private _scoreLabel: Label;
@property({ type: Label, visible: true })
private _ticketLabel: Label;
@property({ type: Label, visible: true })
private _eventLabel: Label;
@property({ type: ParticleSystem, visible: true })
private _buffFx: ParticleSystem;
@ -35,7 +33,6 @@ export class UIController extends Component {
EventManger.instance.on(GameEvent.MultiBall, this.onMultiBall, this);
EventManger.instance.on(GameEvent.BoosterActive, this.onBoosterActive, this);
EventManger.instance.on(GameEvent.BoosterDisable, this.onBoosterDisable, this);
this._eventLabel.string = '';
}
private async onScore(score: number, points: number, type: ScoreType) {
@ -49,30 +46,6 @@ export class UIController extends Component {
StickerManager.instance.Show('BallOut');
}
private showEventLabel(string: string, color?: Color, outLineColor?: Color) {
this._eventLabel.string = string;
this._eventLabel.color = color || new Color('#FFFF00');
this._eventLabel.getComponent(LabelOutline).color = outLineColor || new Color('#FF6600');
Tween.stopAllByTarget(this._eventLabel.node);
tween(this._eventLabel.node)
.set({ scale: Vec3.ZERO })
.to(0.2, { scale: Vec3.ONE }, { easing: 'backOut' })
.delay(1)
.to(
0.1,
{ scale: Vec3.ZERO },
{
onComplete: () => {
this._eventLabel.string = '';
},
easing: 'backIn',
},
)
.start();
}
private async onGameStateChange(state: GameState) {
switch (state) {
case GameState.Init:
@ -90,14 +63,13 @@ export class UIController extends Component {
break;
case GameState.GameOver:
this.showEventLabel('TIME UP!!!', new Color('#ed3a18'), Color.WHITE);
await Utilities.delay(1.2);
this._buffFx.stop();
await Utilities.waitUntil(() => !GameManager.instance.isWaitingUpdateScore);
await Utilities.delay(2);
this._overPanel.active = true;
break;
case GameState.End:
this.showEventLabel('TIME UP!!!', new Color('#ed3a18'), Color.WHITE);
await Utilities.delay(1.2);
await Utilities.delay(2);
this._overPanel.active = true;
break;
case GameState.Relive:
@ -110,13 +82,16 @@ export class UIController extends Component {
private onMultiBall(active: boolean) {
if (active) {
this.showEventLabel('MULTI BALL!!!');
StickerManager.instance.showLabel('MULTI BALL!!!');
}
}
public onBoosterActive() {
this._buffFx.play();
this.showEventLabel('CHEESE!!!', new Color('#ffb517'), new Color('#ec830a'));
StickerManager.instance.showLabel('CHEESE!!!', {
color: new Color('#ffb517'),
outLineColor: new Color('#ec830a'),
});
}
public onBoosterDisable() {