feat(entities): andamiatge del sistema d'entitats (classes, factory, bus, YAML, placeholders, smoke tests)
This commit is contained in:
1 parent
984cc820c0
commit
96b71b0f65
48 files changed
+1957
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#include "game/entities/concrete/mummy.hpp"
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "game/entities/entity_factory.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
// RNG local al mòdul: compartit per totes les mòmies (no cal reproducció
|
||||
// determinista a l'andamiatge). Es reinicialitza amb una llavor fixa
|
||||
// per facilitar la depuració — si algun dia volem aleatoritat real,
|
||||
// llegir-la de std::random_device.
|
||||
auto rng() -> std::mt19937& {
|
||||
static std::mt19937 k_rng_{1337};
|
||||
return k_rng_;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Mummy::Mummy(const fkyaml::node& yaml) {
|
||||
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("mummy");
|
||||
collides_ = true;
|
||||
interactable_ = false;
|
||||
|
||||
// Velocitat i dany des del bloc `stats` (si existeix).
|
||||
if (yaml.contains("stats")) {
|
||||
const auto& s = yaml["stats"];
|
||||
if (s.contains("speed")) { setSpeed(s["speed"].get_value<float>()); }
|
||||
if (s.contains("damage")) { setDamage(s["damage"].get_value<int>()); }
|
||||
}
|
||||
}
|
||||
|
||||
auto Mummy::chooseDirection(const std::vector<Direction>& allowed) -> Direction {
|
||||
if (allowed.empty()) { return Direction::NONE; }
|
||||
std::uniform_int_distribution<std::size_t> dist(0, allowed.size() - 1);
|
||||
return allowed[dist(rng())];
|
||||
}
|
||||
|
||||
void Mummy::onPlayerContact(Player* /*player*/) {
|
||||
if (bus_ != nullptr) { bus_->publish("player_hit", getDamage()); }
|
||||
}
|
||||
|
||||
REGISTER_ENTITY("mummy", Mummy)
|
||||
Reference in new issue
Block a user