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_});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user