merdetes pa debugar a gust

This commit is contained in:
2025-11-14 17:58:32 +01:00
parent 8893e8f05b
commit 710e7cc8c1
9 changed files with 89 additions and 42 deletions

View File

@@ -10,7 +10,8 @@
"Bash(git add:*)", "Bash(git add:*)",
"Bash(git commit:*)", "Bash(git commit:*)",
"Bash(git checkout:*)", "Bash(git checkout:*)",
"Bash(sort:*)" "Bash(sort:*)",
"Bash(cmake:*)"
], ],
"deny": [], "deny": [],
"ask": [] "ask": []

View File

@@ -110,10 +110,12 @@ void handleShowDebugInfo() {
Screen::get()->toggleDebugInfo(); Screen::get()->toggleDebugInfo();
} }
/*
void handleToggleDebug() { void handleToggleDebug() {
Debug::get()->toggleEnabled(); 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 #endif
// Detecta qué acción global ha sido presionada (si alguna) // Detecta qué acción global ha sido presionada (si alguna)
@@ -216,7 +218,7 @@ void handle() {
break; break;
case InputAction::TOGGLE_DEBUG: case InputAction::TOGGLE_DEBUG:
handleToggleDebug(); //handleToggleDebug();
break; break;
case InputAction::SHOW_DEBUG_INFO: case InputAction::SHOW_DEBUG_INFO:

View File

@@ -16,7 +16,7 @@ class Debug {
void setPos(SDL_FPoint p); // Establece la posición donde se colocará la información de debug 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 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 clear() { slot_.clear(); } // Limpia el slot de debug

View File

@@ -14,6 +14,10 @@
#include "game/options.hpp" // Para Cheat, Options, options #include "game/options.hpp" // Para Cheat, Options, options
#include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT #include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
#ifdef _DEBUG
#include "core/system/debug.hpp" // Para Debug
#endif
// Constructor // Constructor
Player::Player(const Data& player) Player::Player(const Data& player)
: room_(player.room) { : room_(player.room) {
@@ -29,7 +33,12 @@ Player::Player(const Data& player)
// Pinta el jugador en pantalla // Pinta el jugador en pantalla
void Player::render() { void Player::render() {
sprite_->render(1, color_); 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<Uint8>(PaletteColor::GREEN));
Screen::get()->getRendererSurface()->putPixel(under_left_foot_.x, under_left_foot_.y, static_cast<Uint8>(PaletteColor::GREEN));
}
#endif
} }
// Actualiza las variables del objeto // Actualiza las variables del objeto
@@ -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) // 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 // Verificar si el pie ha salido de los límites horizontales de la rampa
// Usar min/max porque LEFT slopes tienen x1<x2 pero RIGHT slopes tienen x1>x2 // Usar min/max porque LEFT slopes tienen x1<x2 pero RIGHT slopes tienen x1>x2
@@ -300,12 +309,12 @@ void Player::moveOnSlope(float delta_time) {
if (EXITING_DOWNWARD) { if (EXITING_DOWNWARD) {
// Salida por abajo: bajar 1 pixel para ayudar detección de suelo // 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) // Si sale por arriba, mantener altura (ya está en foot_y - HEIGHT)
// El jugador ya no está en la rampa, limpiar referencia // 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) // Verificar si hay soporte debajo (suelo plano, conveyor belt, u otra slope)
if (isOnFloor()) { if (isOnFloor()) {
@@ -809,6 +818,9 @@ void Player::syncSpriteAndCollider() {
placeSprite(); // Coloca el sprite en la posición del jugador placeSprite(); // Coloca el sprite en la posición del jugador
collider_box_ = getRect(); // Actualiza el rectangulo de colisión collider_box_ = getRect(); // Actualiza el rectangulo de colisión
updateColliderPoints(); // Actualiza los puntos de colisión updateColliderPoints(); // Actualiza los puntos de colisión
#ifdef _DEBUG
updateFeet();
#endif
} }
// Coloca el sprite en la posición del jugador // Coloca el sprite en la posición del jugador

View File

@@ -10,8 +10,8 @@
#include "game/gameplay/item_manager.hpp" // Para ItemManager #include "game/gameplay/item_manager.hpp" // Para ItemManager
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker #include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/room_loader.hpp" // Para RoomLoader #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/scoreboard.hpp" // Para Scoreboard::Data
#include "game/gameplay/tilemap_renderer.hpp" // Para TilemapRenderer
#include "utils/defines.hpp" // Para TILE_SIZE #include "utils/defines.hpp" // Para TILE_SIZE
#include "utils/utils.hpp" // Para stringToColor #include "utils/utils.hpp" // Para stringToColor
@@ -32,8 +32,7 @@ Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
openTheJail(); // Abre la Jail si se da el caso 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_) // Crea el renderizador del tilemap (necesita tile_map_, tile_set_width_, surface_, bg_color_, conveyor_belt_direction_)
tilemap_renderer_ = std::make_unique<TilemapRenderer>(tile_map_, tile_set_width_, surface_, bg_color_, tilemap_renderer_ = std::make_unique<TilemapRenderer>(tile_map_, tile_set_width_, surface_, bg_color_, conveyor_belt_direction_);
conveyor_belt_direction_);
tilemap_renderer_->initialize(collision_map_.get()); // Inicializa (crea map_surface, pinta tiles, busca animados) 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 Screen::get()->setBorderColor(stringToColor(border_color_)); // Establece el color del borde
@@ -118,6 +117,13 @@ void Room::renderItems() {
item_manager_->render(); 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 // Actualiza las variables y objetos de la habitación
void Room::update(float delta_time) { void Room::update(float delta_time) {
if (is_paused_) { if (is_paused_) {
@@ -251,7 +257,6 @@ auto Room::getSlopeAtPoint(const SDL_FPoint& p) const -> const LineDiagonal* {
return collision_map_->getSlopeAtPoint(p); return collision_map_->getSlopeAtPoint(p);
} }
// Carga las variables desde un fichero de mapa (delegado a RoomLoader) // Carga las variables desde un fichero de mapa (delegado a RoomLoader)
auto Room::loadRoomFile(const std::string& file_path, bool verbose) -> Data { auto Room::loadRoomFile(const std::string& file_path, bool verbose) -> Data {
return RoomLoader::loadRoomFile(file_path, verbose); return RoomLoader::loadRoomFile(file_path, verbose);

View File

@@ -67,6 +67,9 @@ class Room {
void renderMap(); // Dibuja el mapa en pantalla void renderMap(); // Dibuja el mapa en pantalla
void renderEnemies(); // Dibuja los enemigos en pantalla void renderEnemies(); // Dibuja los enemigos en pantalla
void renderItems(); // Dibuja los objetos 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 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 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 auto getTile(SDL_FPoint point) -> Tile; // Devuelve el tipo de tile que hay en ese pixel

View File

@@ -8,9 +8,7 @@
#include "utils/utils.hpp" #include "utils/utils.hpp"
// Constructor // Constructor
TilemapRenderer::TilemapRenderer(std::vector<int> tile_map, int tile_set_width, TilemapRenderer::TilemapRenderer(std::vector<int> tile_map, int tile_set_width, std::shared_ptr<Surface> tileset_surface, std::string bg_color, int conveyor_belt_direction)
std::shared_ptr<Surface> tileset_surface, std::string bg_color,
int conveyor_belt_direction)
: tile_map_(std::move(tile_map)), : tile_map_(std::move(tile_map)),
tile_set_width_(tile_set_width), tile_set_width_(tile_set_width),
tileset_surface_(std::move(tileset_surface)), tileset_surface_(std::move(tileset_surface)),
@@ -47,7 +45,7 @@ void TilemapRenderer::render() {
// Dibuja los tiles animados // Dibuja los tiles animados
#ifdef _DEBUG #ifdef _DEBUG
if (!Debug::get()->getEnabled()) { if (!Debug::get()->isEnabled()) {
renderAnimatedTiles(); renderAnimatedTiles();
} }
#else #else
@@ -55,6 +53,13 @@ void TilemapRenderer::render() {
#endif #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 // Pinta el mapa estático y debug lines
void TilemapRenderer::fillMapTexture(const CollisionMap* collision_map) { void TilemapRenderer::fillMapTexture(const CollisionMap* collision_map) {
const Uint8 COLOR = stringToColor(bg_color_); const Uint8 COLOR = stringToColor(bg_color_);
@@ -77,13 +82,20 @@ void TilemapRenderer::fillMapTexture(const CollisionMap* collision_map) {
if (B && !A) { if (B && !A) {
clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE; clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE;
clip.y = (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); tileset_surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip);
} }
#else
tileset_surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip);
#endif
}
} }
} }
#ifdef _DEBUG #ifdef _DEBUG
if (Debug::get()->getEnabled()) { // Pinta las superficies en el modo debug
if (Debug::get()->isEnabled()) {
auto surface = Screen::get()->getRendererSurface(); auto surface = Screen::get()->getRendererSurface();
// BottomSurfaces // BottomSurfaces

View File

@@ -60,6 +60,16 @@ class TilemapRenderer {
*/ */
void render(); 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 * @brief Activa/desactiva modo pausa
* @param paused true para pausar, false para reanudar * @param paused true para pausar, false para reanudar

View File

@@ -190,7 +190,7 @@ void Game::updateDebugInfo() {
// Pone la información de debug en pantalla // Pone la información de debug en pantalla
void Game::renderDebugInfo() { void Game::renderDebugInfo() {
if (!Debug::get()->getEnabled()) { if (!Debug::get()->isEnabled()) {
return; return;
} }
@@ -221,34 +221,36 @@ void Game::renderDebugInfo() {
void Game::handleDebugEvents(const SDL_Event& event) { void Game::handleDebugEvents(const SDL_Event& event) {
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) { if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
switch (event.key.key) { switch (event.key.key) {
case SDL_SCANCODE_G: case SDLK_F12:
Debug::get()->toggleEnabled(); Debug::get()->toggleEnabled();
Options::cheats.invincible = static_cast<Options::Cheat::State>(Debug::get()->getEnabled()); Notifier::get()->show({"DEBUG " + std::string(Debug::get()->isEnabled() ? "ENABLED" : "DISABLED")}, Notifier::TextAlign::CENTER);
board_->music = !Debug::get()->getEnabled(); room_->redrawMap(); // Redibuja el tilemap para mostrar/ocultar líneas de colisión
Options::cheats.invincible = static_cast<Options::Cheat::State>(Debug::get()->isEnabled());
board_->music = !Debug::get()->isEnabled();
board_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic(); board_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic();
break; break;
case SDL_SCANCODE_R: case SDLK_R:
Resource::Cache::get()->reload(); Resource::Cache::get()->reload();
break; break;
case SDL_SCANCODE_W: case SDLK_W:
changeRoom(room_->getRoom(Room::Border::TOP)); changeRoom(room_->getRoom(Room::Border::TOP));
break; break;
case SDL_SCANCODE_A: case SDLK_A:
changeRoom(room_->getRoom(Room::Border::LEFT)); changeRoom(room_->getRoom(Room::Border::LEFT));
break; break;
case SDL_SCANCODE_S: case SDLK_S:
changeRoom(room_->getRoom(Room::Border::BOTTOM)); changeRoom(room_->getRoom(Room::Border::BOTTOM));
break; break;
case SDL_SCANCODE_D: case SDLK_D:
changeRoom(room_->getRoom(Room::Border::RIGHT)); changeRoom(room_->getRoom(Room::Border::RIGHT));
break; 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"); Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, Notifier::TextAlign::CENTER, Notifier::DURATION_CHEEVO, -1, false, "F7");
break; break;