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.
*/
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
*/
Mix_HaltMusic();
- Mix_FreeMusic(music);
-
- Mix_FreeChunk(horn);
fclose(names);
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
- }
}
}
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);
}
test->generate(SCREEN_WIDTH*2);
test->setBackground(BG_FOREST);
+ test->setBGM("assets/music/embark.wav");
test->addHole(100,150);
test->addLayer(400);
* 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);
World::World(void){
bgm = NULL;
+ bgmObj = NULL;
/*
* Nullify pointers to other worlds.
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;