feat(players): suport del segon jugador amb events amb player_id

This commit is contained in:
JailDesigner committed 2026-04-24 14:33:52 +02:00
1 parent 74dad71cc2
commit 4e9d5df872
21 files changed
+309 -49

No files matched your search

+9 -2
View File
@@ -5,6 +5,7 @@
#include "game/entities/entity_factory.hpp"
#include "game/entities/event_bus.hpp"
#include "game/entities/player.hpp"
namespace {
@@ -63,9 +64,15 @@ void Door::update(float delta_time) {
}
}
void Door::onPlayerContact(Player* /*player*/) {
void Door::onPlayerContact(Player* player) {
if (state_ != State::OPEN || level_complete_emitted_) { return; }
if (bus_ != nullptr) { bus_->publish("level_complete"); }
if (bus_ != nullptr) {
bus_->publish(Event{
.name = "level_complete",
.payload = std::monostate{},
.player_id = (player != nullptr) ? player->getId() : -1,
});
}
level_complete_emitted_ = true;
}
+9 -2
View File
@@ -4,6 +4,7 @@
#include "game/entities/entity_factory.hpp"
#include "game/entities/event_bus.hpp"
#include "game/entities/player.hpp"
FloorTrap::FloorTrap(const fkyaml::node& yaml) {
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("floor_trap");
@@ -21,9 +22,15 @@ FloorTrap::FloorTrap(const fkyaml::node& yaml) {
}
}
void FloorTrap::onPlayerContact(Player* /*player*/) {
void FloorTrap::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("floor_trap", FloorTrap)
+9 -2
View File
@@ -9,6 +9,7 @@
#include "game/entities/entity_factory.hpp"
#include "game/entities/event_bus.hpp"
#include "game/entities/player.hpp"
#include "game/map/map.hpp"
namespace {
@@ -294,8 +295,14 @@ void Mummy::applyChoice(Direction dir) {
}
}
void Mummy::onPlayerContact(Player* /*player*/) {
if (bus_ != nullptr) { bus_->publish("player_hit", getDamage()); }
void Mummy::onPlayerContact(Player* player) {
if (bus_ != nullptr) {
bus_->publish(Event{
.name = "player_hit",
.payload = getDamage(),
.player_id = (player != nullptr) ? player->getId() : -1,
});
}
}
REGISTER_ENTITY("mummy", Mummy)
@@ -4,6 +4,7 @@
#include "game/entities/entity_factory.hpp"
#include "game/entities/event_bus.hpp"
#include "game/entities/player.hpp"
#include "game/map/map.hpp"
namespace {
@@ -60,8 +61,14 @@ void RollingRock::step(float delta_time) {
setDirection(0.0F, 0.0F);
}
void RollingRock::onPlayerContact(Player* /*player*/) {
if (bus_ != nullptr) { bus_->publish("player_hit", getDamage()); }
void RollingRock::onPlayerContact(Player* player) {
if (bus_ != nullptr) {
bus_->publish(Event{
.name = "player_hit",
.payload = getDamage(),
.player_id = (player != nullptr) ? player->getId() : -1,
});
}
}
REGISTER_ENTITY("rolling_rock", RollingRock)
+9 -2
View File
@@ -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)