fertig-classic-games/src/ui/Sounds.js

149 lines
5.5 KiB
JavaScript

// Sound effect keys — must match the keys loaded in PreloadScene.
export const SFX = {
CARD_DEAL: 'sfx-card-deal',
CARD_PLACE: 'sfx-card-place',
CARD_SHOW: 'sfx-card-show',
CARD_SHUFFLE: 'sfx-card-shuffle',
COINS: 'sfx-coins',
PURCHASE: 'sfx-purchase',
CASINO_BLACKJACK: 'sfx-casino-blackjack',
CASINO_LOSE: 'sfx-casino-lose',
CASINO_WIN: 'sfx-casino-win',
CHIP_BET: 'sfx-chip-bet',
DICE_ROLL: 'sfx-dice-roll',
PENCIL_WRITE: 'sfx-pencil-write',
BINGO_BALLS: 'sfx-bingo-balls',
PIECE_CLICK: 'sfx-piece-click',
ROULETTE: 'sfx-roulette',
BATTLESHIP_HIT: 'sfx-battleship-hit',
BATTLESHIP_MISS: 'sfx-battleship-miss',
BATTLESHIP_LAUNCH: 'sfx-battleship-launch',
MASTERMIND_GLITCH_1: 'sfx-mastermind-glitch-1',
MASTERMIND_GLITCH_2: 'sfx-mastermind-glitch-2',
MASTERMIND_PLACE: 'sfx-mastermind-place',
MASTERMIND_GRANTED: 'sfx-mastermind-access-granted',
MASTERMIND_DENIED: 'sfx-mastermind-access-denied',
MASTERMIND_COLOR: 'sfx-mastermind-color',
MASTERMIND_MATCH: 'sfx-mastermind-match',
MASTERMIND_CALCULATE: 'sfx-mastermind-calculate',
VICTORY_SHORT: 'sfx-victory-short',
SCIFI_LAUNCH: 'sfx-scifi-launch',
SCIFI_EXPLODE: 'sfx-scifi-explode',
SCIFI_RISER: 'sfx-scifi-riser',
SCIFI_REVEAL: 'sfx-scifi-reveal',
SCIFI_WOOSH: 'sfx-scifi-woosh',
SCIFI_PLINK: 'sfx-scifi-plink',
SCIFI_PLONK: 'sfx-scifi-plonk',
SWORD_HIT: 'sfx-sword-hit',
SWORD_SLICE: 'sfx-sword-slice',
MONOPOLY_PURCHASE: 'sfx-monopoly-purchase',
MONOPOLY_EXPENSE: 'sfx-monopoly-expense',
MONOPAY: 'sfx-monopoly-pay',
MONOPOLY_PAID: 'sfx-monopoly-paid',
EIGHTBIT_SELECT: 'sfx-8bit-select',
EIGHTBIT_ACTIVATE: 'sfx-8bit-activate',
EIGHTBIT_ACTION: 'sfx-8bit-action',
EIGHTBIT_MOVE: 'sfx-8bit-move',
SQUISH: 'sfx-squish',
SQUASH: 'sfx-squash',
WOOSH: 'sfx-woosh',
JELLO_MONSTERS: 'sfx-jello-monsters',
COUNTDOWN_TICK: 'sfx-countdown-tick',
COUNTDOWN_GO: 'sfx-countdown-go',
UI_PICK: 'sfx-ui-pick',
UI_ACTIVATE: 'sfx-ui-activate',
UI_FLIP: 'sfx-ui-flip',
UI_PLACE: 'sfx-ui-place',
UI_CHIME: 'sfx-ui-chime',
GEM_MATCH_1: 'sfx-gem-match-1',
GEM_MATCH_2: 'sfx-gem-match-2',
GEM_MATCH_4: 'sfx-gem-match-4',
GEM_MATCH_5: 'sfx-gem-match-5',
GEM_CHAIN: 'sfx-gem-chain',
GEM_DROP: 'sfx-gem-drop',
GEM_BIG_DROP: 'sfx-gem-big-drop',
FIREWORK: 'sfx-firework',
SW_LIGHT_1: 'sfx-sw-light-1',
SW_LIGHT_2: 'sfx-sw-light-2',
SW_LIGHT_3: 'sfx-sw-light-3',
SW_DARK_1: 'sfx-sw-dark-1',
SW_DARK_2: 'sfx-sw-dark-2',
SW_DARK_3: 'sfx-sw-dark-3',
};
export function playSound(scene, key) {
try { scene.sound.play(key); } catch (_) {}
}
// Picks and plays one of several keys at random (e.g. variations of the same cue).
export function playRandomSound(scene, keys) {
playSound(scene, keys[Math.floor(Math.random() * keys.length)]);
}
const SW_LIGHT_KEYS = [SFX.SW_LIGHT_1, SFX.SW_LIGHT_2, SFX.SW_LIGHT_3];
const SW_DARK_KEYS = [SFX.SW_DARK_1, SFX.SW_DARK_2, SFX.SW_DARK_3];
// SWDBG: Force track shifting toward the Rebel (light) or Empire (dark) side.
export function playForceMove(scene, towardLight) {
playRandomSound(scene, towardLight ? SW_LIGHT_KEYS : SW_DARK_KEYS);
}
// chip-bet is limited to one simultaneous instance.
let _chipBetSound = null;
export function playChipBet(scene) {
if (_chipBetSound?.isPlaying) return;
_chipBetSound?.destroy();
_chipBetSound = scene.sound.add(SFX.CHIP_BET);
_chipBetSound.play();
}
// Each plays at most one simultaneous instance (tie battles would otherwise double up).
let _scifiLaunchSound = null;
export function playScifiLaunch(scene) {
if (_scifiLaunchSound?.isPlaying) return;
_scifiLaunchSound?.destroy();
_scifiLaunchSound = scene.sound.add(SFX.SCIFI_LAUNCH);
_scifiLaunchSound.play();
}
let _scifiExplodeSound = null;
export function playScifiExplode(scene) {
if (_scifiExplodeSound?.isPlaying) return;
_scifiExplodeSound?.destroy();
_scifiExplodeSound = scene.sound.add(SFX.SCIFI_EXPLODE);
_scifiExplodeSound.play();
}
let _scifiRiserSound = null;
export function playScifiRiser(scene) {
if (_scifiRiserSound?.isPlaying) return;
_scifiRiserSound?.destroy();
_scifiRiserSound = scene.sound.add(SFX.SCIFI_RISER);
_scifiRiserSound.play();
}
let _scifiRevealSound = null;
export function playScifiReveal(scene) {
if (_scifiRevealSound?.isPlaying) return;
_scifiRevealSound?.destroy();
_scifiRevealSound = scene.sound.add(SFX.SCIFI_REVEAL);
_scifiRevealSound.play();
}
let _scifiWooshSound = null;
export function playScifiWoosh(scene) {
if (_scifiWooshSound?.isPlaying) return;
_scifiWooshSound?.destroy();
_scifiWooshSound = scene.sound.add(SFX.SCIFI_WOOSH);
_scifiWooshSound.play();
}
// Dot Link: plink/plonk with adjustable rate — even colour index → plink, odd → plonk
export function playDotLinkSound(scene, colorIdx, pathLength) {
const soundKey = colorIdx % 2 === 0 ? SFX.SCIFI_PLINK : SFX.SCIFI_PLONK;
const rate = 1 + (pathLength - 1) * 0.5;
const sound = scene.sound.add(soundKey);
sound.setRate(rate);
sound.play();
}