]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added support for sound
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 1 Oct 2015 13:22:42 +0000 (09:22 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 1 Oct 2015 13:22:42 +0000 (09:22 -0400)
assets/names_en-us
include/common.h
src/main.cpp

index c34e6cfe4644b25ebaf12128426eeb004af3f972..0f6195fd76e73db56eefd22708d5abdcca425baa 100644 (file)
@@ -53,6 +53,7 @@ mAndy
 mClyne
 mPingu
 mShrek
+mLogan
 fShani
 fIsidra
 fAja
index 985dddf63546230db26c2efe1f57846467ecc6fa..9f29fbb26217a19a7adfc76dd01acc9ad2575674 100644 (file)
@@ -47,4 +47,7 @@ extern unsigned int deltaTime;
 extern FILE* config;
 extern FILE* names;
 
+extern Mix_Music *music;
+extern Mix_Chunk *horn;
+
 #endif // COMMON_H
index ea579981e2f272c63ce61b5fc5e2f257c37bcbf0..37e1712f6a2be56a365d2675960b5c9b0105c023 100644 (file)
@@ -28,6 +28,9 @@ std::vector<Structures *>build;
 int mx, my;
 FILE* names;
 
+Mix_Music *music;
+Mix_Chunk *horn;
+
 extern void initEverything(void);
 
 void logic();
@@ -40,7 +43,7 @@ unsigned int millis(void){
 
 int main(int argc, char *argv[]){
        // Initialize SDL
-    if(SDL_Init(SDL_INIT_VIDEO)){
+    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){
                std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
                return -1;
        }
@@ -51,6 +54,23 @@ int main(int argc, char *argv[]){
                return -1;
        }
        atexit(IMG_Quit);
+
+        //Initialize SDL_mixer 
+       if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 ){
+               std::cout << "SDL_mixer could not initialize! SDL_mixer Error: " << Mix_GetError() << std::endl;
+       }
+       atexit(Mix_Quit);
+
+       //Load music
+       music = Mix_LoadMUS("assets/BennyHillTheme.wav");
+       horn = Mix_LoadWAV("assets/air-horn-club-sample_1.wav");
+       if( music == NULL ){
+               printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
+       }
+       Mix_PlayMusic( music, -1 );
+
+
+
        // Turn on double buffering
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     // Create the window
@@ -196,6 +216,7 @@ void logic(){
                                        if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT)){
                                                entity[i]->interact();
                                                std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
+                                               //Mix_PlayChannel( -1, horn, 0);
                                        }
                                }else entity[i]->near=false;
                        }