| 
                Last change
                  on this file since 3669 was
                  3512,
                  checked in by bensch, 21 years ago
           | 
        
        
          | 
               
orxonox/branches/soundEngine: modified, so it has some more c++ style 
 
           | 
        
        | 
            File size:
            1.4 KB
           | 
      
      
        
  | Line |   | 
|---|
| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | #include "sound_control.h" | 
|---|
| 4 |  | 
|---|
| 5 | int verbose = 3; | 
|---|
| 6 |  | 
|---|
| 7 | /**  | 
|---|
| 8 |     \brief Handles input events | 
|---|
| 9 | */  | 
|---|
| 10 | void handleKey(SDL_KeyboardEvent key) { | 
|---|
| 11 |   SoundControl* sound = SoundControl::getInstance(); | 
|---|
| 12 |  | 
|---|
| 13 |   switch(key.keysym.sym) { | 
|---|
| 14 |   case SDLK_a: | 
|---|
| 15 |     if(key.type == SDL_KEYDOWN) { | 
|---|
| 16 |       if(sound->sfx_channel1 < 0) { | 
|---|
| 17 |         sound->sfx_channel1 = 1; | 
|---|
| 18 |         sound->playWav("sound1.wav"); | 
|---|
| 19 |       } | 
|---|
| 20 |     } else { | 
|---|
| 21 |       Mix_HaltChannel(sound->sfx_channel1); | 
|---|
| 22 |       sound->sfx_channel1 = -1; | 
|---|
| 23 |     } | 
|---|
| 24 |     break; | 
|---|
| 25 |   case SDLK_s: | 
|---|
| 26 |     if(key.type == SDL_KEYDOWN) { | 
|---|
| 27 |       if(sound->sfx_channel2 < 0) { | 
|---|
| 28 |         sound->sfx_channel2 = 1; | 
|---|
| 29 |         sound->playWav("sound2.wav"); | 
|---|
| 30 |       } | 
|---|
| 31 |     } else { | 
|---|
| 32 |       Mix_HaltChannel(sound->sfx_channel2); | 
|---|
| 33 |       sound->sfx_channel2 = -1; | 
|---|
| 34 |     } | 
|---|
| 35 |     break; | 
|---|
| 36 |   case SDLK_m: | 
|---|
| 37 |     if(key.state == SDL_PRESSED) { | 
|---|
| 38 |       sound->playOgg("music.ogg"); | 
|---|
| 39 |     } | 
|---|
| 40 |     break; | 
|---|
| 41 |   case SDLK_q: | 
|---|
| 42 |     sound->finished = 1; | 
|---|
| 43 |     break; | 
|---|
| 44 |   default: | 
|---|
| 45 |     break; | 
|---|
| 46 |   } | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | int main(int argc, char* argv[]) { | 
|---|
| 50 |   SDL_Surface* screen; | 
|---|
| 51 |   SDL_Event event; | 
|---|
| 52 |   SoundControl* soundControl = SoundControl::getInstance(); | 
|---|
| 53 |  | 
|---|
| 54 |   SDL_Init(SDL_INIT_VIDEO); | 
|---|
| 55 |   screen = SDL_SetVideoMode(320, 240, 0, 0); | 
|---|
| 56 |   while(!soundControl->finished) { | 
|---|
| 57 |     while(SDL_PollEvent(&event)) { | 
|---|
| 58 |       switch(event.type) { | 
|---|
| 59 |       case SDL_QUIT: | 
|---|
| 60 |         soundControl->finished = 1; | 
|---|
| 61 |         break; | 
|---|
| 62 |       case SDL_KEYDOWN: | 
|---|
| 63 |       case SDL_KEYUP: | 
|---|
| 64 |         handleKey(event.key); | 
|---|
| 65 |         break; | 
|---|
| 66 |       default: | 
|---|
| 67 |         break; | 
|---|
| 68 |       } | 
|---|
| 69 |     } | 
|---|
| 70 |     SDL_Delay(50); | 
|---|
| 71 |   } | 
|---|
| 72 |   delete SoundControl::getInstance(); | 
|---|
| 73 |   SDL_Quit(); | 
|---|
| 74 |   return 0; | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.