Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added content/sounds/explosion.wav
Binary file not shown.
Binary file added content/sounds/hurt.wav
Binary file not shown.
Binary file added content/sounds/jump.wav
Binary file not shown.
Binary file added content/sounds/melody2_forest.ogg
Binary file not shown.
5 changes: 4 additions & 1 deletion src/components/hurtable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "hurtable.h"
#include "animator.h"
#include "../content.h"

using namespace TL;

Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/components/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "collider.h"
#include "orb.h"
#include "../masks.h"
#include "../content.h"

using namespace TL;

Expand Down Expand Up @@ -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);
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace
Vector<Tileset> tilesets;
Vector<Subtexture> subtextures;
Vector<RoomInfo> rooms;
Vector<String> audio_names;
Vector<AudioRef> audios;
TextureRef sprite_atlas;
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/content.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
2 changes: 2 additions & 0 deletions src/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "components/enemy.h"
#include "components/ghost_frog.h"
#include "components/orb.h"
#include "content.h"

using namespace TL;

Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 2 additions & 4 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down