diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj index 65167a2..9cde889 100644 --- a/CrystalPoint.vcxproj +++ b/CrystalPoint.vcxproj @@ -201,12 +201,14 @@ + - - + + + diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters index b76db86..356087f 100644 --- a/CrystalPoint.vcxproj.filters +++ b/CrystalPoint.vcxproj.filters @@ -166,12 +166,18 @@ Source Files\json + + Source Files\json + - + 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 237b63c..a3cc983 100644 --- a/Sound.cpp +++ b/Sound.cpp @@ -17,7 +17,6 @@ Sound::Sound(const char* inWavPath, bool inLooping): buffer_id(0), source_id(0), is_looping(inLooping) - { const char* path = inWavPath; @@ -146,3 +145,12 @@ void Sound::Stop() alSourceStop(source_id); } +bool Sound::IsPlaying() +{ + ALenum state; + + alGetSourcei(source_id, AL_SOURCE_STATE, &state); + + return (state == AL_PLAYING); +} + diff --git a/Sound.h b/Sound.h index baf9246..02fe227 100644 --- a/Sound.h +++ b/Sound.h @@ -13,6 +13,7 @@ public: void Play(); void Pause(); void Stop(); + bool IsPlaying(); private: unsigned int buffer_id; diff --git a/WAVE/Sound.wav b/WAVE/Sound.wav deleted file mode 100644 index 74ccfd2..0000000 Binary files a/WAVE/Sound.wav and /dev/null differ diff --git a/WAVE/bond.wav b/WAVE/bond.wav deleted file mode 100644 index c478afe..0000000 Binary files a/WAVE/bond.wav and /dev/null differ 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/World.cpp b/World.cpp index 00d6bf9..c3141c1 100644 --- a/World.cpp +++ b/World.cpp @@ -3,7 +3,6 @@ #include "Entity.h" #include "json.h" #include "Model.h" -#include "CrystalPoint.h" #include #include #include @@ -179,9 +178,7 @@ 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(); + music = CrystalPoint::GetSoundSystem().GetSound(music_id); } if (!v["portal"].isNull()) @@ -214,6 +211,8 @@ World::World(const std::string &fileName): World::~World() { delete heightmap; + music->Stop(); + delete music; delete skybox; } @@ -257,6 +256,12 @@ void World::draw() void World::update(float elapsedTime) { + music->SetPos(player->position, Vec3f()); + + if (music->IsPlaying() == false) + { + music->Play(); + } for (auto &entity : entities) entity->update(elapsedTime); diff --git a/World.h b/World.h index f12d1e2..a33385f 100644 --- a/World.h +++ b/World.h @@ -8,6 +8,7 @@ #include "Interface.h" #include "Crystal.h" #include "Skybox.h" +#include "CrystalPoint.h" #include "Portal.h" class Entity; @@ -16,6 +17,7 @@ class World { private: std::vector>> objecttemplates; + Sound* music; Player* player; HeightMap* heightmap; diff --git a/worlds/rock.json b/worlds/rock.json index 55f5132..08d3311 100644 --- a/worlds/rock.json +++ b/worlds/rock.json @@ -3,6 +3,7 @@ "heightmap": "worlds/rockHeightmap.png", "texture": "worlds/rockStone2.png", "skybox": "skyboxes/water/", + "music": "WAVE/test2.wav", "object-templates": [ { "color": 50, diff --git a/worlds/small.json b/worlds/small.json index af4cecf..606c410 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -9,7 +9,7 @@ "collision": true } ], - "music": "WAVE/bond.wav" + "music": "WAVE/test1.wav" }, "player": { "startposition": [ 20, 5, 20 ]