merdetes pa debugar a gust
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
"Bash(git add:*)",
|
||||
"Bash(git commit:*)",
|
||||
"Bash(git checkout:*)",
|
||||
"Bash(sort:*)"
|
||||
"Bash(sort:*)",
|
||||
"Bash(cmake:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<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
|
||||
@@ -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 x1<x2 pero RIGHT slopes tienen x1>x2
|
||||
@@ -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
|
||||
|
||||
@@ -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<Scoreboard::Data> 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<TilemapRenderer>(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_, 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
// Constructor
|
||||
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)
|
||||
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)
|
||||
: 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<int>(event.key.repeat) == 0) {
|
||||
switch (event.key.key) {
|
||||
case SDL_SCANCODE_G:
|
||||
case SDLK_F12:
|
||||
Debug::get()->toggleEnabled();
|
||||
Options::cheats.invincible = static_cast<Options::Cheat::State>(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<Options::Cheat::State>(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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user