diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj index 65167a2..c5b1bb5 100644 --- a/CrystalPoint.vcxproj +++ b/CrystalPoint.vcxproj @@ -206,7 +206,10 @@ + + + diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters index b76db86..5a80d88 100644 --- a/CrystalPoint.vcxproj.filters +++ b/CrystalPoint.vcxproj.filters @@ -174,5 +174,14 @@ Resource Files + + Resource Files + + + Resource Files + + + Resource Files + \ No newline at end of file diff --git a/Sound.cpp b/Sound.cpp index cc990da..2eeaf18 100644 --- a/Sound.cpp +++ b/Sound.cpp @@ -8,8 +8,9 @@ Sound::Sound(const char* inWavPath, bool inLooping): buffer_id(0), source_id(0), is_looping(inLooping) - { + isPlaying = false; + const char* path = inWavPath; FILE *fp = fopen(path, "rb"); // Open the WAVE file @@ -121,6 +122,7 @@ void Sound::SetPos(const Vec3f& inPos, const Vec3f& inVel) void Sound::Play() { + isPlaying = true; alSourcePlay(source_id); int e = alGetError(); // != AL_NO_ERROR) return; } @@ -134,6 +136,12 @@ void Sound::Pause() void Sound::Stop() { + isPlaying = false; alSourceStop(source_id); } +bool Sound::IsPlaying() +{ + return isPlaying; +} + diff --git a/Sound.h b/Sound.h index 74e2f9f..7361bf9 100644 --- a/Sound.h +++ b/Sound.h @@ -13,8 +13,10 @@ public: void Play(); void Pause(); void Stop(); + bool IsPlaying(); private: + bool isPlaying; unsigned int buffer_id; unsigned int source_id; diff --git a/WAVE/jpark.wav b/WAVE/jpark.wav new file mode 100644 index 0000000..c9bf3fe Binary files /dev/null and b/WAVE/jpark.wav differ diff --git a/World.cpp b/World.cpp index 00d6bf9..4cf9305 100644 --- a/World.cpp +++ b/World.cpp @@ -179,9 +179,6 @@ World::World(const std::string &fileName): if (!v["world"]["music"].isNull()) { music_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true); - Sound* music = CrystalPoint::GetSoundSystem().GetSound(music_id); - music->SetPos(Vec3f(), Vec3f()); - music->Play(); } if (!v["portal"].isNull()) @@ -257,6 +254,13 @@ void World::draw() void World::update(float elapsedTime) { + Sound* music = CrystalPoint::GetSoundSystem().GetSound(music_id); + music->SetPos(player->position, Vec3f()); + + if (music->IsPlaying() == false) + { + music->Play(); + } for (auto &entity : entities) entity->update(elapsedTime); diff --git a/worlds/small.json b/worlds/small.json index af4cecf..016abb4 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -9,7 +9,7 @@ "collision": true } ], - "music": "WAVE/bond.wav" + "music": "WAVE/test2.wav" }, "player": { "startposition": [ 20, 5, 20 ]