From 6be93da92922230f0af32f8b23afc5f1012c9581 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 6 Apr 2026 22:56:59 +0200 Subject: [PATCH] killing tiles --- data/tilesets/collision.gif | Bin 404 -> 415 bytes source/game/entities/player.cpp | 7 ++++++- source/game/gameplay/tile_collider.cpp | 21 ++++++++++++++++++++- source/game/gameplay/tile_collider.hpp | 7 +++++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/data/tilesets/collision.gif b/data/tilesets/collision.gif index ada22c05f5e0e9059ddc568f780e9d21c18aff50..07802bb29f59add5b937ba208268b8001bc34397 100644 GIT binary patch delta 195 zcmV;!06hPc1D^v2M@dFFH(@}L2j+i300;m82B|=Ra438jk4A}dsr)#f(CCLptx~1f zCz1F7biWS?Kunf=RI7B_sZOh=ynsA#RR`9e^nJY@8ohvFWMgAzdw45zDsORfay)s7 zdu)?M@dFFH(@xD2j+h`00;m82A)8Ga438jk4A}dsr)#f(CCLptx{ju zES5-o0KDLb1TZd3KB|>k?Odx>Q(j;mxB_1HJDytvf4@p(f@dlLZf$fbaB_5WJX?5? zd_{j@WrKtPX>1=WhJ}lDj&+iedwfQffR|-xnwyAoic^h_ka?$EewKq|nRF;Ch>DtV mjdrEEUAwEjgo@8j&(KtLa#y8!lSoKROj6%ZR#sYCK>$0a6HW90 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;