feat: set play rate sound

main
tiendat3699 2024-04-24 18:05:06 +07:00
parent 78d208a7f9
commit 72cd72724e
17 changed files with 2305 additions and 2343 deletions

View File

@ -4835,7 +4835,7 @@
"a": 255 "a": 255
}, },
"_spriteFrame": { "_spriteFrame": {
"__uuid__": "4b4ee4f5-9637-497d-ab9a-c92e1503efc4@f9941", "__uuid__": "a5d6b003-efa8-4090-8f49-66ee18b2c04a@f9941",
"__expectedType__": "cc.SpriteFrame" "__expectedType__": "cc.SpriteFrame"
}, },
"_type": 3, "_type": 3,

File diff suppressed because it is too large Load Diff

View File

@ -4941,12 +4941,12 @@
"a": 255 "a": 255
}, },
"_spriteFrame": { "_spriteFrame": {
"__uuid__": "74173c28-de7e-41b8-bd60-137c033cc275@f9941", "__uuid__": "a5d6b003-efa8-4090-8f49-66ee18b2c04a@f9941",
"__expectedType__": "cc.SpriteFrame" "__expectedType__": "cc.SpriteFrame"
}, },
"_type": 3, "_type": 3,
"_fillType": 2, "_fillType": 2,
"_sizeMode": 1, "_sizeMode": 0,
"_fillCenter": { "_fillCenter": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": 0.5, "x": 0.5,

View File

@ -164,10 +164,10 @@ export class CumulativeBar extends Component {
break; break;
case ScoreType.Goal: case ScoreType.Goal:
if (this._currentValue == 0) { if (this._currentValue == 0) {
SoundManager.instance.playSfx(this._goalSound); SoundManager.instance.playSfx(this._goalSound, 2);
return; return;
} }
SoundManager.instance.playSfx(this._cheeseModeGoalSound); SoundManager.instance.playSfx(this._cheeseModeGoalSound, 2);
this._multiplier = 0; this._multiplier = 0;
this._goal = true; this._goal = true;
let items = Math.ceil(this._currentValue / 10); let items = Math.ceil(this._currentValue / 10);

View File

@ -129,6 +129,9 @@ export class GameManager extends Singleton<GameManager>() {
booster.runningTime += dt; booster.runningTime += dt;
if (booster.runningTime >= booster.time) { if (booster.runningTime >= booster.time) {
this._boostersActive.splice(i, 1); this._boostersActive.splice(i, 1);
if (this._boostersActive.length == 0) {
SoundManager.instance.setPlayRateBGM(1);
}
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type); EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
} }
} }
@ -231,12 +234,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);
SoundManager.instance.playSfx(this._ballOutSound); SoundManager.instance.playSfx(this._ballOutSound);
for (let i = 0; i < this._boostersActive.length; i++) { this.DisableAllBooster();
const booster = this._boostersActive[i];
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
}
this._boostersActive = [];
await Utilities.delay(TimeConfig.DelayPLay); await Utilities.delay(TimeConfig.DelayPLay);
this.spawnBall(true); this.spawnBall(true);
} }
@ -278,11 +276,7 @@ export class GameManager extends Singleton<GameManager>() {
public gameOver() { public gameOver() {
this._ballPool.releaseAll(); this._ballPool.releaseAll();
for (let i = 0; i < this._boostersActive.length; i++) { this.DisableAllBooster();
const booster = this._boostersActive[i];
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
}
this._boostersActive = [];
SoundManager.instance.playBGM(this._gameOverMusic); SoundManager.instance.playBGM(this._gameOverMusic);
BEConnector.instance.gameScore = this.score; BEConnector.instance.gameScore = this.score;
if (this.isReplayed) { if (this.isReplayed) {
@ -320,6 +314,15 @@ export class GameManager extends Singleton<GameManager>() {
this.spawnBall(true); this.spawnBall(true);
} }
private DisableAllBooster() {
for (let i = 0; i < this._boostersActive.length; i++) {
const booster = this._boostersActive[i];
EventManger.instance.emit(GameEvent.BoosterDisable, booster.type);
}
this._boostersActive = [];
SoundManager.instance.setPlayRateBGM(1);
}
public async ActiveBooster(type: BoosterType, time: number) { public async ActiveBooster(type: BoosterType, time: number) {
//check booster already active //check booster already active
for (let i = 0; i < this._boostersActive.length; i++) { for (let i = 0; i < this._boostersActive.length; i++) {
@ -329,5 +332,6 @@ export class GameManager extends Singleton<GameManager>() {
this._boostersActive.push(new Booster(type, time)); this._boostersActive.push(new Booster(type, time));
EventManger.instance.emit(GameEvent.BoosterActive, type); EventManger.instance.emit(GameEvent.BoosterActive, type);
SoundManager.instance.playSfx(this._boosterActiveSound); SoundManager.instance.playSfx(this._boosterActiveSound);
SoundManager.instance.setPlayRateBGM(1.25);
} }
} }

View File

@ -1,5 +1,6 @@
import { _decorator, AudioClip, AudioSource, Component, Node } from 'cc'; import { _decorator, AudioClip, AudioSource, Component, Node } from 'cc';
import Singleton from '../Singleton'; import Singleton from '../Singleton';
import { Howl } from 'howler';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
class SoundSource { class SoundSource {
@ -43,7 +44,7 @@ class SoundSource {
@ccclass('SoundManager') @ccclass('SoundManager')
export class SoundManager extends Singleton<SoundManager>('SoundManager') { export class SoundManager extends Singleton<SoundManager>('SoundManager') {
private _audioSourcesSfx: { [key: string]: SoundSource } = {}; private _audioSourcesSfx: { [key: string]: SoundSource } = {};
private _audioSourceBgm: SoundSource; private _audioSourceBgm: Howl;
private _isMute = false; private _isMute = false;
@ -55,26 +56,28 @@ export class SoundManager extends Singleton<SoundManager>('SoundManager') {
public setMute(mute: boolean) { public setMute(mute: boolean) {
this._isMute = mute; this._isMute = mute;
this._audioSourceBgm.mute = this._isMute; this._audioSourceBgm.mute(this._isMute);
for (const key in this._audioSourcesSfx) { for (const key in this._audioSourcesSfx) {
this._audioSourcesSfx[key].mute = this._isMute; this._audioSourcesSfx[key].mute = this._isMute;
} }
} }
public playBGM(audio: AudioClip, volume = 1, loop = true) { public playBGM(audio: AudioClip, volume = 1, loop = true, rate = 1) {
if (!this._audioSourceBgm) { this._audioSourceBgm?.stop();
this._audioSourceBgm = new SoundSource(); this._audioSourceBgm = new globalThis.Howl({
this._audioSourceBgm.source = new AudioSource('audioSourceBgm'); src: audio.nativeUrl,
this._audioSourceBgm.source.playOnAwake = false; volume: volume,
} loop: loop,
this._audioSourceBgm.stop(); rate: rate,
this._audioSourceBgm.volume = volume; mute: this._isMute,
this._audioSourceBgm.source.clip = audio; });
this._audioSourceBgm.source.loop = loop;
this._audioSourceBgm.mute = this._isMute;
this._audioSourceBgm.play(); this._audioSourceBgm.play();
} }
public setPlayRateBGM(rate: number) {
this._audioSourceBgm.rate(rate);
}
public playSfx(audioClip: AudioClip, volume = 1, loop = false) { public playSfx(audioClip: AudioClip, volume = 1, loop = false) {
let soundSource = this._audioSourcesSfx[audioClip.uuid]; let soundSource = this._audioSourcesSfx[audioClip.uuid];

View File

@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "6ae044bb-dbd0-486b-83a1-ca4fbefbd254",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,17 @@
{
"ver": "4.0.23",
"importer": "javascript",
"imported": true,
"uuid": "8bd3776f-9ce5-4924-b348-3fbada6f0239",
"files": [
".js"
],
"subMetas": {},
"userData": {
"isPlugin": true,
"executionScope": "global",
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": true
}
}

View File

@ -1,4 +1,4 @@
import { _decorator, Component, geometry, Label, Node, Prefab, Tween, tween, Vec3 } from 'cc'; import { _decorator, AudioClip, Component, geometry, Label, Node, Prefab, Tween, tween, Vec3 } from 'cc';
import BEConnector from '../API/BEConnector'; import BEConnector from '../API/BEConnector';
import { GameManager } from '../Manager/GameManager'; import { GameManager } from '../Manager/GameManager';
import ObjectPool from '../Pool/ObjectPool'; import ObjectPool from '../Pool/ObjectPool';
@ -7,6 +7,7 @@ import { EventManger } from '../Manager/EventManger';
import GameEvent from '../Events/GameEvent'; import GameEvent from '../Events/GameEvent';
import GameState from '../Enum/GameState'; import GameState from '../Enum/GameState';
import { SequenceSound } from '../Environments/SequenceSound'; import { SequenceSound } from '../Environments/SequenceSound';
import { SoundManager } from '../Manager/SoundManager';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('GameOverPanel') @ccclass('GameOverPanel')
@ -27,8 +28,8 @@ export class GameOverPanel extends Component {
@property({ type: Prefab, visible: true }) @property({ type: Prefab, visible: true })
private _scorePrefab: Prefab; private _scorePrefab: Prefab;
@property({ type: SequenceSound, visible: true }) @property({ type: AudioClip, visible: true })
private _soundCollectCoinFx: SequenceSound; private _soundCollectCoinFx: AudioClip;
@property({ type: geometry.AnimationCurve, visible: true }) @property({ type: geometry.AnimationCurve, visible: true })
private _starSpeedCurve: geometry.AnimationCurve = new geometry.AnimationCurve(); private _starSpeedCurve: geometry.AnimationCurve = new geometry.AnimationCurve();
@ -168,7 +169,7 @@ export class GameOverPanel extends Component {
} }
}) })
.start(); .start();
this._soundCollectCoinFx.playSound(); SoundManager.instance.playSfx(this._soundCollectCoinFx);
await Utilities.delay(duration / 3); await Utilities.delay(duration / 3);
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@ -1,134 +0,0 @@
{
"ver": "1.0.25",
"importer": "image",
"imported": true,
"uuid": "74173c28-de7e-41b8-bd60-137c033cc275",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "74173c28-de7e-41b8-bd60-137c033cc275@6c48a",
"displayName": "combo_base",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "74173c28-de7e-41b8-bd60-137c033cc275",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "74173c28-de7e-41b8-bd60-137c033cc275@f9941",
"displayName": "combo_base",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 861,
"height": 374,
"rawWidth": 861,
"rawHeight": 374,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-430.5,
-187,
0,
430.5,
-187,
0,
-430.5,
187,
0,
430.5,
187,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
374,
861,
374,
0,
0,
861,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-430.5,
-187,
0
],
"maxPos": [
430.5,
187,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "74173c28-de7e-41b8-bd60-137c033cc275@6c48a",
"atlasUuid": ""
},
"ver": "1.0.11",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": true,
"hasAlpha": true,
"redirect": "74173c28-de7e-41b8-bd60-137c033cc275@f9941"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -2,7 +2,7 @@
"ver": "1.0.25", "ver": "1.0.25",
"importer": "image", "importer": "image",
"imported": true, "imported": true,
"uuid": "4b4ee4f5-9637-497d-ab9a-c92e1503efc4", "uuid": "a5d6b003-efa8-4090-8f49-66ee18b2c04a",
"files": [ "files": [
".json", ".json",
".png" ".png"
@ -10,14 +10,14 @@
"subMetas": { "subMetas": {
"6c48a": { "6c48a": {
"importer": "texture", "importer": "texture",
"uuid": "4b4ee4f5-9637-497d-ab9a-c92e1503efc4@6c48a", "uuid": "a5d6b003-efa8-4090-8f49-66ee18b2c04a@6c48a",
"displayName": "combo_bar_base", "displayName": "combo_bar_base",
"id": "6c48a", "id": "6c48a",
"name": "texture", "name": "texture",
"userData": { "userData": {
"wrapModeS": "clamp-to-edge", "wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge", "wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "4b4ee4f5-9637-497d-ab9a-c92e1503efc4", "imageUuidOrDatabaseUri": "a5d6b003-efa8-4090-8f49-66ee18b2c04a",
"isUuid": true, "isUuid": true,
"visible": false, "visible": false,
"minfilter": "linear", "minfilter": "linear",
@ -34,7 +34,7 @@
}, },
"f9941": { "f9941": {
"importer": "sprite-frame", "importer": "sprite-frame",
"uuid": "4b4ee4f5-9637-497d-ab9a-c92e1503efc4@f9941", "uuid": "a5d6b003-efa8-4090-8f49-66ee18b2c04a@f9941",
"displayName": "combo_bar_base", "displayName": "combo_bar_base",
"id": "f9941", "id": "f9941",
"name": "spriteFrame", "name": "spriteFrame",
@ -42,14 +42,14 @@
"trimType": "auto", "trimType": "auto",
"trimThreshold": 1, "trimThreshold": 1,
"rotated": false, "rotated": false,
"offsetX": 0, "offsetX": 4.5,
"offsetY": 0, "offsetY": 1.5,
"trimX": 0, "trimX": 26,
"trimY": 0, "trimY": 20,
"width": 861, "width": 861,
"height": 374, "height": 374,
"rawWidth": 861, "rawWidth": 904,
"rawHeight": 374, "rawHeight": 417,
"borderTop": 0, "borderTop": 0,
"borderBottom": 0, "borderBottom": 0,
"borderLeft": 0, "borderLeft": 0,
@ -83,24 +83,24 @@
3 3
], ],
"uv": [ "uv": [
0, 26,
374, 397,
861, 887,
374, 397,
0, 26,
0, 23,
861, 887,
0 23
], ],
"nuv": [ "nuv": [
0, 0.028761061946902654,
0, 0.05515587529976019,
1, 0.9811946902654868,
0, 0.05515587529976019,
0, 0.028761061946902654,
1, 0.9520383693045563,
1, 0.9811946902654868,
1 0.9520383693045563
], ],
"minPos": [ "minPos": [
-430.5, -430.5,
@ -114,7 +114,7 @@
] ]
}, },
"isUuid": true, "isUuid": true,
"imageUuidOrDatabaseUri": "4b4ee4f5-9637-497d-ab9a-c92e1503efc4@6c48a", "imageUuidOrDatabaseUri": "a5d6b003-efa8-4090-8f49-66ee18b2c04a@6c48a",
"atlasUuid": "" "atlasUuid": ""
}, },
"ver": "1.0.11", "ver": "1.0.11",
@ -129,6 +129,6 @@
"type": "sprite-frame", "type": "sprite-frame",
"fixAlphaTransparencyArtifacts": true, "fixAlphaTransparencyArtifacts": true,
"hasAlpha": true, "hasAlpha": true,
"redirect": "4b4ee4f5-9637-497d-ab9a-c92e1503efc4@f9941" "redirect": "a5d6b003-efa8-4090-8f49-66ee18b2c04a@f9941"
} }
} }

14
package-lock.json generated
View File

@ -6,7 +6,9 @@
"": { "": {
"name": "PinBallTCC", "name": "PinBallTCC",
"dependencies": { "dependencies": {
"crypto-es": "^2.1.0" "@types/howler": "^2.2.11",
"crypto-es": "^2.1.0",
"howler": "^2.2.4"
}, },
"devDependencies": { "devDependencies": {
"husky": "^9.0.11", "husky": "^9.0.11",
@ -14,6 +16,11 @@
"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=="
},
"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",
@ -84,6 +91,11 @@
"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,7 +5,9 @@
"version": "3.7.2" "version": "3.7.2"
}, },
"dependencies": { "dependencies": {
"crypto-es": "^2.1.0" "@types/howler": "^2.2.11",
"crypto-es": "^2.1.0",
"howler": "^2.2.4"
}, },
"devDependencies": { "devDependencies": {
"husky": "^9.0.11", "husky": "^9.0.11",