diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 4 | ||||
-rw-r--r-- | src/gameplay.cpp | 3 | ||||
-rw-r--r-- | src/world.cpp | 24 |
3 files changed, 19 insertions, 12 deletions
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 "<<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; |