From 897802f67d502c070eac0c14b43113d521a711ef Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 3 Dec 2015 20:06:19 -0500 Subject: fixed sounds --- main.cpp | 27 +-------------------------- src/entities.cpp | 4 ++-- src/gameplay.cpp | 3 ++- src/world.cpp | 24 +++++++++++++++--------- 4 files changed, 20 insertions(+), 38 deletions(-) diff --git a/main.cpp b/main.cpp index 1ce6049..a273f0c 100644 --- 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/ - 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 - } } } diff --git a/src/entities.cpp b/src/entities.cpp index a2bff3c..729bcdd 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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); } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index f54c607..b4c4b16 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -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); diff --git a/src/world.cpp b/src/world.cpp index ff4c461..5f8d44c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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 "<