feat(mummy): so mummy_hurt en colpejada de fuet

This commit is contained in:
JailDesigner committed 2026-05-07 20:25:23 +02:00
1 parent 4ea8ab7b6d
commit 0ec1a2548a
6 files changed
+56

No files matched your search

+2
View File
@@ -361,6 +361,7 @@ if(BUILD_TESTS)
add_executable(test_entities_smoke add_executable(test_entities_smoke
tests/test_entities_smoke.cpp tests/test_entities_smoke.cpp
tests/hole_player_stubs.cpp tests/hole_player_stubs.cpp
tests/audio_cache_stubs.cpp
source/core/resources/resource_helper.cpp source/core/resources/resource_helper.cpp
source/core/resources/resource_pack.cpp source/core/resources/resource_pack.cpp
source/game/map/map.cpp source/game/map/map.cpp
@@ -389,6 +390,7 @@ if(BUILD_TESTS)
tests/test_whip_attack.cpp tests/test_whip_attack.cpp
tests/whip_attack_player_stubs.cpp tests/whip_attack_player_stubs.cpp
tests/hole_player_stubs.cpp tests/hole_player_stubs.cpp
tests/audio_cache_stubs.cpp
source/core/resources/resource_helper.cpp source/core/resources/resource_helper.cpp
source/core/resources/resource_pack.cpp source/core/resources/resource_pack.cpp
source/game/map/map.cpp source/game/map/map.cpp
Binary file not shown.
+3
View File
@@ -58,3 +58,6 @@ hurt:
duration_ms: 600 duration_ms: 600
speed: 60 speed: 60
whippable: true 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
+14
View File
@@ -8,11 +8,14 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "core/audio/audio.hpp"
#include "core/resources/resource_cache.hpp"
#include "game/entities/entity_factory.hpp" #include "game/entities/entity_factory.hpp"
#include "game/entities/entity_manager.hpp" #include "game/entities/entity_manager.hpp"
#include "game/entities/event_bus.hpp" #include "game/entities/event_bus.hpp"
#include "game/entities/player.hpp" #include "game/entities/player.hpp"
#include "game/map/map.hpp" #include "game/map/map.hpp"
#include "utils/defaults.hpp"
namespace { namespace {
@@ -133,6 +136,14 @@ Mummy::Mummy(const fkyaml::node& yaml)
if (h.contains("whippable")) { if (h.contains("whippable")) {
whippable_ = h["whippable"].get_value<bool>(); whippable_ = h["whippable"].get_value<bool>();
} }
// 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<std::string>();
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; state_ = State::HURT;
hurt_remaining_s_ = hurt_config_.duration_s; hurt_remaining_s_ = hurt_config_.duration_s;
hurt_speed_ = (hurt_config_.speed_px_per_s > 0.0F) ? hurt_config_.speed_px_per_s : speed_; 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); const Direction CHOSEN = chooseHurtDirection(flee_dir);
if (CHOSEN == Direction::NONE) { if (CHOSEN == Direction::NONE) {
+2
View File
@@ -3,6 +3,7 @@
#include <climits> #include <climits>
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
#include <string>
#include <vector> #include <vector>
#include "external/fkyaml_node.hpp" #include "external/fkyaml_node.hpp"
@@ -35,6 +36,7 @@ class Mummy : public DynamicHazard {
struct HurtConfig { struct HurtConfig {
float duration_s{0.0F}; float duration_s{0.0F};
float speed_px_per_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); explicit Mummy(const fkyaml::node& yaml);
+35
View File
@@ -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