feat(player): publica PaintedTile amb l'índex de pintat propi
This commit is contained in:
1 parent
87b08a7c7c
commit
0f56ce7567
2 files changed
+17
-7
No files matched your search
@@ -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_});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
};
|
||||
Reference in new issue
Block a user