Play multiple audio files
This commit is contained in:
parent
a35cb8d2a6
commit
403051e540
BIN
Data/Audio/terry_hit.ogg
(Stored with Git LFS)
Normal file
BIN
Data/Audio/terry_hit.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -427,7 +427,8 @@ void TELY_DLL_Init(void *user_data)
|
|||||||
game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size);
|
game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size);
|
||||||
game->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size);
|
game->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size);
|
||||||
game->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size);
|
game->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size);
|
||||||
game->test_audio = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa"));
|
game->audio[FP_GameAudio_TestAudio] = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa"));
|
||||||
|
game->audio[FP_GameAudio_TerryHit] = platform->func_load_audio(assets, DQN_STRING8("Terry Hit"), DQN_STRING8("Data/Audio/terry_hit.ogg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 dir_vector)
|
void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_GameEntity *entity, Dqn_V2 dir_vector)
|
||||||
@ -562,6 +563,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_PlatformInput *input, FP_Ga
|
|||||||
if (!entity->attack_processed && game->clock_ms >= midpoint_clock_ms) {
|
if (!entity->attack_processed && game->clock_ms >= midpoint_clock_ms) {
|
||||||
entity->attack_box_size = entity->local_hit_box_size;
|
entity->attack_box_size = entity->local_hit_box_size;
|
||||||
|
|
||||||
|
FP_EnqueueSound(game, game->audio[FP_GameAudio_TerryHit], 1.0f);
|
||||||
// NOTE: Position the attack box
|
// NOTE: Position the attack box
|
||||||
switch (entity->direction) {
|
switch (entity->direction) {
|
||||||
case FP_GameDirection_Left: {
|
case FP_GameDirection_Left: {
|
||||||
@ -1341,7 +1343,6 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Dqn_Profiler_EndZone(update_zone);
|
Dqn_Profiler_EndZone(update_zone);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
|
void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
|
||||||
@ -1574,10 +1575,23 @@ void TELY_DLL_FrameUpdate(void *user_data)
|
|||||||
// =============================================================================================
|
// =============================================================================================
|
||||||
|
|
||||||
TELY_Audio *audio = &platform->audio;
|
TELY_Audio *audio = &platform->audio;
|
||||||
if (audio->playback_size == 0) {
|
|
||||||
TELY_Audio_Play(audio, game->test_audio, 1.f /*volume*/);
|
// NOTE: Process the sound command queue
|
||||||
|
for (uint32_t i = 0; i < game->sound_command_count; i++)
|
||||||
|
{
|
||||||
|
FP_SoundCommand *sound_command = &game->sound_commands[i];
|
||||||
|
TELY_Audio_Play(audio, sound_command->audio_handle, sound_command->volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: Clear the sound command queue for the next frame
|
||||||
|
game->sound_command_count = 0;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (audio->playback_size == 0) {
|
||||||
|
TELY_Audio_Play(audio, game->audio[FP_GameAudio_TestAudio], 1.f /*volume*/);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// =============================================================================================
|
// =============================================================================================
|
||||||
|
|
||||||
if (TELY_Platform_InputKeyWasDown(input->mouse_left) && TELY_Platform_InputKeyIsDown(input->mouse_left)) {
|
if (TELY_Platform_InputKeyWasDown(input->mouse_left) && TELY_Platform_InputKeyIsDown(input->mouse_left)) {
|
||||||
@ -1693,5 +1707,5 @@ void TELY_DLL_FrameUpdate(void *user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TELY_RFui_Flush(rfui, renderer, input, assets);
|
TELY_RFui_Flush(rfui, renderer, input, assets);
|
||||||
//TELY_Audio_MixPlaybackSamples(audio, assets);
|
TELY_Audio_MixPlaybackSamples(audio, assets);
|
||||||
}
|
}
|
||||||
|
@ -706,3 +706,10 @@ FP_GameFindClosestEntityResult FP_Game_FindClosestEntityWithType(FP_Game *game,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void FP_EnqueueSound(FP_Game *game, TELY_AssetAudioHandle audio_handle, Dqn_f32 volume)
|
||||||
|
{
|
||||||
|
DQN_ASSERT(game->sound_command_count < MAX_SOUNDS);
|
||||||
|
FP_SoundCommand *sound_command = &game->sound_commands[game->sound_command_count++];
|
||||||
|
sound_command->audio_handle = audio_handle;
|
||||||
|
sound_command->volume = volume;
|
||||||
|
}
|
||||||
|
@ -197,6 +197,20 @@ struct FP_GameCamera
|
|||||||
Dqn_V2 scale;
|
Dqn_V2 scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum FP_GameAudio
|
||||||
|
{
|
||||||
|
FP_GameAudio_TestAudio,
|
||||||
|
FP_GameAudio_TerryHit,
|
||||||
|
FP_GameAudio_Count,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FP_SoundCommand
|
||||||
|
{
|
||||||
|
TELY_AssetAudioHandle audio_handle;
|
||||||
|
float volume;
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t MAX_SOUNDS = 128;
|
||||||
struct FP_Game
|
struct FP_Game
|
||||||
{
|
{
|
||||||
Dqn_f32 delta_s_accumulator;
|
Dqn_f32 delta_s_accumulator;
|
||||||
@ -205,7 +219,11 @@ struct FP_Game
|
|||||||
TELY_AssetFontHandle inter_regular_font;
|
TELY_AssetFontHandle inter_regular_font;
|
||||||
TELY_AssetFontHandle inter_italic_font;
|
TELY_AssetFontHandle inter_italic_font;
|
||||||
TELY_AssetFontHandle jetbrains_mono_font;
|
TELY_AssetFontHandle jetbrains_mono_font;
|
||||||
TELY_AssetAudioHandle test_audio;
|
TELY_AssetAudioHandle audio[FP_GameAudio_Count];
|
||||||
|
|
||||||
|
FP_SoundCommand sound_commands[MAX_SOUNDS];
|
||||||
|
uint32_t sound_command_count;
|
||||||
|
|
||||||
Dqn_Slice<TELY_AssetSpriteAnimation> hero_sprite_anims;
|
Dqn_Slice<TELY_AssetSpriteAnimation> hero_sprite_anims;
|
||||||
TELY_AssetSpriteSheet hero_sprite_sheet;
|
TELY_AssetSpriteSheet hero_sprite_sheet;
|
||||||
Dqn_FArray<FP_GameEntityHandle, 8> parent_entity_stack;
|
Dqn_FArray<FP_GameEntityHandle, 8> parent_entity_stack;
|
||||||
|
Loading…
Reference in New Issue
Block a user