From 710e7cc8c168d8c3e3e618fa39f79d42028d1aab Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 14 Nov 2025 17:58:32 +0100 Subject: [PATCH] merdetes pa debugar a gust --- .claude/settings.local.json | 3 ++- source/core/input/global_inputs.cpp | 6 +++-- source/core/system/debug.hpp | 20 +++++++------- source/game/entities/player.cpp | 32 ++++++++++++++++------- source/game/gameplay/room.cpp | 13 ++++++--- source/game/gameplay/room.hpp | 3 +++ source/game/gameplay/tilemap_renderer.cpp | 22 ++++++++++++---- source/game/gameplay/tilemap_renderer.hpp | 10 +++++++ source/game/scenes/game.cpp | 22 +++++++++------- 9 files changed, 89 insertions(+), 42 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 5eb388c..d770675 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -10,7 +10,8 @@ "Bash(git add:*)", "Bash(git commit:*)", "Bash(git checkout:*)", - "Bash(sort:*)" + "Bash(sort:*)", + "Bash(cmake:*)" ], "deny": [], "ask": [] diff --git a/source/core/input/global_inputs.cpp b/source/core/input/global_inputs.cpp index 45bb41a..1a33116 100644 --- a/source/core/input/global_inputs.cpp +++ b/source/core/input/global_inputs.cpp @@ -110,10 +110,12 @@ void handleShowDebugInfo() { Screen::get()->toggleDebugInfo(); } +/* void handleToggleDebug() { Debug::get()->toggleEnabled(); - Notifier::get()->show({"DEBUG " + std::string(Debug::get()->getEnabled() ? "ENABLED" : "DISABLED")}, Notifier::TextAlign::CENTER); + Notifier::get()->show({"DEBUG " + std::string(Debug::get()->isEnabled() ? "ENABLED" : "DISABLED")}, Notifier::TextAlign::CENTER); } +*/ #endif // Detecta qué acción global ha sido presionada (si alguna) @@ -216,7 +218,7 @@ void handle() { break; case InputAction::TOGGLE_DEBUG: - handleToggleDebug(); + //handleToggleDebug(); break; case InputAction::SHOW_DEBUG_INFO: diff --git a/source/core/system/debug.hpp b/source/core/system/debug.hpp index 8538a04..4652b90 100644 --- a/source/core/system/debug.hpp +++ b/source/core/system/debug.hpp @@ -8,22 +8,22 @@ // Clase Debug class Debug { public: - static void init(); // [SINGLETON] Crearemos el objeto con esta función estática - static void destroy(); // [SINGLETON] Destruiremos el objeto con esta función estática - static auto get() -> Debug*; // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él + static void init(); // [SINGLETON] Crearemos el objeto con esta función estática + static void destroy(); // [SINGLETON] Destruiremos el objeto con esta función estática + static auto get() -> Debug*; // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él void render(); // Dibuja en pantalla void setPos(SDL_FPoint p); // Establece la posición donde se colocará la información de debug - [[nodiscard]] auto getEnabled() const -> bool { return enabled_; } // Obtiene si el debug está activo + [[nodiscard]] auto isEnabled() const -> bool { return enabled_; } // Obtiene si el debug está activo - void add(const std::string& text) { slot_.push_back(text); } // Añade texto al slot de debug - void clear() { slot_.clear(); } // Limpia el slot de debug - void addToLog(const std::string& text) { log_.push_back(text); } // Añade texto al log - void clearLog() { log_.clear(); } // Limpia el log - void setEnabled(bool value) { enabled_ = value; } // Establece si el debug está activo - void toggleEnabled() { enabled_ = !enabled_; } // Alterna el estado del debug + void add(const std::string& text) { slot_.push_back(text); } // Añade texto al slot de debug + void clear() { slot_.clear(); } // Limpia el slot de debug + void addToLog(const std::string& text) { log_.push_back(text); } // Añade texto al log + void clearLog() { log_.clear(); } // Limpia el log + void setEnabled(bool value) { enabled_ = value; } // Establece si el debug está activo + void toggleEnabled() { enabled_ = !enabled_; } // Alterna el estado del debug private: static Debug* debug; // [SINGLETON] Objeto privado diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index a55d06b..e7fa8b0 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -14,6 +14,10 @@ #include "game/options.hpp" // Para Cheat, Options, options #include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT +#ifdef _DEBUG +#include "core/system/debug.hpp" // Para Debug +#endif + // Constructor Player::Player(const Data& player) : room_(player.room) { @@ -29,7 +33,12 @@ Player::Player(const Data& player) // Pinta el jugador en pantalla void Player::render() { sprite_->render(1, color_); - Screen::get()->getRendererSurface()->putPixel(under_right_foot_.x, under_right_foot_.y, 6); +#ifdef _DEBUG + if (Debug::get()->isEnabled()) { + Screen::get()->getRendererSurface()->putPixel(under_right_foot_.x, under_right_foot_.y, static_cast(PaletteColor::GREEN)); + Screen::get()->getRendererSurface()->putPixel(under_left_foot_.x, under_left_foot_.y, static_cast(PaletteColor::GREEN)); + } +#endif } // Actualiza las variables del objeto @@ -104,7 +113,7 @@ void Player::transitionToState(State state) { fall_sound_ctrl_.reset(); current_slope_ = nullptr; break; - case State::ON_SLOPE: + case State::ON_SLOPE: std::cout << "ON_SLOPE\n"; vy_ = 0; handleDeathByFalling(); @@ -285,7 +294,7 @@ void Player::moveOnSlope(float delta_time) { } // Ajustar la posición Y del jugador (restar HEIGHT porque foot_y es la posición del pie) - y_ = foot_y - HEIGHT; + 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 @@ -296,16 +305,16 @@ void Player::moveOnSlope(float delta_time) { 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); + (FOOT_X < current_slope_->x1 && !IS_LEFT_SLOPE); if (EXITING_DOWNWARD) { // Salida por abajo: bajar 1 pixel para ayudar detección de suelo - y_ += 1.0F; + // 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; + // current_slope_ = nullptr; // Verificar si hay soporte debajo (suelo plano, conveyor belt, u otra slope) if (isOnFloor()) { @@ -591,13 +600,13 @@ auto Player::isOnSlope() -> bool { // Verificar si cada pie está "volando" (sin soporte: ni top surface ni conveyor belt) const bool LEFT_FOOT_FLYING = !(room_->checkTopSurfaces(under_left_foot_) || - room_->checkConveyorBelts(under_left_foot_)); + room_->checkConveyorBelts(under_left_foot_)); const bool RIGHT_FOOT_FLYING = !(room_->checkTopSurfaces(under_right_foot_) || - room_->checkConveyorBelts(under_right_foot_)); + room_->checkConveyorBelts(under_right_foot_)); // Retornar true si UN pie en rampa Y el OTRO volando return (LEFT_FOOT_ON_LEFT_SLOPE && RIGHT_FOOT_FLYING) || - (RIGHT_FOOT_ON_RIGHT_SLOPE && LEFT_FOOT_FLYING); + (RIGHT_FOOT_ON_RIGHT_SLOPE && LEFT_FOOT_FLYING); } // Comprueba si current_slope_ es una rampa izquierda (ascendente a la izquierda) @@ -614,7 +623,7 @@ auto Player::isLeftSlope() -> bool { // Actualiza current_slope_ con la rampa correcta según el pie que toca void Player::updateCurrentSlope() { updateFeet(); - + // Left slopes (\) ascendentes a izquierda tocan el pie izquierdo if (room_->checkLeftSlopes(under_left_foot_)) { current_slope_ = room_->getSlopeAtPoint(under_left_foot_); @@ -809,6 +818,9 @@ void Player::syncSpriteAndCollider() { placeSprite(); // Coloca el sprite en la posición del jugador collider_box_ = getRect(); // Actualiza el rectangulo de colisión updateColliderPoints(); // Actualiza los puntos de colisión +#ifdef _DEBUG + updateFeet(); +#endif } // Coloca el sprite en la posición del jugador diff --git a/source/game/gameplay/room.cpp b/source/game/gameplay/room.cpp index 425502e..37743f3 100644 --- a/source/game/gameplay/room.cpp +++ b/source/game/gameplay/room.cpp @@ -10,8 +10,8 @@ #include "game/gameplay/item_manager.hpp" // Para ItemManager #include "game/gameplay/item_tracker.hpp" // Para ItemTracker #include "game/gameplay/room_loader.hpp" // Para RoomLoader -#include "game/gameplay/tilemap_renderer.hpp" // Para TilemapRenderer #include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data +#include "game/gameplay/tilemap_renderer.hpp" // Para TilemapRenderer #include "utils/defines.hpp" // Para TILE_SIZE #include "utils/utils.hpp" // Para stringToColor @@ -32,8 +32,7 @@ Room::Room(const std::string& room_path, std::shared_ptr data) openTheJail(); // Abre la Jail si se da el caso // Crea el renderizador del tilemap (necesita tile_map_, tile_set_width_, surface_, bg_color_, conveyor_belt_direction_) - tilemap_renderer_ = std::make_unique(tile_map_, tile_set_width_, surface_, bg_color_, - conveyor_belt_direction_); + tilemap_renderer_ = std::make_unique(tile_map_, tile_set_width_, surface_, bg_color_, conveyor_belt_direction_); tilemap_renderer_->initialize(collision_map_.get()); // Inicializa (crea map_surface, pinta tiles, busca animados) Screen::get()->setBorderColor(stringToColor(border_color_)); // Establece el color del borde @@ -118,6 +117,13 @@ void Room::renderItems() { item_manager_->render(); } +#ifdef _DEBUG +// Redibuja el mapa (para actualizar modo debug) +void Room::redrawMap() { + tilemap_renderer_->redrawMap(collision_map_.get()); +} +#endif + // Actualiza las variables y objetos de la habitación void Room::update(float delta_time) { if (is_paused_) { @@ -251,7 +257,6 @@ auto Room::getSlopeAtPoint(const SDL_FPoint& p) const -> const LineDiagonal* { return collision_map_->getSlopeAtPoint(p); } - // Carga las variables desde un fichero de mapa (delegado a RoomLoader) auto Room::loadRoomFile(const std::string& file_path, bool verbose) -> Data { return RoomLoader::loadRoomFile(file_path, verbose); diff --git a/source/game/gameplay/room.hpp b/source/game/gameplay/room.hpp index 75494d9..ee5feac 100644 --- a/source/game/gameplay/room.hpp +++ b/source/game/gameplay/room.hpp @@ -67,6 +67,9 @@ class Room { void renderMap(); // Dibuja el mapa en pantalla void renderEnemies(); // Dibuja los enemigos en pantalla void renderItems(); // Dibuja los objetos en pantalla +#ifdef _DEBUG + void redrawMap(); // Redibuja el mapa (para actualizar modo debug) +#endif void update(float delta_time); // Actualiza las variables y objetos de la habitación auto getRoom(Border border) -> std::string; // Devuelve la cadena del fichero de la habitación contigua segun el borde auto getTile(SDL_FPoint point) -> Tile; // Devuelve el tipo de tile que hay en ese pixel diff --git a/source/game/gameplay/tilemap_renderer.cpp b/source/game/gameplay/tilemap_renderer.cpp index 5952ae6..1f86970 100644 --- a/source/game/gameplay/tilemap_renderer.cpp +++ b/source/game/gameplay/tilemap_renderer.cpp @@ -8,9 +8,7 @@ #include "utils/utils.hpp" // Constructor -TilemapRenderer::TilemapRenderer(std::vector tile_map, int tile_set_width, - std::shared_ptr tileset_surface, std::string bg_color, - int conveyor_belt_direction) +TilemapRenderer::TilemapRenderer(std::vector tile_map, int tile_set_width, std::shared_ptr tileset_surface, std::string bg_color, int conveyor_belt_direction) : tile_map_(std::move(tile_map)), tile_set_width_(tile_set_width), tileset_surface_(std::move(tileset_surface)), @@ -47,7 +45,7 @@ void TilemapRenderer::render() { // Dibuja los tiles animados #ifdef _DEBUG - if (!Debug::get()->getEnabled()) { + if (!Debug::get()->isEnabled()) { renderAnimatedTiles(); } #else @@ -55,6 +53,13 @@ void TilemapRenderer::render() { #endif } +#ifdef _DEBUG +// Redibuja el tilemap (para actualizar modo debug) +void TilemapRenderer::redrawMap(const CollisionMap* collision_map) { + fillMapTexture(collision_map); +} +#endif + // Pinta el mapa estático y debug lines void TilemapRenderer::fillMapTexture(const CollisionMap* collision_map) { const Uint8 COLOR = stringToColor(bg_color_); @@ -77,13 +82,20 @@ void TilemapRenderer::fillMapTexture(const CollisionMap* collision_map) { if (B && !A) { clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE; clip.y = (tile_map_[INDEX] / tile_set_width_) * TILE_SIZE; +#ifdef _DEBUG + if (!Debug::get()->isEnabled()) { + tileset_surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip); + } +#else tileset_surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip); +#endif } } } #ifdef _DEBUG - if (Debug::get()->getEnabled()) { + // Pinta las superficies en el modo debug + if (Debug::get()->isEnabled()) { auto surface = Screen::get()->getRendererSurface(); // BottomSurfaces diff --git a/source/game/gameplay/tilemap_renderer.hpp b/source/game/gameplay/tilemap_renderer.hpp index 99741cc..7494734 100644 --- a/source/game/gameplay/tilemap_renderer.hpp +++ b/source/game/gameplay/tilemap_renderer.hpp @@ -60,6 +60,16 @@ class TilemapRenderer { */ void render(); +#ifdef _DEBUG + /** + * @brief Redibuja el tilemap (para actualizar modo debug) + * @param collision_map Mapa de colisiones para dibujar líneas de debug + * + * Llamado cuando se activa/desactiva el modo debug para actualizar la visualización + */ + void redrawMap(const CollisionMap* collision_map); +#endif + /** * @brief Activa/desactiva modo pausa * @param paused true para pausar, false para reanudar diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index a511365..f125106 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -190,7 +190,7 @@ void Game::updateDebugInfo() { // Pone la información de debug en pantalla void Game::renderDebugInfo() { - if (!Debug::get()->getEnabled()) { + if (!Debug::get()->isEnabled()) { return; } @@ -221,34 +221,36 @@ void Game::renderDebugInfo() { void Game::handleDebugEvents(const SDL_Event& event) { if (event.type == SDL_EVENT_KEY_DOWN && static_cast(event.key.repeat) == 0) { switch (event.key.key) { - case SDL_SCANCODE_G: + case SDLK_F12: Debug::get()->toggleEnabled(); - Options::cheats.invincible = static_cast(Debug::get()->getEnabled()); - board_->music = !Debug::get()->getEnabled(); + 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()); + board_->music = !Debug::get()->isEnabled(); board_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic(); break; - case SDL_SCANCODE_R: + case SDLK_R: Resource::Cache::get()->reload(); break; - case SDL_SCANCODE_W: + case SDLK_W: changeRoom(room_->getRoom(Room::Border::TOP)); break; - case SDL_SCANCODE_A: + case SDLK_A: changeRoom(room_->getRoom(Room::Border::LEFT)); break; - case SDL_SCANCODE_S: + case SDLK_S: changeRoom(room_->getRoom(Room::Border::BOTTOM)); break; - case SDL_SCANCODE_D: + case SDLK_D: changeRoom(room_->getRoom(Room::Border::RIGHT)); break; - case SDL_SCANCODE_7: + case SDLK_7: Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, Notifier::TextAlign::CENTER, Notifier::DURATION_CHEEVO, -1, false, "F7"); break;