From 0ec1a2548aaea620a9adc2cdabdcdec8d3fe06eb Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 7 May 2026 20:25:23 +0200 Subject: [PATCH] feat(mummy): so mummy_hurt en colpejada de fuet --- CMakeLists.txt | 2 ++ data/audio/sounds/mummy_hurt.wav | Bin 0 -> 8344 bytes data/entities/mummy/mummy.yaml | 3 ++ source/game/entities/concrete/mummy.cpp | 14 ++++++++++ source/game/entities/concrete/mummy.hpp | 2 ++ tests/audio_cache_stubs.cpp | 35 ++++++++++++++++++++++++ 6 files changed, 56 insertions(+) create mode 100644 data/audio/sounds/mummy_hurt.wav create mode 100644 tests/audio_cache_stubs.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 035836c..36200cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -361,6 +361,7 @@ if(BUILD_TESTS) add_executable(test_entities_smoke tests/test_entities_smoke.cpp tests/hole_player_stubs.cpp + tests/audio_cache_stubs.cpp source/core/resources/resource_helper.cpp source/core/resources/resource_pack.cpp source/game/map/map.cpp @@ -389,6 +390,7 @@ if(BUILD_TESTS) tests/test_whip_attack.cpp tests/whip_attack_player_stubs.cpp tests/hole_player_stubs.cpp + tests/audio_cache_stubs.cpp source/core/resources/resource_helper.cpp source/core/resources/resource_pack.cpp source/game/map/map.cpp diff --git a/data/audio/sounds/mummy_hurt.wav b/data/audio/sounds/mummy_hurt.wav new file mode 100644 index 0000000000000000000000000000000000000000..3bd5dcd2e783a72e1517bf46b0c615c919f52be5 GIT binary patch literal 8344 zcmeHJ*HTka6pe2_`U(DuGwO`5KIoGrp$Mon5d>*U5u_Lp3!+FskP?a%=^%DM2!f)5 z1ypPd<1e_@KIh(>adZp{BF^1`bMug#RrWgjWap0U+ufTTj@?^!Z3{gdw|SGp;n;xJ zRzLr z=%~oUhYm(WgolM42n`Jh2@Vbl3UawzPN#D}Y9DH^)E=`UKfinZd}@67?ybJg_7-nl zHMYNm?cD`=xu>!+Po{sjKLHL#gcCs^6ov-TI0}hqOCRTFryoChaA%5WK!^~LqSOG01x>L_AK$)wHaYeX0_abDO_is-tn|DX zlq(qNsVT|F6OSd(BQYr|Qc!4=5<)40Bv2X*))|NZb-BhC7v^T3PC(3HZ)Y2{REoBVryZ?L4Yic2kuZ%j96_XtZ88+HQ5h#O57??y5s7Y5C1on1N-E`Qy-Ky8a8bWvi@E)uy%}4W zgAEgp9wMu~U8>L5tE)U$kyhnHk!1uDtDO)llov=Yv#b5kj##cR1X5znUs(*q)p$z3 zt!4D>E1qfogJ+$jSV>KVqaM)MkjJqbVdgWXGIK@Eb+iFPV^9gLeWNTq-7=} zCS^gc?YpEzgVA4qO2z_PJg;Y_Cw-%Gw!3d)0^@KSZNU)6m4*SP`hpoIjbXHLf8dy- zHS7(WquQezWHm{(%CA|0vHC|pWvE$a&y-|2HmkB!Oi$rvxOaQ75BGO#OOsdb1`fqC zi4Tvp$`9^928c%+2~rVah8Q9hBON3&OFZzXW%K@ddzQV`|NjN$vAwRH18J!;Kka3? z4&-3$@V7+U4U8TBn5e9fxg$R(%)wKTZ%iH;J)AupKDfY8oIiR3nL~&-8Y@6LYZsg! qBL_&^{+R86?SSoo?ZC=ApzaTQwH>e>upO`+upO`+upL;R4txXT|1zEc literal 0 HcmV?d00001 diff --git a/data/entities/mummy/mummy.yaml b/data/entities/mummy/mummy.yaml index ef41d5b..ef1232d 100644 --- a/data/entities/mummy/mummy.yaml +++ b/data/entities/mummy/mummy.yaml @@ -58,3 +58,6 @@ hurt: duration_ms: 600 speed: 60 whippable: true + # So opcional: basename del fitxer dins `data/audio/sounds/`. Es dispara + # un sol cop per fuetada quan la mòmia entra a HURT. Si manca, no sona. + sound: mummy_hurt.wav diff --git a/source/game/entities/concrete/mummy.cpp b/source/game/entities/concrete/mummy.cpp index a53ffa1..ef26502 100644 --- a/source/game/entities/concrete/mummy.cpp +++ b/source/game/entities/concrete/mummy.cpp @@ -8,11 +8,14 @@ #include #include +#include "core/audio/audio.hpp" +#include "core/resources/resource_cache.hpp" #include "game/entities/entity_factory.hpp" #include "game/entities/entity_manager.hpp" #include "game/entities/event_bus.hpp" #include "game/entities/player.hpp" #include "game/map/map.hpp" +#include "utils/defaults.hpp" namespace { @@ -133,6 +136,14 @@ Mummy::Mummy(const fkyaml::node& yaml) if (h.contains("whippable")) { whippable_ = h["whippable"].get_value(); } + // So opcional: el basename val tant de clau al Resource::Cache com de + // path (`Defaults::Paths::AUDIO_SOUNDS_DIR + key`). Mateix patró que + // els sons del Player. Si el camp manca, la clau queda buida i + // `enterHurt` no dispara playSound. + if (h.contains("sound")) { + hurt_config_.sound_key = h["sound"].get_value(); + Resource::Cache::get().loadSound(hurt_config_.sound_key, std::string{Defaults::Paths::AUDIO_SOUNDS_DIR} + hurt_config_.sound_key); + } } } @@ -511,6 +522,9 @@ void Mummy::enterHurt(Direction flee_dir) { state_ = State::HURT; hurt_remaining_s_ = hurt_config_.duration_s; hurt_speed_ = (hurt_config_.speed_px_per_s > 0.0F) ? hurt_config_.speed_px_per_s : speed_; + if (!hurt_config_.sound_key.empty() && Audio::get() != nullptr) { + Audio::get()->playSound(hurt_config_.sound_key, Audio::Group::GAME); + } const Direction CHOSEN = chooseHurtDirection(flee_dir); if (CHOSEN == Direction::NONE) { diff --git a/source/game/entities/concrete/mummy.hpp b/source/game/entities/concrete/mummy.hpp index 15c15d2..c2c246e 100644 --- a/source/game/entities/concrete/mummy.hpp +++ b/source/game/entities/concrete/mummy.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "external/fkyaml_node.hpp" @@ -35,6 +36,7 @@ class Mummy : public DynamicHazard { struct HurtConfig { float duration_s{0.0F}; float speed_px_per_s{0.0F}; + std::string sound_key; // Buit = sense so. El fitxer viu a Defaults::Paths::AUDIO_SOUNDS_DIR. }; explicit Mummy(const fkyaml::node& yaml); diff --git a/tests/audio_cache_stubs.cpp b/tests/audio_cache_stubs.cpp new file mode 100644 index 0000000..aafa42e --- /dev/null +++ b/tests/audio_cache_stubs.cpp @@ -0,0 +1,35 @@ +// Stubs d'`Audio` i `Resource::Cache` per als smokes que enllacen +// entitats amb so propi (`mummy.cpp` carrega + dispara `mummy_hurt.wav`). +// +// Linkar `audio.cpp` i `resource_cache.cpp` arrossegaria SDL_mixer/Ja, +// el sistema de paquets, el carregador de GIFs, etc. — la mateixa +// explosió de dependències que `hole_player_stubs.cpp` evita per al +// Player. Aquests stubs deixen `Audio::get()` retornant `nullptr` +// (els call-sites comprovem aquesta condició abans de tocar el so) i +// fan no-op `Resource::Cache::loadSound`. + +#include "core/audio/audio.hpp" +#include "core/resources/resource_cache.hpp" + +auto Audio::get() -> Audio* { + return nullptr; +} + +void Audio::playSound(const std::string& /*name*/, Audio::Group /*group*/) { +} + +namespace Resource { + + auto Cache::get() -> Cache& { + // Heap-leak deliberat: el destructor de Cache requeriria els + // deleters de Ja::Music/Ja::Sound (a resource_types.cpp) que el + // smoke target no enllaça. Mai destruïm la instància — el procés + // mor abans i el SO recupera la memòria. + static Cache* instance_ = new Cache(); + return *instance_; + } + + void Cache::loadSound(const std::string& /*name*/, const std::string& /*file_path*/) { + } + +} // namespace Resource