74 lines
2.3 KiB
C
74 lines
2.3 KiB
C
#include "sounds.h"
|
|
|
|
void soundsApplyVolume(SoundState *sounds, f32 master, f32 music, f32 sound) {
|
|
SetMasterVolume(master);
|
|
if (sounds->musicLoaded)
|
|
SetMusicVolume(sounds->music, music);
|
|
for (i32 i = 0; i < SOUND_COUNT; i++) {
|
|
if (IsSoundPlaying(sounds->sounds[i]))
|
|
SetSoundVolume(sounds->sounds[i], sound);
|
|
}
|
|
|
|
sounds->masterVolume = master;
|
|
sounds->musicVolume = music;
|
|
sounds->soundVolume = sound;
|
|
}
|
|
|
|
void soundsLoad(SoundState *sounds, SoundType type, f32 interval, const char *path) {
|
|
Sound newSound = LoadSound(path);
|
|
sounds->sounds[type] = newSound;
|
|
sounds->soundInterval[type] = interval;
|
|
}
|
|
bool soundsPlay(SoundState *sounds, SoundType type) {
|
|
f32 time = GetTime();
|
|
f32 lastPlayedTime = sounds->soundLastPlayed[type];
|
|
if (time - lastPlayedTime < sounds->soundInterval[type])
|
|
return false;
|
|
|
|
PlaySound(sounds->sounds[type]);
|
|
SetSoundVolume(sounds->sounds[type], sounds->soundVolume);
|
|
sounds->soundLastPlayed[type] = time;
|
|
return true;
|
|
}
|
|
bool soundsPosPlay(SoundState *sounds, Vector2 position, SoundType type) {
|
|
if (!CheckCollisionPointRec(position, sounds->cameraBounds))
|
|
return false;
|
|
return soundsPlay(sounds, type);
|
|
}
|
|
|
|
void soundsUnloadAll(SoundState *sounds) {
|
|
for (i32 i = 0; i < SOUND_COUNT; i++) {
|
|
UnloadSound(sounds->sounds[i]);
|
|
}
|
|
}
|
|
|
|
void soundsUpdate(SoundState *sounds, Rectangle cameraBounds) {
|
|
if (sounds->musicLoaded == true) {
|
|
UpdateMusicStream(sounds->music);
|
|
}
|
|
sounds->cameraBounds = cameraBounds;
|
|
}
|
|
void soundsLoadMusicStream(SoundState *sounds, const char *path) {
|
|
soundsUnloadMusicStream(sounds);
|
|
sounds->music = LoadMusicStream(path);
|
|
sounds->musicLoaded = true;
|
|
}
|
|
void soundsPlayMusicStream(SoundState *sounds) {
|
|
if (sounds->musicLoaded == false) return;
|
|
PlayMusicStream(sounds->music);
|
|
SetMusicVolume(sounds->music, sounds->musicVolume);
|
|
}
|
|
void soundsPauseMusicStream(SoundState *sounds) {
|
|
if (sounds->musicLoaded == false) return;
|
|
PauseMusicStream(sounds->music);
|
|
}
|
|
void soundsResumeMusicStream(SoundState *sounds) {
|
|
if (sounds->musicLoaded == false) return;
|
|
ResumeMusicStream(sounds->music);
|
|
}
|
|
void soundsUnloadMusicStream(SoundState *sounds) {
|
|
if (sounds->musicLoaded == false) return;
|
|
UnloadMusicStream(sounds->music);
|
|
sounds->musicLoaded = false;
|
|
}
|