Add more sounds

This commit is contained in:
Nikita Lisitsa 2024-08-20 17:36:53 +03:00
parent 33cc157643
commit 7be83e1b7c
9 changed files with 85 additions and 0 deletions

View file

@ -13,3 +13,4 @@ file(GLOB_RECURSE GMTK_SOURCES LIST_DIRECTORIES FALSE "${CMAKE_CURRENT_SOURCE_DI
file(GLOB_RECURSE GMTK_HEADERS LIST_DIRECTORIES FALSE "${CMAKE_CURRENT_SOURCE_DIR}/include/*")
psemek_add_application(color-fractory ${GMTK_SOURCES} ${GMTK_HEADERS})
psemek_package_files(color-fractory sounds)

BIN
sounds/click_high.mp3 Normal file

Binary file not shown.

BIN
sounds/click_low.mp3 Normal file

Binary file not shown.

BIN
sounds/error.mp3 Normal file

Binary file not shown.

BIN
sounds/gears.mp3 Normal file

Binary file not shown.

BIN
sounds/key_click.mp3 Normal file

Binary file not shown.

BIN
sounds/machine.mp3 Normal file

Binary file not shown.

BIN
sounds/pop.mp3 Normal file

Binary file not shown.

View file

@ -8,6 +8,7 @@
#include <psemek/util/hash_table.hpp>
#include <psemek/util/enum.hpp>
#include <psemek/util/clock.hpp>
#include <psemek/util/executable_path.hpp>
#include <psemek/geom/box.hpp>
#include <psemek/geom/camera.hpp>
#include <psemek/geom/contains.hpp>
@ -16,6 +17,7 @@
#include <psemek/ecs/declare_uuid.hpp>
#include <psemek/log/log.hpp>
#include <psemek/io/file_stream.hpp>
#include <psemek/audio/engine.hpp>
#include <psemek/audio/combine/mixer.hpp>
@ -28,6 +30,7 @@
#include <psemek/audio/effect/fade_in.hpp>
#include <psemek/audio/effect/fade_out.hpp>
#include <psemek/audio/effect/pitch.hpp>
#include <psemek/audio/track.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/flat_map.hpp>
@ -1345,6 +1348,16 @@ namespace gmtk
volume_ = audio::volume(mixer_);
audio_->output()->stream(audio::compressor(volume_));
auto sounds_root = util::executable_path().parent_path() / "sounds";
click_low_ = audio::load_mp3(io::read_full(io::file_istream{sounds_root / "click_low.mp3"}));
click_high_ = audio::load_mp3(io::read_full(io::file_istream{sounds_root / "click_high.mp3"}));
key_click_ = audio::load_mp3(io::read_full(io::file_istream{sounds_root / "key_click.mp3"}));
gears_ = audio::load_mp3(io::read_full(io::file_istream{sounds_root / "gears.mp3"}));
machine_ = audio::load_mp3(io::read_full(io::file_istream{sounds_root / "machine.mp3"}));
pop_ = audio::load_mp3(io::read_full(io::file_istream{sounds_root / "pop.mp3"}));
error_ = audio::load_mp3(io::read_full(io::file_istream{sounds_root / "error.mp3"}));
context_.windowed(is_windowed_);
set_start_menu();
}
@ -1629,7 +1642,10 @@ namespace gmtk
if (!map_.world->get(t).contains<occupied>())
{
if (!map_.world->get(t).get<path_vertex>().belts_to.empty())
{
s.animate += 1.f;
item_produced_sound();
}
auto i = map_.world->create(
item{s.type, p}
@ -1763,8 +1779,23 @@ namespace gmtk
}
if (crafted)
{
t.animate += 1.f;
switch (t.type)
{
case transformer_type::mixer:
mixer_sound();
break;
case transformer_type::hue_shifter:
shifter_sound();
break;
case transformer_type::reshaper:
reshaper_sound();
break;
}
}
if (!crafted && !has_inputs.empty())
{
return;
@ -1817,9 +1848,11 @@ namespace gmtk
map_.resource_count += 1;
l->animate += 1.f;
map_.world->destroy(entity);
item_received_sound();
}
else
{
item_error_sound();
l->animate_error += 1.f;
map_.world->destroy(entity);
}
@ -1952,6 +1985,7 @@ namespace gmtk
map_.world->detach<occupied>(map_.world->index<path_index>().get(i.start));
map_.world->destroy(*selected_item_);
selected_item_ = std::nullopt;
item_removed_sound();
}
{
@ -2389,6 +2423,14 @@ namespace gmtk
audio::mixer_ptr mixer_;
std::shared_ptr<audio::volume_control> volume_;
audio::track_ptr click_low_;
audio::track_ptr click_high_;
audio::track_ptr key_click_;
audio::track_ptr gears_;
audio::track_ptr machine_;
audio::track_ptr pop_;
audio::track_ptr error_;
bool running_ = true;
bool in_start_menu_ = true;
@ -2581,6 +2623,48 @@ namespace gmtk
pitch->pitch(0.666f);
mixer_->add(audio::volume(pitch, 0.25f));
}
void item_received_sound()
{
if (in_start_menu_) return;
mixer_->add(audio::volume(click_high_->stream(), 0.25f));
}
void item_produced_sound()
{
if (in_start_menu_) return;
mixer_->add(audio::volume(click_low_->stream(), 0.5f));
}
void mixer_sound()
{
if (in_start_menu_) return;
mixer_->add(audio::volume(machine_->stream(), 0.125f));
}
void shifter_sound()
{
if (in_start_menu_) return;
mixer_->add(audio::volume(gears_->stream(), 0.5f));
}
void reshaper_sound()
{
if (in_start_menu_) return;
mixer_->add(audio::volume(key_click_->stream(), 0.25f));
}
void item_removed_sound()
{
if (in_start_menu_) return;
mixer_->add(audio::volume(pop_->stream(), 0.5f));
}
void item_error_sound()
{
if (in_start_menu_) return;
mixer_->add(audio::volume(error_->stream(), 0.25f));
}
};
}