killing tiles

This commit is contained in:
2026-04-06 22:56:59 +02:00
parent 5c40b9bbf9
commit 6be93da929
4 changed files with 31 additions and 4 deletions

View File

@@ -65,7 +65,12 @@ void Player::update(float delta_time) {
// 5. Detectar caída
checkFalling();
// 6. Finalizar
// 6. Kill tiles
if (room_->getTileCollider().touchesKillTile(x_, y_, WIDTH, HEIGHT)) {
markAsDead();
}
// 7. Finalizar
syncSpriteAndCollider();
animate(delta_time);
border_ = handleBorders();

View File

@@ -15,7 +15,7 @@ auto TileCollider::getTileAt(int tile_x, int tile_y) const -> Tile {
return Tile::EMPTY;
}
int value = tile_map_[tile_y * MW + tile_x];
if (value >= 0 && value <= 4) {
if (value >= 0 && value <= 5) {
return static_cast<Tile>(value);
}
return Tile::EMPTY;
@@ -220,3 +220,22 @@ auto TileCollider::checkSlopeBelow(float x, float foot_y, float w) const -> Slop
return {};
}
// --- Detección de kill tiles ---
// Devuelve true si el rectángulo del jugador solapa algún tile KILL.
auto TileCollider::touchesKillTile(float x, float y, float w, float h) const -> bool {
int top_row = toTile(static_cast<int>(y));
int bot_row = toTile(static_cast<int>(y + h - 1));
int left_col = toTile(static_cast<int>(x));
int right_col = toTile(static_cast<int>(x + w - 1));
for (int row = top_row; row <= bot_row; ++row) {
for (int col = left_col; col <= right_col; ++col) {
if (getTileAt(col, row) == Tile::KILL) {
return true;
}
}
}
return false;
}

View File

@@ -11,7 +11,8 @@ class TileCollider {
WALL = 1,
PASSABLE = 2,
SLOPE_L = 3,
SLOPE_R = 4
SLOPE_R = 4,
KILL = 5
};
struct FloorHit {
@@ -45,9 +46,11 @@ class TileCollider {
[[nodiscard]] auto checkSlopeBelow(float x, float foot_y, float w) const -> SlopeInfo;
// Devuelve true si el jugador está parcialmente dentro de algún tile de slope
// (algún pie está por debajo de la superficie de un slope que solapa)
[[nodiscard]] auto isInsideAnySlope(float x, float foot_y, float w) const -> bool;
// Devuelve true si el rectángulo del jugador solapa algún tile KILL
[[nodiscard]] auto touchesKillTile(float x, float y, float w, float h) const -> bool;
private:
static constexpr int TS = ::Tile::SIZE;
static constexpr int MW = ::Map::WIDTH;