diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-12-03 16:30:08 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-12-03 16:30:08 -0500 |
commit | dcd2d1e9ed9df2b67a48acc442c9e816b677b208 (patch) | |
tree | bb9da022908f71323bde29ad8787adf097f3b725 /src | |
parent | 67803d1c1ef1bb96a6cdfdfecba943378e0ec5d1 (diff) |
moving music to world
Diffstat (limited to 'src')
-rw-r--r-- | src/gameplay.cpp | 2 | ||||
-rw-r--r-- | src/world.cpp | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 958356e..f54c607 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -77,6 +77,7 @@ void initEverything(void){ playerSpawnHill=new World(); playerSpawnHill->setBackground(BG_FOREST); + playerSpawnHill->setBGM("assets/music/embark.wav"); /*if((load=fopen("world.dat","rb"))){ playerSpawnHill->load(load); @@ -135,6 +136,7 @@ void initEverything(void){ playerSpawnHill->npc[0]->addAIFunc(giveTestQuest,false); + currentWorld->bgmPlay(); atexit(destroyEverything); } diff --git a/src/world.cpp b/src/world.cpp index e5203df..ff4c461 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -64,6 +64,8 @@ void World::load(FILE *s){ World::World(void){ + bgm = NULL; + /* * Nullify pointers to other worlds. */ @@ -282,6 +284,28 @@ void World::update(Player *p,unsigned int delta){ } } +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; |