test out audio branch for blah

This commit is contained in:
RandyGaul 2022-11-19 14:13:15 -08:00
parent f62a60cb3e
commit 7aa6efad1f
10 changed files with 37 additions and 5 deletions

Binary file not shown.

BIN
content/sounds/hurt.wav Normal file

Binary file not shown.

BIN
content/sounds/jump.wav Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,6 @@
#include "hurtable.h" #include "hurtable.h"
#include "animator.h" #include "animator.h"
#include "../content.h"
using namespace TL; using namespace TL;
@ -15,8 +16,10 @@ void Hurtable::update()
{ {
if (collider && on_hurt && stun_timer <= 0) 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(); hurt();
}
} }
stun_timer -= Time::delta; stun_timer -= Time::delta;

View File

@ -4,6 +4,7 @@
#include "collider.h" #include "collider.h"
#include "orb.h" #include "orb.h"
#include "../masks.h" #include "../masks.h"
#include "../content.h"
using namespace TL; using namespace TL;
@ -119,6 +120,9 @@ void Player::update()
anim->scale = Vec2f(m_facing * 0.65f, 1.4f); anim->scale = Vec2f(m_facing * 0.65f, 1.4f);
mover->speed.x = input * max_air_speed; mover->speed.x = input * max_air_speed;
m_jump_timer = jump_time; m_jump_timer = jump_time;
SoundParams params;
params.volume = 3.0f;
Sound::play(Content::find_audio("jump.wav"), params);
} }
} }

View File

@ -26,6 +26,8 @@ namespace
Vector<Tileset> tilesets; Vector<Tileset> tilesets;
Vector<Subtexture> subtextures; Vector<Subtexture> subtextures;
Vector<RoomInfo> rooms; Vector<RoomInfo> rooms;
Vector<String> audio_names;
Vector<AudioRef> audios;
TextureRef sprite_atlas; TextureRef sprite_atlas;
} }
@ -198,6 +200,19 @@ void Content::load()
rooms.push_back(info); 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() void Content::unload()
@ -236,3 +251,12 @@ const Image* Content::find_room(const Point& cell)
return nullptr; 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;
}

View File

@ -21,5 +21,6 @@ namespace TL
static const Sprite* find_sprite(const char* name); static const Sprite* find_sprite(const char* name);
static const Tileset* find_tileset(const char* name); static const Tileset* find_tileset(const char* name);
static const Image* find_room(const Point& cell); static const Image* find_room(const Point& cell);
static const AudioRef find_audio(const char* name);
}; };
} }

View File

@ -9,6 +9,7 @@
#include "components/enemy.h" #include "components/enemy.h"
#include "components/ghost_frog.h" #include "components/ghost_frog.h"
#include "components/orb.h" #include "components/orb.h"
#include "content.h"
using namespace TL; using namespace TL;
@ -60,6 +61,7 @@ Entity* Factory::pop(World* world, Point position)
auto anim = en->add(Animator("pop")); auto anim = en->add(Animator("pop"));
anim->play("pop"); anim->play("pop");
anim->depth = -20; anim->depth = -20;
Sound::play(Content::find_audio("explosion.wav"));
auto timer = en->add(Timer(anim->animation()->duration(), [](Timer* self) auto timer = en->add(Timer(anim->animation()->duration(), [](Timer* self)
{ {

View File

@ -35,6 +35,8 @@ void Game::startup()
load_room(Point(0, 0)); load_room(Point(0, 0));
camera = Vec2f(room.x * width, room.y * height); camera = Vec2f(room.x * width, room.y * height);
fullscreen = false; fullscreen = false;
Music::play(Content::find_audio("melody2_forest.ogg"));
} }
void Game::load_room(Point cell, bool is_reload) void Game::load_room(Point cell, bool is_reload)
@ -180,10 +182,6 @@ void Game::update()
camera = Vec2f(0, 0); camera = Vec2f(0, 0);
} }
// Toggle Fullscreen
if (Input::pressed(Key::F4))
App::fullscreen(fullscreen = !fullscreen);
// Normal Update // Normal Update
if (!m_transition) if (!m_transition)
{ {