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,29 @@
|
||||
#include "game/entities/concrete/floor_trap.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "game/entities/entity_factory.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
|
||||
FloorTrap::FloorTrap(const fkyaml::node& yaml) {
|
||||
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("floor_trap");
|
||||
collides_ = false;
|
||||
interactable_ = false;
|
||||
|
||||
if (yaml.contains("cycle")) {
|
||||
const auto& c = yaml["cycle"];
|
||||
const float ACTIVE = c.contains("active_duration") ? c["active_duration"].get_value<float>() : 0.3F;
|
||||
const float INACTIVE = c.contains("inactive_duration") ? c["inactive_duration"].get_value<float>() : 2.0F;
|
||||
setCycle(ACTIVE, INACTIVE);
|
||||
}
|
||||
if (yaml.contains("stats") && yaml["stats"].contains("damage")) {
|
||||
setDamage(yaml["stats"]["damage"].get_value<int>());
|
||||
}
|
||||
}
|
||||
|
||||
void FloorTrap::onPlayerContact(Player* /*player*/) {
|
||||
if (!isActive()) { return; }
|
||||
if (bus_ != nullptr) { bus_->publish("player_hit", getDamage()); }
|
||||
}
|
||||
|
||||
REGISTER_ENTITY("floor_trap", FloorTrap)
|
||||
Reference in new issue
Block a user