From e4c10b6b752e9f224a7f182ce056303664af54d7 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 15 Nov 2025 22:45:18 +0100 Subject: [PATCH] =?UTF-8?q?ACABADA=20LA=20LOGICA=20DE=20PLAYER!=20es=20pot?= =?UTF-8?q?=20refactoritzar=20i=20falta=20els=20casos=20on=20Player=20puga?= =?UTF-8?q?=20avan=C3=A7ar=20mes=20de=20un=20pixel=20en=20un=20frame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game/entities/player.cpp | 47 +++++++++++++++++---------------- source/game/scenes/game.cpp | 1 + 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index e7fa8b0..1707f2f 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -82,6 +82,8 @@ void Player::move(float delta_time) { break; } syncSpriteAndCollider(); // Actualiza la posición del sprite y las colisiones + Debug::get()->add(std::string("X: " + std::to_string(static_cast(x_)))); + Debug::get()->add(std::string("Y: " + std::to_string(static_cast(y_)))); } void Player::handleConveyorBelts() { @@ -237,6 +239,9 @@ void Player::moveOnGround(float delta_time) { y_ = SLOPE_Y - HEIGHT; transitionToState(State::ON_SLOPE); } + + // Comprueba si está sobre una rampa + if (isOnSlope()) { transitionToState(State::ON_SLOPE); } } // Movimiento físico del estado ON_SLOPE @@ -275,50 +280,46 @@ void Player::moveOnSlope(float delta_time) { } } - // Actualizar posición de los pies para cálculos - updateFeet(); - // Seleccionar el pie apropiado según el tipo de rampa // Left slopes (forma \) colisionan con el pie izquierdo // Right slopes (forma /) colisionan con el pie derecho - const float FOOT_X = IS_LEFT_SLOPE ? under_left_foot_.x : under_right_foot_.x; + const int X = IS_LEFT_SLOPE ? x_ : x_ + WIDTH - 1; - // Calcular la Y del pie basado en la ecuación de la rampa (45 grados) + // Calcular la Y basada en la ecuación de la rampa (45 grados) // Left slope (\): y aumenta con x -> y = y1 + (x - x1) // Right slope (/): y disminuye con x -> y = y1 - (x - x1) - float foot_y = 0.0F; if (IS_LEFT_SLOPE) { - foot_y = current_slope_->y1 + (FOOT_X - current_slope_->x1); + y_ = current_slope_->y1 + (X - current_slope_->x1) - HEIGHT; } else { - foot_y = current_slope_->y1 - (FOOT_X - current_slope_->x1); + y_ = current_slope_->y1 - (X - current_slope_->x1) - HEIGHT; } - // Ajustar la posición Y del jugador (restar HEIGHT porque foot_y es la posición del pie) - y_ = foot_y - HEIGHT + 1; - // Verificar si el pie ha salido de los límites horizontales de la rampa // Usar min/max porque LEFT slopes tienen x1x2 const int MIN_X = std::min(current_slope_->x1, current_slope_->x2); const int MAX_X = std::max(current_slope_->x1, current_slope_->x2); - const bool OUT_OF_BOUNDS = (FOOT_X < MIN_X) || (FOOT_X > MAX_X); + const bool OUT_OF_BOUNDS = (X < MIN_X) || (X > MAX_X); if (OUT_OF_BOUNDS) { // Determinar si estamos saliendo por arriba o por abajo de la rampa - const bool EXITING_DOWNWARD = (FOOT_X > current_slope_->x2 && IS_LEFT_SLOPE) || - (FOOT_X < current_slope_->x1 && !IS_LEFT_SLOPE); + const bool EXITING_DOWNWARD = (X > current_slope_->x2 && IS_LEFT_SLOPE) || + (X < current_slope_->x1 && !IS_LEFT_SLOPE); + const bool EXITING_UPWARD = (X < current_slope_->x1 && IS_LEFT_SLOPE) || + (X > current_slope_->x2 && !IS_LEFT_SLOPE); if (EXITING_DOWNWARD) { - // Salida por abajo: bajar 1 pixel para ayudar detección de suelo + // Salida por abajo: no hacer nada // y_ += 1.0F; } - // Si sale por arriba, mantener altura (ya está en foot_y - HEIGHT) - // El jugador ya no está en la rampa, limpiar referencia - // current_slope_ = nullptr; + if (EXITING_UPWARD) { + // Salida por arriba: bajar un pixel ya que ha subido 1 de mas al salirse de la recta + y_ += 1.0F; + } - // Verificar si hay soporte debajo (suelo plano, conveyor belt, u otra slope) - if (isOnFloor()) { - // Hay soporte: transición a ON_GROUND (podría ser superficie, conveyor u otra rampa) + // Verificar si hay soporte debajo (suelo plano o conveyor belt) + if (isOnTopSurface() || isOnConveyorBelt()) { + // Hay soporte: transición a ON_GROUND (podría ser superficie o conveyor belt) transitionToState(State::ON_GROUND); } else { // Sin soporte: empezar a caer @@ -328,10 +329,10 @@ void Player::moveOnSlope(float delta_time) { } // Verificar transición a superficie plana - if (isOnTopSurface()) { + /*if (isOnTopSurface()) { transitionToState(State::ON_GROUND); return; - } + }*/ } // Movimiento físico del estado JUMPING diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index f125106..85a6394 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -226,6 +226,7 @@ void Game::handleDebugEvents(const SDL_Event& event) { Notifier::get()->show({"DEBUG " + std::string(Debug::get()->isEnabled() ? "ENABLED" : "DISABLED")}, Notifier::TextAlign::CENTER); room_->redrawMap(); // Redibuja el tilemap para mostrar/ocultar líneas de colisión Options::cheats.invincible = static_cast(Debug::get()->isEnabled()); + player_->setColor(); board_->music = !Debug::get()->isEnabled(); board_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic(); break;