feat(players): suport del segon jugador amb events amb player_id
This commit is contained in:
1 parent
74dad71cc2
commit
4e9d5df872
21 files changed
+309
-49
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "game/entities/entity_factory.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
#include "game/entities/player.hpp"
|
||||
|
||||
WallTrap::WallTrap(const fkyaml::node& yaml) {
|
||||
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("wall_trap");
|
||||
@@ -21,9 +22,15 @@ WallTrap::WallTrap(const fkyaml::node& yaml) {
|
||||
}
|
||||
}
|
||||
|
||||
void WallTrap::onPlayerContact(Player* /*player*/) {
|
||||
void WallTrap::onPlayerContact(Player* player) {
|
||||
if (!isActive()) { return; }
|
||||
if (bus_ != nullptr) { bus_->publish("player_hit", getDamage()); }
|
||||
if (bus_ != nullptr) {
|
||||
bus_->publish(Event{
|
||||
.name = "player_hit",
|
||||
.payload = getDamage(),
|
||||
.player_id = (player != nullptr) ? player->getId() : -1,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_ENTITY("wall_trap", WallTrap)
|
||||
Reference in new issue
Block a user