]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixed sounds
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 4 Dec 2015 01:06:19 +0000 (20:06 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 4 Dec 2015 01:06:19 +0000 (20:06 -0500)
main.cpp
src/entities.cpp
src/gameplay.cpp
src/world.cpp

index 1ce60497d466c21a3928c440350102d0e6a576bf..a273f0cd3da603323142bf94b74e2f8b84d46862 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -123,14 +123,6 @@ GLuint shaderProgram;
 
 FILE *names;
 
-/*
- *     These variables are used by SDL_mixer to create sound.
- *     horn is not currently used, although it may be set.
-*/
-
-Mix_Music *music;
-Mix_Chunk *horn;
-
 /*
  *     loops is used for texture animation. It is believed to be passed to entity
  *     draw functions, although it may be externally referenced instead.
@@ -415,18 +407,6 @@ int main(/*int argc, char *argv[]*/){
        */
        fadeIntensity = 250;
        initEverything();
-       
-       /*
-        *      Open a test background music file and sound. The background music is then played indefinitely
-        *      while the sound is never referenced again.
-        * 
-       */
-       
-       music = Mix_LoadMUS("assets/BennyHillTheme.wav");                       // as in gamedev/assets/<sound>
-       horn  = Mix_LoadWAV("assets/air-horn-club-sample_1.wav");       //
-       
-       Mix_VolumeMusic(15);            // Set the volume
-       //Mix_PlayMusic( music, -1 );   // Play music forever
 
        /*
         *      Load sprites used in the inventory menu. See src/inventory.cpp
@@ -454,9 +434,6 @@ int main(/*int argc, char *argv[]*/){
     */
     
     Mix_HaltMusic();
-    Mix_FreeMusic(music);
-    
-    Mix_FreeChunk(horn);
     
     fclose(names);
     
@@ -901,10 +878,8 @@ void logic(){
 
                                        if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
 
-                                               if(!ui::dialogBoxExists){
+                                               if(!ui::dialogBoxExists)
                                                        n->interact();
-                                                       Mix_PlayChannel( -1, horn, 0);  // Audio feedback
-                                               }
 
                                        }
                                }
index a2bff3cffe69ec33792f8c0e805753604f6a4f46..729bcdd37079bbcc2a43f0ba65e71376928afa84 100644 (file)
@@ -376,14 +376,14 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){
        
        unsigned int tempN = (getRand() % 5 + 2);
        
-       while(--tempN){
+       for(unsigned int i = 0;i < tempN;i++){
                
                /*
                 *      This is where the entities actually spawn. A new entity is created
                 *      with type NPC.
                */
                
-               currentWorld->addNPC(loc.x + (tempN - 5),100);
+               currentWorld->addNPC(loc.x + i * HLINE ,100);
                
        }
 
index f54c60704587d9077262c1ae2343bb52721a096b..b4c4b165e2526b7962fa1e17ff367b149a4e48e9 100644 (file)
@@ -71,6 +71,7 @@ void initEverything(void){
        
        test->generate(SCREEN_WIDTH*2);
        test->setBackground(BG_FOREST);
+       test->setBGM("assets/music/embark.wav");
        
        test->addHole(100,150);
        test->addLayer(400);
@@ -115,7 +116,7 @@ void initEverything(void){
         *      Spawn some entities.
        */
 
-       playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),10,test,iw);
+       playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),100,test,iw);
        playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);
        
        playerSpawnHill->addObject(SWORD_WOOD, false, "", 480,200);
index ff4c4611c95306e125e7bc2ec3ff6d8347f06484..5f8d44c37c094d7c341ee3458b69315efd6a8294 100644 (file)
@@ -65,6 +65,7 @@ void World::load(FILE *s){
 World::World(void){
        
        bgm = NULL;
+       bgmObj = NULL;
        
        /*
         *      Nullify pointers to other worlds.
@@ -286,24 +287,29 @@ void World::update(Player *p,unsigned int delta){
 
 void World::setBGM(const char *path){
        if(!bgm) delete[] bgm;
-       if(!path){
+       //if(!path){
                bgm = new char[strlen(path) + 1];
                strcpy(bgm,path);
                bgmObj = Mix_LoadMUS(bgm);
-               if(!bgmObj){
-                       std::cout<<"Failed to load song file "<<path<<": "<<Mix_GetError()<<std::endl;
-               }
-       }
+       //}else std::cout<<path;
 }
 
+static Mix_Music *bgmC;
+
 void World::bgmPlay(void){
-       Mix_VolumeMusic(15);
-       Mix_PlayMusic(bgmObj,-1);       // Loop infinitely
+       if(bgmObj && bgmC != bgmObj){
+               Mix_VolumeMusic(15);
+               Mix_PlayMusic(bgmObj,-1);       // Loop infinitely
+               bgmC = bgmObj;
+       }
 }
 
 void World::bgmStop(void){
-       Mix_FreeMusic(bgmObj);
-       bgmObj = NULL;
+       if(bgmObj){
+               if(bgmC != bgmObj){
+                       Mix_FreeMusic(bgmObj);
+               }
+       }
 }
 
 int worldShade = 0;