From af39f2e08b0503db723ae707a5c7278d8c85f812 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 1 Oct 2019 20:50:28 -0400 Subject: Audio component loading, getting ready to play --- src/engine.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/engine.cpp') diff --git a/src/engine.cpp b/src/engine.cpp index b1d9a56..3fc4fdd 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -19,6 +19,7 @@ * along with this program. If not, see . */ +#include "audio.hpp" #include "config.hpp" #include "engine.hpp" #include "gamestate.hpp" @@ -54,6 +55,7 @@ int Engine::init(void) systems.add(entities, *(systems.system().get())); systems.add(); systems.add(); + systems.add(); systems.configure(); // Load game script and entity data -- cgit v1.2.3 From 9d79ba461a399ce5c211dc7ca2fc49b8934c1cd7 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 1 Oct 2019 20:57:25 -0400 Subject: sound on jump --- Scripts/init.lua | 1 + src/engine.cpp | 3 +++ 2 files changed, 4 insertions(+) (limited to 'src/engine.cpp') diff --git a/Scripts/init.lua b/Scripts/init.lua index ea5a833..d09fb14 100644 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@ -21,6 +21,7 @@ player = { end, JumpKeyPressed = function(self) if self.Physics.standing == true then + game.play(self.Position, self.Audio) self.Velocity.y = self.Velocity.y + 9 end end, diff --git a/src/engine.cpp b/src/engine.cpp index ed5ba07..c6bec27 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -66,6 +66,9 @@ int Engine::init(void) script->addToGameNamespace("puts", bindInstance(&TextSystem::put, systems.system().get())); + script->addToGameNamespace("play", + bindInstance(&AudioSystem::playSound, + systems.system().get())); script->init(); -- cgit v1.2.3 From eed19ec73698c8180a51c33fa56c7cfe7c0e60f0 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 3 Oct 2019 10:24:01 -0400 Subject: positional audio working --- Assets/boing.wav | Bin 605018 -> 302628 bytes Assets/jump.wav | Bin 303194 -> 151716 bytes src/audio.cpp | 18 ++++++++++++++++-- src/engine.cpp | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/engine.cpp') diff --git a/Assets/boing.wav b/Assets/boing.wav index a142197..088963d 100644 Binary files a/Assets/boing.wav and b/Assets/boing.wav differ diff --git a/Assets/jump.wav b/Assets/jump.wav index 1cd1681..b9849ab 100644 Binary files a/Assets/jump.wav and b/Assets/jump.wav differ diff --git a/src/audio.cpp b/src/audio.cpp index 8bb1413..2f14c97 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -19,6 +19,7 @@ */ #include "audio.hpp" +#include "components/Player.hpp" #include #include @@ -55,12 +56,25 @@ void AudioSystem::configure([[maybe_unused]] entityx::EntityManager& entities, if (alutInitWithoutContext(nullptr, nullptr) != AL_TRUE) return; // TODO Third uh oh + + ALfloat listenerOri[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }; + alListener3f(AL_POSITION, 0, 0, 0.0f); + alListener3f(AL_VELOCITY, 0, 0, 0); + alListenerfv(AL_ORIENTATION, listenerOri); } -void AudioSystem::update([[maybe_unused]] entityx::EntityManager& entities, +void AudioSystem::update(entityx::EntityManager& entities, [[maybe_unused]] entityx::EventManager& events, [[maybe_unused]] entityx::TimeDelta dt) -{} +{ + entities.each( + []([[maybe_unused]] entityx::Entity e, + [[maybe_unused]] Player& p, + Position &pos) + { + alListener3f(AL_POSITION, pos.x, pos.y, 0.0f); + }); +} void AudioSystem::receive(const entityx::ComponentAddedEvent