From 0f56ce7567b23b238855bafda70ac39d82697a26 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 23 Apr 2026 13:19:01 +0200 Subject: [PATCH] =?UTF-8?q?feat(player):=20publica=20PaintedTile=20amb=20l?= =?UTF-8?q?'=C3=ADndex=20de=20pintat=20propi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game/entities/player.cpp | 12 +++++++----- source/game/entities/player.hpp | 12 ++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index dbe5787..fa5a18b 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -73,10 +73,11 @@ void Player::loadFrom(const std::string& yaml_path) { collision_y_offset = (sprite_h - base_size) - collision_padding; } -Player::Player(const std::string& anim_key, float x, float y, const Controls& controls, const Map::Info& map_info) +Player::Player(const std::string& anim_key, float x, float y, const Controls& controls, const Map::Info& map_info, int paint_tile_index) : AnimatedSprite(Resource::Cache::get().getAnimationData(anim_key)), controls_(controls), - map_(map_info) { + map_(map_info), + paint_tile_index_(paint_tile_index) { setPos(x, y); setCurrentAnimation("stand"); } @@ -161,15 +162,16 @@ void Player::update(float delta_time) { // Detecció de canvi de tile. Es calcula *després* del clamp i de les // col·lisions perquè la posició aquí ja és la definitiva del frame; - // així els sarcòfags no reben falsos positius mentre el Player rellisca + // així el PaintLayer no rep falsos positius mentre el Player rellisca // contra una paret. Si el tile ha canviat, publiquem `on_tile_entered` - // al bus; l'EntityManager farà fan-out a notifyTileEntered. + // al bus amb l'índex de pintat d'aquest jugador; el PaintLayer filtra + // pintabilitat i re-publica `tile_painted` als sarcòfags. if (bus_ != nullptr) { const auto [COL, ROW] = getCurrentTile(); if (COL != last_tile_col_ || ROW != last_tile_row_) { last_tile_col_ = COL; last_tile_row_ = ROW; - bus_->publish("on_tile_entered", TilePos{.col = COL, .row = ROW}); + bus_->publish("on_tile_entered", PaintedTile{.col = COL, .row = ROW, .tile_index = paint_tile_index_}); } } } diff --git a/source/game/entities/player.hpp b/source/game/entities/player.hpp index 584c36d..77790f0 100644 --- a/source/game/entities/player.hpp +++ b/source/game/entities/player.hpp @@ -41,7 +41,7 @@ class Player : public AnimatedSprite { // Ha de cridar-se abans d'instanciar Player; GameScene ho fa al ctor. static void loadFrom(const std::string& yaml_path); - Player(const std::string& anim_key, float x, float y, const Controls& controls, const Map::Info& map_info); + Player(const std::string& anim_key, float x, float y, const Controls& controls, const Map::Info& map_info, int paint_tile_index = -1); void update(float delta_time) override; @@ -54,7 +54,9 @@ class Player : public AnimatedSprite { // Injecta el bus del nivell. El Player publica `on_tile_entered` cada // vegada que el centre de la seua caixa de col·lisió entra en una - // cel·la nova del tilemap. Si el bus no s'injecta, no emet res. + // cel·la nova del tilemap, amb payload `PaintedTile{col,row,paint_tile_index_}`. + // El PaintLayer filtra pintabilitat i re-publica `tile_painted` a qui + // correspongui (sarcòfags). Si el bus no s'injecta, no emet res. void setEventBus(EventBus* bus) { bus_ = bus; } // Tile actual del jugador (centre de `baseBox()` convertit a @@ -127,4 +129,10 @@ class Player : public AnimatedSprite { // el primer frame en què el bus estigui connectat ja emeti un event. int last_tile_col_{-9999}; int last_tile_row_{-9999}; + + // Índex de tile del tileset amb què aquest jugador pinta. Llegit del + // YAML del mapa (`player1_paint_tile` / `player2_paint_tile`) i passat + // al ctor per GameScene. -1 desactiva el pintat (p.ex. al test + // d'arrencada o en un escenari que no vulgui feedback visual). + int paint_tile_index_{-1}; };