From c772a3e5d8d9507b898813cdfb597c14b07cdc61 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 2 Feb 2021 20:18:41 -0500 Subject: Added "bumping into something while running" sfx --- src/mixer.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/mixer.cpp (limited to 'src/mixer.cpp') diff --git a/src/mixer.cpp b/src/mixer.cpp new file mode 100644 index 0000000..bfbedcd --- /dev/null +++ b/src/mixer.cpp @@ -0,0 +1,16 @@ +#include "mixer.h" + +void Mixer::playSound(std::string filename) { + if (!sounds_.count(filename)) { + Mix_Chunk* sample = Mix_LoadWAV(filename.c_str()); + if (!sample) { + throw mix_error(); + } + + sounds_[filename] = chunk_ptr(sample); + } + + if (Mix_PlayChannel(-1, sounds_[filename].get(), 0) == -1) { + throw mix_error(); + } +} -- cgit 1.4.1