Add sounds
This commit is contained in:
@@ -6,15 +6,41 @@
|
||||
#include <raylib.h>
|
||||
|
||||
typedef enum SoundType {
|
||||
SOUND_WOOD_PUNCH,
|
||||
SOUND_HURT_1,
|
||||
SOUND_HURT_2,
|
||||
SOUND_HURT_3,
|
||||
SOUNDS_ORE_PUNCH_1,
|
||||
SOUNDS_ORE_PUNCH_2,
|
||||
SOUNDS_ORE_PUNCH_3,
|
||||
SOUNDS_ORE_PUNCH_4,
|
||||
SOUNDS_ORE_PUNCH_5,
|
||||
SOUNDS_WHEAT_PUNCH_1,
|
||||
SOUNDS_WHEAT_PUNCH_2,
|
||||
SOUNDS_WHEAT_PUNCH_3,
|
||||
SOUNDS_WHEAT_PUNCH_4,
|
||||
SOUNDS_WHEAT_PUNCH_5,
|
||||
SOUNDS_WOOD_PUNCH_1,
|
||||
SOUNDS_WOOD_PUNCH_2,
|
||||
SOUNDS_WOOD_PUNCH_3,
|
||||
SOUNDS_WOOD_PUNCH_4,
|
||||
SOUNDS_WOOD_PUNCH_5,
|
||||
SOUND_COUNT
|
||||
} SoundType;
|
||||
|
||||
static SoundType getRandomSoundType(SoundType min, SoundType max) {
|
||||
BZ_ASSERT(min <= max && min >= 0 && max < SOUND_COUNT);
|
||||
return GetRandomValue(min, max);
|
||||
}
|
||||
|
||||
#define SOUND_MAX_PLAYING 16
|
||||
|
||||
typedef struct SoundState {
|
||||
Rectangle cameraBounds;
|
||||
Sound sounds[SOUND_COUNT];
|
||||
Sound playing;
|
||||
Sound playing[SOUND_MAX_PLAYING];
|
||||
// How long it needs to wait,
|
||||
// before playing the same sound
|
||||
f32 soundLastPlayed[SOUND_COUNT];
|
||||
f32 soundInterval[SOUND_COUNT];
|
||||
|
||||
bool musicLoaded;
|
||||
@@ -28,11 +54,12 @@ typedef struct SoundState {
|
||||
void soundsApplyVolume(SoundState *sounds, f32 master, f32 music, f32 sound);
|
||||
|
||||
void soundsLoad(SoundState *sounds, SoundType type, f32 interval, const char *path);
|
||||
void soundsPlay(SoundState *sounds, SoundType type);
|
||||
bool soundsPlay(SoundState *sounds, SoundType type);
|
||||
bool soundsPosPlay(SoundState *sounds, Vector2 position, SoundType type);
|
||||
|
||||
void soundsUnloadAll(SoundState *sounds);
|
||||
|
||||
void soundsUpdate(SoundState *sounds);
|
||||
void soundsUpdate(SoundState *sounds, Rectangle cameraBounds);
|
||||
|
||||
void soundsLoadMusicStream(SoundState *sounds, const char *path);
|
||||
void soundsPlayMusicStream(SoundState *sounds);
|
||||
|
||||
Reference in New Issue
Block a user