diff --git a/content/sounds/explosion.wav b/content/sounds/explosion.wav new file mode 100644 index 0000000..58ada31 Binary files /dev/null and b/content/sounds/explosion.wav differ diff --git a/content/sounds/hurt.wav b/content/sounds/hurt.wav new file mode 100644 index 0000000..2816ee7 Binary files /dev/null and b/content/sounds/hurt.wav differ diff --git a/content/sounds/jump.wav b/content/sounds/jump.wav new file mode 100644 index 0000000..f05fbcc Binary files /dev/null and b/content/sounds/jump.wav differ diff --git a/content/sounds/melody2_forest.ogg b/content/sounds/melody2_forest.ogg new file mode 100644 index 0000000..8255f74 Binary files /dev/null and b/content/sounds/melody2_forest.ogg differ diff --git a/src/components/hurtable.cpp b/src/components/hurtable.cpp index a45900e..90da132 100644 --- a/src/components/hurtable.cpp +++ b/src/components/hurtable.cpp @@ -1,5 +1,6 @@ #include "hurtable.h" #include "animator.h" +#include "../content.h" using namespace TL; @@ -15,8 +16,10 @@ void Hurtable::update() { if (collider && on_hurt && stun_timer <= 0) { - if (collider->check(hurt_by)) + if (collider->check(hurt_by)) { + Sound::play(Content::find_audio("hurt.wav")); hurt(); + } } stun_timer -= Time::delta; diff --git a/src/components/player.cpp b/src/components/player.cpp index b87a1ff..3ddcc72 100644 --- a/src/components/player.cpp +++ b/src/components/player.cpp @@ -4,6 +4,7 @@ #include "collider.h" #include "orb.h" #include "../masks.h" +#include "../content.h" using namespace TL; @@ -119,6 +120,9 @@ void Player::update() anim->scale = Vec2f(m_facing * 0.65f, 1.4f); mover->speed.x = input * max_air_speed; m_jump_timer = jump_time; + SoundParams params; + params.volume = 3.0f; + Sound::play(Content::find_audio("jump.wav"), params); } } diff --git a/src/content.cpp b/src/content.cpp index 36de477..f292ea0 100644 --- a/src/content.cpp +++ b/src/content.cpp @@ -26,6 +26,8 @@ namespace Vector tilesets; Vector subtextures; Vector rooms; + Vector audio_names; + Vector audios; TextureRef sprite_atlas; } @@ -198,6 +200,19 @@ void Content::load() rooms.push_back(info); } + + // load audio + for (auto& it : Directory::enumerate(path() + "/sounds", false)) + { + if (!(it.ends_with(".ogg") || it.ends_with(".wav"))) + continue; + + FilePath path = FilePath(it.cstr()); + AudioRef audio = Audio::create(path); + BLAH_ASSERT(audio->get_backend_handle(), "Unable to load audio."); + audios.push_back(audio); + audio_names.push_back(Path::get_file_name(path)); + } } void Content::unload() @@ -236,3 +251,12 @@ const Image* Content::find_room(const Point& cell) return nullptr; } + +const AudioRef Content::find_audio(const char* name) +{ + for (int i = 0; i < audio_names.size(); ++i) + if (audio_names[i] == name) + return audios[i]; + + return nullptr; +} diff --git a/src/content.h b/src/content.h index 4c7463e..269c30c 100644 --- a/src/content.h +++ b/src/content.h @@ -21,5 +21,6 @@ namespace TL static const Sprite* find_sprite(const char* name); static const Tileset* find_tileset(const char* name); static const Image* find_room(const Point& cell); + static const AudioRef find_audio(const char* name); }; } \ No newline at end of file diff --git a/src/factory.cpp b/src/factory.cpp index 0935982..7a1c5af 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -9,6 +9,7 @@ #include "components/enemy.h" #include "components/ghost_frog.h" #include "components/orb.h" +#include "content.h" using namespace TL; @@ -60,6 +61,7 @@ Entity* Factory::pop(World* world, Point position) auto anim = en->add(Animator("pop")); anim->play("pop"); anim->depth = -20; + Sound::play(Content::find_audio("explosion.wav")); auto timer = en->add(Timer(anim->animation()->duration(), [](Timer* self) { diff --git a/src/game.cpp b/src/game.cpp index 00d9f3a..d72da74 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -35,6 +35,8 @@ void Game::startup() load_room(Point(0, 0)); camera = Vec2f(room.x * width, room.y * height); fullscreen = false; + + Music::play(Content::find_audio("melody2_forest.ogg")); } void Game::load_room(Point cell, bool is_reload) @@ -180,10 +182,6 @@ void Game::update() camera = Vec2f(0, 0); } - // Toggle Fullscreen - if (Input::pressed(Key::F4)) - App::fullscreen(fullscreen = !fullscreen); - // Normal Update if (!m_transition) {