react-native-games
Version:
Free games for your react native projects.
1 lines • 3.05 kB
JavaScript
;import * as Speech from 'expo-speech';let lastSpeechTime = 0;const SPEECH_THROTTLE_MS = 100;let isSpeaking = false;export const playSound =(soundConfig,soundEnabled)=>{if(!soundEnabled)return;const now = Date.now();if(now - lastSpeechTime < SPEECH_THROTTLE_MS){return;}if(isSpeaking){return;}lastSpeechTime = now;isSpeaking = true;Speech.speak(soundConfig.text,{pitch:soundConfig.pitch || 1.0,rate:soundConfig.rate || 1.5,language:soundConfig.language || 'en',onDone:()=>{isSpeaking = false;},onStopped:()=>{isSpeaking = false;},onError:()=>{isSpeaking = false;}});};export const stopAllSounds =()=>{Speech.stop();isSpeaking = false;lastSpeechTime = 0;};export const isSpeechAvailable = async()=>{try{return await Speech.isSpeakingAsync();}catch{return false;}};export const GAME_SOUNDS ={POP:{text:'Pop!',pitch:1.6,rate:2.2},SWOOSH:{text:'Swoosh!',pitch:1.5,rate:2.5},BOOM:{text:'Boom!',pitch:0.8,rate:1.5},WHOOSH:{text:'Whoosh',pitch:0.7,rate:1.8},GAME_START:{text:'Game started!',pitch:1.1,rate:0.9},GAME_OVER:{text:'Game over!',pitch:0.9,rate:0.8},TIME_UP:{text:'Time up! Game over!',pitch:0.9,rate:0.8},WELL_DONE:{text:'Well done!',pitch:1.2,rate:1.0},CONGRATULATIONS:{text:'Congratulations!',pitch:1.1,rate:0.9},BUBBLE_POPPER:{START:{text:'Bubble Popper started!',pitch:1.1,rate:0.9},COMPLETE:{text:'All bubbles popped! Well done!',pitch:1.2,rate:1.0},POP:{text:'Pop!',pitch:1.6,rate:2.2}},WHACK_A_MOLE:{HIT:{text:'Pop!',pitch:1.8,rate:2.0},MISS:{text:'Whoosh',pitch:0.7,rate:1.8}},BALLOON_BLASTER:{POP:{text:'Pop!',pitch:1.5,rate:2.5},BOMB:{text:'Boom!',pitch:0.8,rate:1.5},BONUS:{text:'bonus life!',pitch:1.8,rate:2.0}},FRUIT_NINJA:{SLICE:{text:'Swoosh!',pitch:1.5,rate:2.5},BOMB:{text:'Boom!',pitch:0.8,rate:1.5},BONUS:{text:'bonus life!',pitch:1.8,rate:2.0}},MAZE_RUNNER:{START:{text:'Maze started! Navigate to the exit!',pitch:1.0,rate:0.9},COMPLETE:{text:'Congratulations! Maze completed!',pitch:1.1,rate:0.9},STOP:{text:'Maze stopped!',pitch:0.9,rate:0.8}},SPACE_FIGHTER:{START:{text:'Mission started! Navigate through the asteroid field!',pitch:1.0,rate:0.9},SUCCESS:{text:'Nice!',pitch:1.8,rate:2.0},COLLISION:{text:'Ouch!',pitch:0.8,rate:1.5}},DINO_JUMP:{START:{text:'Run!',pitch:1.2,rate:1.5},COLLECT:{text:'Yum!',pitch:1.8,rate:2.2},HIT:{text:'Ouch!',pitch:0.8,rate:1.5},GAME_OVER:{text:'Game over!',pitch:0.9,rate:0.8}},COLORS_SORT:{START:{text:'Sort colors!',pitch:1.1,rate:1.2},MATCH:{text:'Click!',pitch:1.6,rate:2.0},COMPLETE:{text:'Perfect!',pitch:1.8,rate:1.8},MISS:{text:'Oops!',pitch:0.8,rate:1.0},GAME_OVER:{text:'Game over!',pitch:0.9,rate:0.8}},FRUIT_MERGER:{START:{text:'Merge fruits!',pitch:1.2,rate:1.3},MERGE:{text:'Pop!',pitch:1.5,rate:1.8},DROP:{text:'Boing!',pitch:1.3,rate:1.5},COMPLETE:{text:'Amazing!',pitch:1.9,rate:1.9},GAME_OVER:{text:'Game over!',pitch:0.9,rate:0.8}},FLAPPY_BIRD:{START:{text:'Fly!',pitch:1.3,rate:1.5},FLAP:{text:'Flap!',pitch:1.8,rate:2.5},SCORE:{text:'Point!',pitch:1.6,rate:2.0},HIT:{text:'Ouch!',pitch:0.8,rate:1.2},GAME_OVER:{text:'Game over!',pitch:0.9,rate:0.8}}};