diff --git a/data/tilesets/collision.gif b/data/tilesets/collision.gif index ada22c0..07802bb 100644 Binary files a/data/tilesets/collision.gif and b/data/tilesets/collision.gif differ diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 5272cad..6333c81 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -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(); diff --git a/source/game/gameplay/tile_collider.cpp b/source/game/gameplay/tile_collider.cpp index 8ac870d..a7242ef 100644 --- a/source/game/gameplay/tile_collider.cpp +++ b/source/game/gameplay/tile_collider.cpp @@ -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(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(y)); + int bot_row = toTile(static_cast(y + h - 1)); + int left_col = toTile(static_cast(x)); + int right_col = toTile(static_cast(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; +} diff --git a/source/game/gameplay/tile_collider.hpp b/source/game/gameplay/tile_collider.hpp index 8096013..81dd693 100644 --- a/source/game/gameplay/tile_collider.hpp +++ b/source/game/gameplay/tile_collider.hpp @@ -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;