Texturec *bgTex;
+ Mix_Music *bgmObj;
+ char *bgm;
+
public:
/*
void setBackground(WORLD_BG_TYPE bgt);
+ /*
+ * Start/stop background music.
+ */
+
+ void setBGM(const char *path);
+ void bgmPlay(void);
+ void bgmStop(void);
+
/*
* Looks for the furthest back layer in this world and adds a new layer of width `width` behind it.
*/
horn = Mix_LoadWAV("assets/air-horn-club-sample_1.wav"); //
Mix_VolumeMusic(15); // Set the volume
- Mix_PlayMusic( music, -1 ); // Play music forever
+ //Mix_PlayMusic( music, -1 ); // Play music forever
/*
* Load sprites used in the inventory menu. See src/inventory.cpp
static unsigned int prevTime = 0, // Used for timing operations
currentTime = 0, //
prevPrevTime= 0; //
+ World *prev;
if(!currentTime){ // Initialize currentTime if it hasn't been
currentTime=millis();
/*
* Run the logic handler if MSEC_PER_TICK milliseconds have passed.
*/
-
+
+ prev = currentWorld;
ui::handleEvents();
+
+ if(prev != currentWorld){
+ prev->bgmStop();
+ currentWorld->bgmPlay();
+ }
+
if(prevPrevTime + MSEC_PER_TICK <= currentTime){
logic();
prevPrevTime = currentTime;
playerSpawnHill=new World();
playerSpawnHill->setBackground(BG_FOREST);
+ playerSpawnHill->setBGM("assets/music/embark.wav");
/*if((load=fopen("world.dat","rb"))){
playerSpawnHill->load(load);
playerSpawnHill->npc[0]->addAIFunc(giveTestQuest,false);
+ currentWorld->bgmPlay();
atexit(destroyEverything);
}
World::World(void){
+ bgm = NULL;
+
/*
* Nullify pointers to other worlds.
*/
}
}
+void World::setBGM(const char *path){
+ if(!bgm) delete[] bgm;
+ 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;
+ }
+ }
+}
+
+void World::bgmPlay(void){
+ Mix_VolumeMusic(15);
+ Mix_PlayMusic(bgmObj,-1); // Loop infinitely
+}
+
+void World::bgmStop(void){
+ Mix_FreeMusic(bgmObj);
+ bgmObj = NULL;
+}
+
int worldShade = 0;
extern vec2 offset;