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,49 @@
|
||||
#include "game/entities/concrete/rolling_rock.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "game/entities/entity_factory.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
// Tradueix la direcció inicial textual del YAML a un vector 2D. Valors
|
||||
// no reconeguts → sense moviment (útil per spawn estàtics a tests).
|
||||
void applyInitialDirection(const std::string& dir, DynamicHazard& rock) {
|
||||
if (dir == "right") {
|
||||
rock.setDirection(1.0F, 0.0F);
|
||||
} else if (dir == "left") {
|
||||
rock.setDirection(-1.0F, 0.0F);
|
||||
} else if (dir == "up") {
|
||||
rock.setDirection(0.0F, -1.0F);
|
||||
} else if (dir == "down") {
|
||||
rock.setDirection(0.0F, 1.0F);
|
||||
} else {
|
||||
rock.setDirection(0.0F, 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
RollingRock::RollingRock(const fkyaml::node& yaml) {
|
||||
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("rolling_rock");
|
||||
collides_ = true;
|
||||
interactable_ = false;
|
||||
|
||||
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>()); }
|
||||
}
|
||||
std::string initial = "right";
|
||||
if (yaml.contains("ai") && yaml["ai"].contains("initial_direction")) {
|
||||
initial = yaml["ai"]["initial_direction"].get_value<std::string>();
|
||||
}
|
||||
applyInitialDirection(initial, *this);
|
||||
}
|
||||
|
||||
void RollingRock::onPlayerContact(Player* /*player*/) {
|
||||
if (bus_ != nullptr) { bus_->publish("player_hit", getDamage()); }
|
||||
}
|
||||
|
||||
REGISTER_ENTITY("rolling_rock", RollingRock)
|
||||
Reference in new issue
Block a user