Battles ~ Sound integration with battle (design document) - uchicago-cs/chiventure GitHub Wiki

Based on a collaboration between sound and battles group members, here are the steps needed to integrate the sound feature into battles in Chiventure using .WAV files:

move_t and battle_item_t: add a sound field that is a sound_t pointer or NULL if no sound. something like sound_t *sound_effect; the sound struct should be added to the move or item in the respective init functions using sound_t *sound_effect = sound_new(SOUND_EFFECT, "sound/[sound file name]"); and freed with free_sound(). this requires having a sound directory in battle/src that stores all of the affiliated sound files.

battle_logic: add function that plays sound if there is a sound file for a move and one for an item. They should look something like:

       sound_t *sound = move->sound_effect;
       if(!sound)
       {
           return;
       }
       sound_type_t *bgm = load_wav(sound);
       play_sound(sound, 0);
       return;
   }

for moves, and

       sound_t *sound = item->sound_effect;
       if(!sound)
       {
           return;
       }
       sound_type_t *bgm = load_wav(sound);
       play_sound(sound, 0);
       return;
   }

for items.

Further, we could do a similar thing with battle intros and endings (even conditionally based on who wins). These could be thematic music or recorded intro dialogue. Similarly, this would require adding sound fields to a battle and run sound functions for the various sounds.

Alternatively, the sound functions can be refactored into a single sound function that either calls the specific ones or that takes a sound instead of the struct in which it lives.