From 9ebf259525d8393753257bd75591b569e7d42e21 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 8 Mar 2026 14:46:00 +0100 Subject: [PATCH] fix: hack per a poder entrar en huecos de dos tiles d'altura al saltar fix: calcul incorrecte del offset dels tiles que maten --- source/game/defaults.hpp | 6 +++--- source/game/entities/player.cpp | 10 +++++++--- source/game/gameplay/collision_map.cpp | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/game/defaults.hpp b/source/game/defaults.hpp index 3b39f5d9..ebb21e70 100644 --- a/source/game/defaults.hpp +++ b/source/game/defaults.hpp @@ -100,7 +100,7 @@ namespace Game { namespace Room { #ifdef _DEBUG - constexpr const char* INITIAL = "51.yaml"; // Habitación de inicio en debug + constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio en debug #else constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio en release #endif @@ -108,8 +108,8 @@ namespace Room { namespace Player { #ifdef _DEBUG - constexpr int SPAWN_X = 28 * Tile::SIZE; // Posición X inicial en debug - constexpr int SPAWN_Y = 10 * Tile::SIZE; // Posición Y inicial en debug + constexpr int SPAWN_X = 26 * Tile::SIZE; // Posición X inicial en debug + constexpr int SPAWN_Y = 13 * Tile::SIZE; // Posición Y inicial en debug constexpr SDL_FlipMode SPAWN_FLIP = Flip::LEFT; // Orientación inicial en debug #else constexpr int SPAWN_X = 25 * Tile::SIZE; // Posición X inicial en release diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 52dc2827..7055de59 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -47,6 +47,7 @@ void Player::update(float delta_time) { handleInput(); updateState(delta_time); move(delta_time); + handleKillingTiles(); // Los collider_points_ están actualizados por syncSpriteAndCollider() dentro de move() animate(delta_time); border_ = handleBorders(); } @@ -349,7 +350,10 @@ void Player::moveJumping(float delta_time) { handleLandingFromAir(DISPLACEMENT_Y, PROJECTION); } else { // Comprueba la colisión con las superficies y las cintas transportadoras (sin rampas) - const float POS = std::max(room_->checkTopSurfaces(PROJECTION), room_->checkAutoSurfaces(PROJECTION)); + // Extendemos 1px hacia arriba para detectar suelos traversados ligeramente al + // entrar horizontalmente (consecuencia del margen h=HEIGHT-1 en la proyección horizontal) + const SDL_FRect ADJ = {PROJECTION.x, PROJECTION.y - 1.0F, PROJECTION.w, PROJECTION.h + 1.0F}; + const float POS = std::max(room_->checkTopSurfaces(ADJ), room_->checkAutoSurfaces(ADJ)); if (POS != Collision::NONE) { // Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie y_ = POS - HEIGHT; @@ -868,14 +872,14 @@ auto Player::getProjection(Direction direction, float displacement) -> SDL_FRect .x = x_ + displacement, .y = y_, .w = std::ceil(std::fabs(displacement)), // Para evitar que tenga una anchura de 0 pixels - .h = HEIGHT}; + .h = HEIGHT - 1}; // -1 para dar ventana de 2px en aperturas de altura exacta case Direction::RIGHT: return { .x = x_ + WIDTH, .y = y_, .w = std::ceil(displacement), // Para evitar que tenga una anchura de 0 pixels - .h = HEIGHT}; + .h = HEIGHT - 1}; // -1 para dar ventana de 2px en aperturas de altura exacta case Direction::UP: return { diff --git a/source/game/gameplay/collision_map.cpp b/source/game/gameplay/collision_map.cpp index 2f2c653f..a4127a3c 100644 --- a/source/game/gameplay/collision_map.cpp +++ b/source/game/gameplay/collision_map.cpp @@ -29,7 +29,9 @@ void CollisionMap::initializeSurfaces() { // Devuelve el tipo de tile que hay en ese pixel auto CollisionMap::getTile(SDL_FPoint point) const -> Tile { - const int POS = ((point.y / TILE_SIZE) * MAP_WIDTH) + (point.x / TILE_SIZE); + const int row = static_cast(point.y / TILE_SIZE); + const int col = static_cast(point.x / TILE_SIZE); + const int POS = row * MAP_WIDTH + col; return getTile(POS); }