diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj index 63084e9..84afcba 100644 --- a/CrystalPoint.vcxproj +++ b/CrystalPoint.vcxproj @@ -205,12 +205,9 @@ - - - - + + - diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters index fd07b95..0be5633 100644 --- a/CrystalPoint.vcxproj.filters +++ b/CrystalPoint.vcxproj.filters @@ -168,22 +168,13 @@ - - Resource Files - - - Resource Files - - - Resource Files - - + Resource Files Resource Files - + Resource Files diff --git a/Enemy.cpp b/Enemy.cpp index 3c802b2..36c3f44 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -2,7 +2,6 @@ #include #include "Enemy.h" #include "Model.h" -#include "CrystalPoint.h" #include Enemy::Enemy(const std::string &fileName, @@ -19,7 +18,8 @@ Enemy::Enemy(const std::string &fileName, speed = 1; radius = 10; hasTarget = false; - hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/Sound.wav", false); + hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/enemy.wav", false); + music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id); attack = false; } @@ -72,9 +72,14 @@ void Enemy::collide(const Entity * entity) void Enemy::update(float delta) { + music->SetPos(position, Vec3f()); + if (hasTarget) { - + if (music->IsPlaying() == false) + { + music->Play(); + } //just 2d walking float dx, dz, length; @@ -98,15 +103,14 @@ void Enemy::update(float delta) else { attack = true; + if (music->IsPlaying() == true) + { +// music->Pause(); + music->Stop(); + } } rotation.y = atan2f(dx, dz) * 180 / M_PI; } - if (false) - { - Sound* sound = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id); - sound->SetPos(position, Vec3f()); - sound->Play(); - } } \ No newline at end of file diff --git a/Enemy.h b/Enemy.h index 4908738..d1376c8 100644 --- a/Enemy.h +++ b/Enemy.h @@ -3,6 +3,7 @@ #include "Entity.h" #include #include "Vector.h" +#include "CrystalPoint.h" class Enemy : public Entity { @@ -10,6 +11,8 @@ public: Enemy(const std::string &fileName,const Vec3f &position,Vec3f &rotation,const float &scale); ~Enemy(); + Sound* music; + bool hasTarget; Vec3f target; float speed,radius; diff --git a/Sound.cpp b/Sound.cpp index 2eeaf18..fbde702 100644 --- a/Sound.cpp +++ b/Sound.cpp @@ -9,8 +9,6 @@ Sound::Sound(const char* inWavPath, bool inLooping): source_id(0), is_looping(inLooping) { - isPlaying = false; - const char* path = inWavPath; FILE *fp = fopen(path, "rb"); // Open the WAVE file @@ -122,7 +120,6 @@ void Sound::SetPos(const Vec3f& inPos, const Vec3f& inVel) void Sound::Play() { - isPlaying = true; alSourcePlay(source_id); int e = alGetError(); // != AL_NO_ERROR) return; } @@ -136,12 +133,15 @@ void Sound::Pause() void Sound::Stop() { - isPlaying = false; alSourceStop(source_id); } bool Sound::IsPlaying() { - return isPlaying; + ALenum state; + + alGetSourcei(source_id, AL_SOURCE_STATE, &state); + + return (state == AL_PLAYING); } diff --git a/Sound.h b/Sound.h index 7361bf9..059fd0d 100644 --- a/Sound.h +++ b/Sound.h @@ -16,7 +16,6 @@ public: bool IsPlaying(); private: - bool isPlaying; unsigned int buffer_id; unsigned int source_id; diff --git a/WAVE/enemy.wav b/WAVE/enemy.wav new file mode 100644 index 0000000..89e9dae Binary files /dev/null and b/WAVE/enemy.wav differ diff --git a/WAVE/test1.wav b/WAVE/test1.wav new file mode 100644 index 0000000..e8e4fb8 Binary files /dev/null and b/WAVE/test1.wav differ diff --git a/WAVE/test2.wav b/WAVE/test2.wav new file mode 100644 index 0000000..364ff42 Binary files /dev/null and b/WAVE/test2.wav differ diff --git a/worlds/small.json b/worlds/small.json index 734fb4b..606c410 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -9,7 +9,7 @@ "collision": true } ], - "music": "WAVE/test3.wav" + "music": "WAVE/test1.wav" }, "player": { "startposition": [ 20, 5, 20 ]