Added Component to bricks to emitt sound. Improved code for playing a sound
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <Sound/CCollisionSound.h>
|
||||||
|
|
||||||
#include "ResourceManager.h"
|
#include "ResourceManager.h"
|
||||||
#include "OBJ.h"
|
#include "OBJ.h"
|
||||||
@@ -37,6 +38,7 @@
|
|||||||
#include "Rendering/CPointLight.h"
|
#include "Rendering/CPointLight.h"
|
||||||
#include "Transform/TransformSystem.h"
|
#include "Transform/TransformSystem.h"
|
||||||
#include "Sound/SoundSystem.h"
|
#include "Sound/SoundSystem.h"
|
||||||
|
#include "Sound/CCollisionSound.h"
|
||||||
#include "Game/LevelSystem.h"
|
#include "Game/LevelSystem.h"
|
||||||
#include "Game/PadSystem.h"
|
#include "Game/PadSystem.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
@@ -76,6 +78,7 @@ public:
|
|||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
|
|
||||||
|
m_World->ComponentFactory.Register<Components::CollisionSound>();
|
||||||
m_World->SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
|
m_World->SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::SoundSystem>();
|
m_World->AddSystem<Systems::SoundSystem>();
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
#include "Physics/EContact.h"
|
#include "Physics/EContact.h"
|
||||||
|
#include "Sound/CCollisionSound.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <intrin.h>
|
#include <intrin.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
|
||||||
@@ -28,9 +28,11 @@
|
|||||||
#include "Sound/EPlaySFX.h"
|
#include "Sound/EPlaySFX.h"
|
||||||
#include "Physics/EContact.h"
|
#include "Physics/EContact.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
#include <Game/CBall.h>
|
#include "Game/CBall.h"
|
||||||
#include <Game/CBrick.h>
|
#include "Game/CBrick.h"
|
||||||
#include <Game/CPad.h>
|
#include "Game/CPad.h"
|
||||||
|
#include "Sound/CCollisionSound.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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->Scale = glm::vec3(1.6, 0.35, 0.5);
|
||||||
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
|
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
|
||||||
cBrick->Score = 10 * num;
|
cBrick->Score = 10 * num;
|
||||||
|
|
||||||
|
//sound
|
||||||
|
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
|
||||||
|
collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
|
||||||
|
|
||||||
m_World->CommitEntity(brick);
|
m_World->CommitEntity(brick);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,21 @@ bool dd::Systems::SoundSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
|||||||
|
|
||||||
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
int localBallEntID = 0;
|
auto collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity1);
|
||||||
|
if (collisionSound == NULL) {
|
||||||
|
collisionSound = m_World->GetComponent<Components::CollisionSound>(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
|
//Make sure a ball is colliding
|
||||||
auto ball = m_World->GetComponent<Components::Ball>(event.Entity1);
|
auto ball = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||||
if (ball == NULL) {
|
if (ball == NULL) {
|
||||||
@@ -117,7 +131,7 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
e.path = "Sounds/Metal/impact.wav";
|
e.path = "Sounds/Metal/impact.wav";
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
ALuint dd::Systems::SoundSystem::CreateSource()
|
ALuint dd::Systems::SoundSystem::CreateSource()
|
||||||
|
|||||||
Reference in New Issue
Block a user