From 00eb696859f021de93e10a66904202f5d3d6a0e9 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 23 Apr 2026 13:15:08 +0200 Subject: [PATCH] feat(map): afegeix Map::isPaintable(col, row) --- source/game/map/map.cpp | 17 +++++++++++++++++ source/game/map/map.hpp | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/source/game/map/map.cpp b/source/game/map/map.cpp index 32c417a..12c1048 100644 --- a/source/game/map/map.cpp +++ b/source/game/map/map.cpp @@ -106,6 +106,23 @@ namespace Map { return box.x >= static_cast(playfield_x) && box.y >= static_cast(playfield_y) && box.x + box.w <= static_cast(playfield_x + playfield_w) && box.y + box.h <= static_cast(playfield_y + playfield_h); } + auto isPaintable(int col, int row) -> bool { + // Construïm la caixa píxel del tile a partir de l'origen del tilemap. + // El grid és 16-alineat respecte a `tilemap_origin_*`; per a un tile + // (col,row) la cantonada superior-esquerra cau a: + // x = tilemap_origin_x + col * tile_size + // y = tilemap_origin_y + row * tile_size + const SDL_FRect BOX{ + .x = static_cast(tilemap_origin_x + (col * tile_size)), + .y = static_cast(tilemap_origin_y + (row * tile_size)), + .w = static_cast(tile_size), + .h = static_cast(tile_size), + }; + if (!insidePlayfield(BOX)) { return false; } + if (collides(BOX)) { return false; } + return true; + } + auto makeInfo() -> Info { return { .playfield_x = playfield_x, diff --git a/source/game/map/map.hpp b/source/game/map/map.hpp index 7b10d24..895469f 100644 --- a/source/game/map/map.hpp +++ b/source/game/map/map.hpp @@ -81,6 +81,12 @@ namespace Map { // entitats dinàmiques per validar posicions candidates del seu step. [[nodiscard]] auto insidePlayfield(const SDL_FRect& box) -> bool; + // true si el tile (col, row) — coordenades del tilemap, amb origen + // `tilemap_origin_*` — és "sòl transitable" i per tant pintable: cau + // completament dins del playfield i no s'encavalca cap sarcòfag. Ho + // usa el `PaintLayer` per filtrar quines cel·les accepten pintat. + [[nodiscard]] auto isPaintable(int col, int row) -> bool; + // Snapshot plà de la geometria del mapa + punters a `collides` / // `insidePlayfield`. Pensat per ser passat per valor (POD petit, // trivialment copiable). Un cop construïda, llegeix els valors