Start and stop some sounds and add a little bit of reverb to sounds so they fit the 'dungeon' theme.

This commit is contained in:
Zed A. Shaw 2025-02-28 10:48:45 -05:00
parent a8ae6df13b
commit 25d782df6d
18 changed files with 20 additions and 2 deletions

View file

@ -36,7 +36,7 @@
{"_type": "EnemyConfig", "hearing_distance": 5}, {"_type": "EnemyConfig", "hearing_distance": 5},
{"_type": "Sprite", "name": "axe_ranger"}, {"_type": "Sprite", "name": "axe_ranger"},
{"_type": "Animation", "scale": 0.1, "simple": false, "frames": 10, "speed": 0.6}, {"_type": "Animation", "scale": 0.1, "simple": false, "frames": 10, "speed": 0.6},
{"_type": "Sound", "attack": "Sword_Hit_1", "death": "Humanoid_Death_1"} {"_type": "Sound", "attack": "Sword_Hit_1", "death": "Ranger_1"}
] ]
}, },
"EVIL_EYE": { "EVIL_EYE": {

View file

@ -123,6 +123,8 @@ namespace gui {
void FSM::IDLE(Event ev) { void FSM::IDLE(Event ev) {
using enum Event; using enum Event;
sound::stop("walk");
switch(ev) { switch(ev) {
case QUIT: case QUIT:
$window.close(); $window.close();
@ -164,7 +166,7 @@ namespace gui {
dbc::log("Nothing to close."); dbc::log("Nothing to close.");
break; break;
case STAIRS_DOWN: case STAIRS_DOWN:
// $main_ui.show_level(); sound::stop("ambient");
state(State::NEXT_LEVEL); state(State::NEXT_LEVEL);
break; break;
case STOP_COMBAT: case STOP_COMBAT:
@ -181,6 +183,7 @@ namespace gui {
switch(ev) { switch(ev) {
case STAIRS_DOWN: case STAIRS_DOWN:
sound::play("ambient");
next_level(); next_level();
state(State::IDLE); state(State::IDLE);
default: default:

View file

@ -53,6 +53,19 @@ namespace sound {
} }
} }
void stop(const std::string name) {
dbc::check(initialized, "You need to call sound::init() first");
if(SMGR.sounds.contains(name)) {
// get the sound from the sound map
auto pair = SMGR.sounds.at(name);
pair.sound->stop();
} else {
dbc::log(fmt::format("Attempted to stop {} sound but not available.",
name));
}
}
void play_at(const std::string name, float x, float y, float z) { void play_at(const std::string name, float x, float y, float z) {
dbc::check(initialized, "You need to call sound::init() first"); dbc::check(initialized, "You need to call sound::init() first");
if(SMGR.sounds.contains(name)) { if(SMGR.sounds.contains(name)) {

View file

@ -19,5 +19,6 @@ namespace sound {
void load(const std::string name, const std::string path); void load(const std::string name, const std::string path);
void play(const std::string name, bool loop=false); void play(const std::string name, bool loop=false);
void play_at(const std::string name, float x, float y, float z); void play_at(const std::string name, float x, float y, float z);
void stop(const std::string name);
void mute(bool setting); void mute(bool setting);
} }

View file

@ -135,6 +135,7 @@ void System::death(GameLevel &level, components::ComponentMap& components) {
world.remove<Animation>(ent); world.remove<Animation>(ent);
if(auto snd = world.get_if<Sound>(ent)) { if(auto snd = world.get_if<Sound>(ent)) {
sound::stop(snd->attack);
sound::play(snd->death); sound::play(snd->death);
} }