Aaldert преди 9 години
родител
ревизия
b7d73c9abe
променени са 7 файла, в които са добавени 31 реда и са изтрити 5 реда
  1. 3 0
      CrystalPoint.vcxproj
  2. 9 0
      CrystalPoint.vcxproj.filters
  3. 9 1
      Sound.cpp
  4. 2 0
      Sound.h
  5. BIN
      WAVE/jpark.wav
  6. 7 3
      World.cpp
  7. 1 1
      worlds/small.json

+ 3 - 0
CrystalPoint.vcxproj

@@ -206,7 +206,10 @@
   </ItemGroup>
   <ItemGroup>
     <Media Include="WAVE\bond.wav" />
+    <Media Include="WAVE\jpark.wav" />
     <Media Include="WAVE\Sound.wav" />
+    <Media Include="WAVE\test.wav" />
+    <Media Include="WAVE\test2.wav" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 9 - 0
CrystalPoint.vcxproj.filters

@@ -174,5 +174,14 @@
     <Media Include="WAVE\bond.wav">
       <Filter>Resource Files</Filter>
     </Media>
+    <Media Include="WAVE\test.wav">
+      <Filter>Resource Files</Filter>
+    </Media>
+    <Media Include="WAVE\test2.wav">
+      <Filter>Resource Files</Filter>
+    </Media>
+    <Media Include="WAVE\jpark.wav">
+      <Filter>Resource Files</Filter>
+    </Media>
   </ItemGroup>
 </Project>

+ 9 - 1
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;
+}
+

+ 2 - 0
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;
 

BIN
WAVE/jpark.wav


+ 7 - 3
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);
 

+ 1 - 1
worlds/small.json

@@ -9,7 +9,7 @@
         "collision": true
       }
     ],
-	"music": "WAVE/bond.wav"
+	"music": "WAVE/test2.wav"
   },
   "player": {
     "startposition": [ 20, 5, 20 ]