30 lines
1.0 KiB
C++
30 lines
1.0 KiB
C++
#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)
|