Subversion Repositories Games.Chess Giants

Rev

Rev 11 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // audio.cpp
  2.  
  3. #include "common.h"
  4.  
  5.  
  6. // global variables used in this module only
  7. static int queued_sound = 0;
  8.  
  9.  
  10. void Audio_Think (void)
  11. {
  12.    // this function plays the queued sounds on the right time
  13.  
  14.    int sound_index;
  15.  
  16.    // do we have a sound to play ? if so, play it
  17.    if (queued_sound != 0)
  18.    {
  19.       // given the type of sound we want, enqueue the right one
  20.       if (queued_sound == SOUNDTYPE_CLICK)
  21.          PlaySound (L"data/sounds/click.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  22.       else if (queued_sound == SOUNDTYPE_ILLEGALMOVE)
  23.          PlaySound (L"data/sounds/illegal.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  24.       else if (queued_sound == SOUNDTYPE_VICTORY)
  25.          PlaySound (L"data/sounds/win.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  26.       else if (queued_sound == SOUNDTYPE_DEFEAT)
  27.          PlaySound (L"data/sounds/lose.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  28.       else if (queued_sound == SOUNDTYPE_CHECK)
  29.          PlaySound (L"data/sounds/check.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  30.       else if (queued_sound == SOUNDTYPE_PIECETAKEN)
  31.          PlaySound (L"data/sounds/take.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  32.       else if (queued_sound == SOUNDTYPE_MOVE)
  33.       {
  34.          sound_index = rand () % 6; // there are several movement sounds, pick one at random
  35.          if (sound_index == 0)
  36.             PlaySound (L"data/sounds/move1.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  37.          else if (sound_index == 1)
  38.             PlaySound (L"data/sounds/move2.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  39.          else if (sound_index == 2)
  40.             PlaySound (L"data/sounds/move3.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  41.          else if (sound_index == 3)
  42.             PlaySound (L"data/sounds/move4.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  43.          else if (sound_index == 4)
  44.             PlaySound (L"data/sounds/move5.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  45.          else
  46.             PlaySound (L"data/sounds/move6.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  47.       }
  48.  
  49.       queued_sound = 0; // play this sound then forget it
  50.    }
  51.  
  52.    return; // finished, audio has been handled
  53. }
  54.  
  55.  
  56. void Audio_PlaySound (int sound_type)
  57. {
  58.    // helper function to play a sound
  59.  
  60.    if (!options.want_sounds)
  61.       return; // if we want no sound, don't play anything
  62.  
  63.    queued_sound = sound_type; // enqueue the desired sound for playing
  64.    return; // finished
  65. }
  66.