diff --git a/assets/Sounds/Brick/brickBreak-bak1.wav b/assets/Sounds/Brick/brickBreak-bak1.wav deleted file mode 100644 index 31d62ff..0000000 Binary files a/assets/Sounds/Brick/brickBreak-bak1.wav and /dev/null differ diff --git a/assets/Sounds/Brick/brickBreak.wav b/assets/Sounds/Brick/brickBreak.wav deleted file mode 100644 index 5b800eb..0000000 Binary files a/assets/Sounds/Brick/brickBreak.wav and /dev/null differ diff --git a/assets/Sounds/Brick/shortbrickbreak.wav b/assets/Sounds/Brick/shortbrickbreak.wav new file mode 100644 index 0000000..509a188 Binary files /dev/null and b/assets/Sounds/Brick/shortbrickbreak.wav differ diff --git a/include/Core/Engine.h b/include/Core/Engine.h index a32c479..a48c4ac 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -18,6 +18,7 @@ #include #include +#include #include "ResourceManager.h" #include "OBJ.h" @@ -37,6 +38,7 @@ #include "Rendering/CPointLight.h" #include "Transform/TransformSystem.h" #include "Sound/SoundSystem.h" +#include "Sound/CCollisionSound.h" #include "Game/LevelSystem.h" #include "Game/PadSystem.h" #include "Game/CBall.h" @@ -76,6 +78,7 @@ public: m_World->ComponentFactory.Register(); m_World->ComponentFactory.Register(); + m_World->ComponentFactory.Register(); m_World->SystemFactory.Register([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); }); m_World->AddSystem(); diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index 786355f..7b9f890 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -23,6 +23,7 @@ #include "Physics/CCircleShape.h" #include "Physics/ESetImpulse.h" #include "Physics/EContact.h" +#include "Sound/CCollisionSound.h" #include #include #include diff --git a/include/Sound/CCollisionSound.h b/include/Sound/CCollisionSound.h new file mode 100644 index 0000000..4a631a3 --- /dev/null +++ b/include/Sound/CCollisionSound.h @@ -0,0 +1,25 @@ +// +// Created by Adam on 2015-09-17. +// + +#ifndef COMPONENTS_CCOLLISIONSOUND_H__ +#define COMPONENTS_CCOLLISIONSOUND_H__ + +#include "Core/Component.h" + +namespace dd +{ + +namespace Components +{ + +struct CollisionSound : public Component +{ + std::string filePath; +}; + +} + +} + +#endif diff --git a/include/Sound/SoundSystem.h b/include/Sound/SoundSystem.h index 5066aca..d3d247d 100644 --- a/include/Sound/SoundSystem.h +++ b/include/Sound/SoundSystem.h @@ -28,9 +28,11 @@ #include "Sound/EPlaySFX.h" #include "Physics/EContact.h" #include "Core/EventBroker.h" -#include -#include -#include +#include "Game/CBall.h" +#include "Game/CBrick.h" +#include "Game/CPad.h" +#include "Sound/CCollisionSound.h" + namespace dd { diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 816d839..366b6e7 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -111,6 +111,11 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe transform->Scale = glm::vec3(1.6, 0.35, 0.5); transform->Position = glm::vec3(x - 7, y + 1, -10.f); cBrick->Score = 10 * num; + + //sound + auto collisionSound = m_World->AddComponent(brick); + collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav"; + m_World->CommitEntity(brick); return; } diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index fab5712..3a7903a 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -78,7 +78,21 @@ bool dd::Systems::SoundSystem::OnKeyDown(const dd::Events::KeyDown &event) bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) { - int localBallEntID = 0; + auto collisionSound = m_World->GetComponent(event.Entity1); + if (collisionSound == NULL) { + collisionSound = m_World->GetComponent(event.Entity2); + if (collisionSound == NULL) { + return false; + } + } + + dd::Events::PlaySFX e; + e.path = collisionSound->filePath; + EventBroker->Publish(e); + return true; + + + /*int localBallEntID = 0; //Make sure a ball is colliding auto ball = m_World->GetComponent(event.Entity1); if (ball == NULL) { @@ -117,7 +131,7 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) e.path = "Sounds/Metal/impact.wav"; EventBroker->Publish(e); return true; - } + }*/ } ALuint dd::Systems::SoundSystem::CreateSource()