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

+13 -3
View File
@@ -222,13 +222,19 @@ void Player::updateFacingAndTurn(float delta_time, float vx, float vy) {
}
}
Player::Player(const std::string& anim_key, float x, float y, const Controls& controls, const Map::Info& map_info, int paint_tile_index)
Player::Player(const std::string& anim_key, int id, float x, float y, const Controls& controls, const Map::Info& map_info, int paint_tile_index)
: AnimatedSprite(Resource::Cache::get().getAnimationData(anim_key)),
id_(id),
controls_(controls),
map_(map_info),
paint_tile_index_(paint_tile_index) {
setPos(x, y);
setCurrentAnimation("stand");
// Postura inicial mirant cap al jugador (cara avall), no de costat:
// forcem facing_ a DOWN i l'animació `stand_down` abans del primer
// frame d'input — el primer `update` la preservarà si l'usuari no
// prem cap tecla.
facing_ = Facing::DOWN;
setCurrentAnimation("stand_down");
}
void Player::update(float delta_time) {
@@ -308,7 +314,11 @@ void Player::update(float delta_time) {
if (COL != last_tile_col_ || ROW != last_tile_row_) {
last_tile_col_ = COL;
last_tile_row_ = ROW;
bus_->publish("on_tile_entered", PaintedTile{.col = COL, .row = ROW, .tile_index = paint_tile_index_});
bus_->publish(Event{
.name = "on_tile_entered",
.payload = PaintedTile{.col = COL, .row = ROW, .tile_index = paint_tile_index_},
.player_id = id_,
});
}
}
}