Added sound files. Listens to collision events -> play sound.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,8 +16,8 @@
|
|||||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DAYDREAM_EPLAYSOUND_H
|
#ifndef Events_PlaySFX_h__
|
||||||
#define DAYDREAM_EPLAYSOUND_H
|
#define Events_PlaySFX_h__
|
||||||
|
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
@@ -27,14 +27,13 @@ namespace dd
|
|||||||
namespace Events
|
namespace Events
|
||||||
{
|
{
|
||||||
|
|
||||||
struct PlaySound : Event
|
struct PlaySFX : Event
|
||||||
{
|
{
|
||||||
float volume;
|
std::string path;
|
||||||
std::string path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //DAYDREAM_EPLAYSOUND_H
|
#endif // Events_PlaySFX_h__
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Adam on 2015-09-09.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DAYDREAM_EPLAYSOUND_H
|
|
||||||
#define DAYDREAM_EPLAYSOUND_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "EventBroker.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
|
||||||
{
|
|
||||||
|
|
||||||
namespace Events
|
|
||||||
{
|
|
||||||
|
|
||||||
struct PlaySound
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //DAYDREAM_EPLAYSOUND_H
|
|
||||||
@@ -25,7 +25,8 @@
|
|||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Core/EKeyDown.h"
|
#include "Core/EKeyDown.h"
|
||||||
#include "Core/EPlaySound.h"
|
#include "Core/EPlaySFX.h"
|
||||||
|
#include "Physics/EContact.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -53,10 +54,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
//Events
|
//Events
|
||||||
dd::EventRelay<Sound, dd::Events::KeyDown> m_EKeyDown;
|
dd::EventRelay<Sound, dd::Events::KeyDown> m_EKeyDown;
|
||||||
bool OnKeyDown(const dd::Events::KeyDown &event);
|
dd::EventRelay<Sound, dd::Events::PlaySFX> m_EPlaySFX;
|
||||||
|
dd::EventRelay<Sound, dd::Events::Contact> m_EContact;
|
||||||
|
|
||||||
//dd::EventRelay<Sound, dd::Events::PlaySound> m_EPlaySound;
|
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||||
//bool PlayASound(const dd::Events::PlaySound &event);
|
bool OnPlaySFX(const dd::Events::PlaySFX &event);
|
||||||
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
|
|
||||||
ALuint LoadFile(std::string fileName);
|
ALuint LoadFile(std::string fileName);
|
||||||
ALuint CreateSource();
|
ALuint CreateSource();
|
||||||
|
|||||||
+56
-10
@@ -16,6 +16,9 @@
|
|||||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <Game/CBall.h>
|
||||||
|
#include <Game/CBrick.h>
|
||||||
|
#include <Game/CPad.h>
|
||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
#include "Core/Sound.h"
|
#include "Core/Sound.h"
|
||||||
|
|
||||||
@@ -42,8 +45,9 @@ void dd::Systems::Sound::Initialize()
|
|||||||
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
||||||
|
|
||||||
//Subscribe to events
|
//Subscribe to events
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &Sound::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Sound::OnKeyDown);
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Sound::OnKeyDown);
|
||||||
//EVENT_SUBSCRIBE_MEMBER(m_EPlaySound, &Sound::PlayASound);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &Sound::OnPlaySFX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::Sound::Update(double dt)
|
void dd::Systems::Sound::Update(double dt)
|
||||||
@@ -54,25 +58,67 @@ void dd::Systems::Sound::Update(double dt)
|
|||||||
alSourcefv(m_Source, AL_POSITION, pos);
|
alSourcefv(m_Source, AL_POSITION, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*bool dd::Systems::Sound::PlayASound(const dd::Events::PlaySound &event)
|
bool dd::Systems::Sound::OnPlaySFX(const dd::Events::PlaySFX &event)
|
||||||
{
|
{
|
||||||
|
m_Source = CreateSource();
|
||||||
|
ALuint buffer = LoadFile(event.path);
|
||||||
|
|
||||||
}*/
|
alSourcei(m_Source, AL_BUFFER, buffer);
|
||||||
|
alSourcePlay(m_Source);
|
||||||
|
}
|
||||||
|
|
||||||
bool dd::Systems::Sound::OnKeyDown(const dd::Events::KeyDown &event)
|
bool dd::Systems::Sound::OnKeyDown(const dd::Events::KeyDown &event)
|
||||||
{
|
{
|
||||||
// #define GLFW_KEY_S 83
|
// #define GLFW_KEY_S 83
|
||||||
/*if (event.KeyCode == 83) {
|
/*if (event.KeyCode == 83) {
|
||||||
Events::PlaySound e;
|
|
||||||
e.path = "Sounds/screwed.wav";
|
|
||||||
EventBroker->Publish(e);
|
|
||||||
}*/
|
}*/
|
||||||
if (event.KeyCode == 83) {
|
if (event.KeyCode == 83) {
|
||||||
m_Source = CreateSource();
|
|
||||||
ALuint buffer = LoadFile("Sounds/screwed.wav");
|
|
||||||
|
|
||||||
alSourcei(m_Source, AL_BUFFER, buffer);
|
}
|
||||||
alSourcePlay(m_Source);
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::Sound::OnContact(const dd::Events::Contact &event)
|
||||||
|
{
|
||||||
|
int localBallEntID = 0;
|
||||||
|
//Make sure a ball is colliding
|
||||||
|
auto ball = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||||
|
if (ball == NULL) {
|
||||||
|
ball = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||||
|
if (ball == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
localBallEntID = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
localBallEntID = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Determine which event.Entity is not t
|
||||||
|
EntityID collObject;
|
||||||
|
if (localBallEntID == 1) {
|
||||||
|
collObject = event.Entity2;
|
||||||
|
}
|
||||||
|
else if (localBallEntID == 2) {
|
||||||
|
collObject = event.Entity1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*auto collisionBrick = m_World->GetComponent<Components::Brick>(collObject);
|
||||||
|
if (collisionBrick != NULL) {
|
||||||
|
dd::Events::PlaySFX e;
|
||||||
|
e.path = "Sounds/Brick/brickBreak.wav";
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
return true;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
auto collisionPad = m_World->GetComponent<Components::Pad>(collObject);
|
||||||
|
if (collisionPad != NULL) {
|
||||||
|
dd::Events::PlaySFX e;
|
||||||
|
e.path = "Sounds/Metal/impact.wav";
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user