Guest User

Untitled

a guest
Jan 12th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.68 KB | None | 0 0
  1. Mix_Music* playMusic(backgroundMusic bgmIndex)                                                                                                                                                              [80/194]
  2. {                                                                                                                                                                                                                  
  3.     std::string filename;                                                                                                                                                                                          
  4.     Mix_Music* musicFile;                                                                                                                                                                                          
  5.                                                                                                                                                                                                                    
  6.     switch(bgmIndex)                                                                                                                                                                                                
  7.     {                                                                                                                                                                                                              
  8.         case BGM_MENU_001:                                                                                                                                                                                          
  9.             musicFile = Mix_LoadMUS("./output.ogg");                                                                                                                                                                
  10.             break;                                                                                                                                                                                                  
  11.     }                                                                                                                                                                                                              
  12.                                                                                                                                                                                                                    
  13.     currentBgm = musicFile;                                                                                                                                                                                        
  14.                                                                                                                                                                                                                    
  15.     return musicFile;                                                                                                                                                                                              
  16. }                                                                                                                                                                                                                  
  17.                                                                                                                                                                                                                    
  18. void playBgm(gameState state)                                                                                                                                                                                      
  19. {                                                                                                                                                                                                                  
  20.     gameState c = state;                                                                                                                                                                                            
  21.     switch (c)                                                                                                                                                                                                      
  22.     {                                                                                                                                                                                                              
  23.         case MENU:                                                                                                                                                                                                  
  24.             playMusic(BGM_MENU_001);                                                                                                                                                                                
  25.             break;                                                                                                                                                                                                  
  26.         default:                                                                                                                                                                                                    
  27.             playMusic(BGM_MENU_001);                                                                                                                                                                                
  28.             break;                                                                                                                                                                                                  
  29.     }                                                                                                                                                                                                              
  30.                                                                                                                                                                                                                    
  31. }                                                                                                                                                                                                                  
  32.                                                                                                                                                                                                                    
  33. int gameMenu(void)                                                                                                                                                                                                  
  34. {                                                                                                                                                                                                                  
  35.     if (!Mix_PlayingMusic()) {                                                                                                                                                                                      
  36.         if (NULL == currentBgm) {                                                                                                                                                                                  
  37.             printf("Unable to load the bgm for the menu %s\n", Mix_GetError());                                                                                                                                    
  38.             return 1;                                                                                                                                                                                              
  39.         }                                                                                                                                                                                                          
  40.                                                                                                                                                                                                                    
  41.         if(Mix_OpenAudio(22050, AUDIO_U16SYS, 2, 512) == -1)                                                                                                                                                        
  42.         {                                                                                                                                                                                                          
  43.             cerr << "Unable to open audio device. Mix_GetError: " << Mix_GetError() << endl;                                                                                                                        
  44.         }                                                                                                                                                                                                          
  45.                                                                                                                                                                                                                    
  46.         if (-1 == Mix_PlayMusic(currentBgm, LOOP_SOUND)) {                                                                                                                                                          
  47.             printf("Unable to play the bgm for the menu %s\n", Mix_GetError());                                                                                                                                    
  48.         }                                                                                                                                                                                                          
  49.     }                                                                                                                                                                                                              
  50.                                                                                                                                                                                                                    
  51.     return 0;                                                                                                                                                                                                      
  52. }
Advertisement
Add Comment
Please, Sign In to add comment